@mirasen/chessboard 0.1.1 → 1.0.0
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/CHANGELOG.md +24 -0
- package/README.md +240 -45
- package/dist/animation/planner.d.ts +11 -6
- package/dist/animation/planner.js +164 -45
- package/dist/animation/render/fade.d.ts +2 -2
- package/dist/animation/render/fade.js +3 -3
- package/dist/animation/render/move.d.ts +3 -3
- package/dist/animation/render/move.js +5 -5
- package/dist/animation/render/plan.d.ts +3 -3
- package/dist/animation/render/static.d.ts +2 -2
- package/dist/animation/render/static.js +3 -3
- package/dist/animation/types.d.ts +14 -15
- package/dist/animation/types.js +1 -6
- package/dist/extensions/build/index.d.ts +21 -0
- package/dist/extensions/build/index.js +9 -0
- package/dist/extensions/factory/main.js +23 -2
- package/dist/extensions/factory/runtime.d.ts +2 -1
- package/dist/extensions/factory/runtime.js +48 -4
- package/dist/extensions/first-party/active-target/factory.js +9 -9
- package/dist/extensions/first-party/active-target/types.d.ts +2 -2
- package/dist/extensions/first-party/active-target/types.js +4 -1
- package/dist/extensions/first-party/auto-promote/factory.d.ts +2 -0
- package/dist/extensions/first-party/auto-promote/factory.js +51 -0
- package/dist/extensions/first-party/auto-promote/types.d.ts +12 -0
- package/dist/extensions/first-party/auto-promote/types.js +2 -0
- package/dist/extensions/first-party/board-events/factory.js +1 -16
- package/dist/extensions/first-party/board-events/types.d.ts +1 -4
- package/dist/extensions/first-party/common/helpers.d.ts +7 -7
- package/dist/extensions/first-party/common/helpers.js +11 -11
- package/dist/extensions/first-party/common/types.d.ts +2 -3
- package/dist/extensions/first-party/last-move/factory.js +10 -10
- package/dist/extensions/first-party/last-move/types.d.ts +2 -2
- package/dist/extensions/first-party/legal-moves/factory.js +5 -5
- package/dist/extensions/first-party/legal-moves/types.d.ts +2 -2
- package/dist/extensions/first-party/main-renderer/animation/render.js +1 -2
- package/dist/extensions/first-party/main-renderer/animation/update.js +9 -23
- package/dist/extensions/first-party/main-renderer/board/render.js +3 -3
- package/dist/extensions/first-party/main-renderer/board/update.js +5 -3
- package/dist/extensions/first-party/main-renderer/coordinates/render.js +4 -4
- package/dist/extensions/first-party/main-renderer/drag/render.js +1 -1
- package/dist/extensions/first-party/main-renderer/factory.js +4 -4
- package/dist/extensions/first-party/main-renderer/normalize.d.ts +2 -3
- package/dist/extensions/first-party/main-renderer/normalize.js +1 -1
- package/dist/extensions/first-party/main-renderer/pieces/render.js +5 -5
- package/dist/extensions/first-party/main-renderer/pieces/suppress.js +7 -2
- package/dist/extensions/first-party/main-renderer/types/extension.d.ts +1 -1
- package/dist/extensions/first-party/main-renderer/types/extension.js +1 -1
- package/dist/extensions/first-party/main-renderer/types/instance.d.ts +2 -2
- package/dist/extensions/first-party/promotion/factory.d.ts +3 -0
- package/dist/extensions/first-party/promotion/factory.js +219 -0
- package/dist/extensions/first-party/promotion/normalize.d.ts +3 -0
- package/dist/extensions/first-party/promotion/normalize.js +37 -0
- package/dist/extensions/first-party/promotion/types/input.d.ts +10 -0
- package/dist/extensions/first-party/promotion/types/internal.d.ts +12 -0
- package/dist/extensions/first-party/promotion/types/internal.js +22 -0
- package/dist/extensions/first-party/promotion/types/main.d.ts +24 -0
- package/dist/extensions/first-party/promotion/types/main.js +2 -0
- package/dist/extensions/first-party/selected-square/factory.js +7 -7
- package/dist/extensions/first-party/selected-square/types.d.ts +2 -2
- package/dist/extensions/index.d.ts +1 -8
- package/dist/extensions/index.js +1 -6
- package/dist/extensions/types/basic/events.d.ts +8 -31
- package/dist/extensions/types/basic/events.js +9 -5
- package/dist/extensions/types/basic/interaction.d.ts +21 -0
- package/dist/extensions/types/basic/transient-visuals.d.ts +2 -1
- package/dist/extensions/types/context/events.d.ts +5 -0
- package/dist/extensions/types/context/events.js +1 -0
- package/dist/extensions/types/context/ui-move.d.ts +3 -15
- package/dist/extensions/types/extension.d.ts +10 -8
- package/dist/extensions/types/main.d.ts +11 -6
- package/dist/extensions/types/surface/commands.d.ts +9 -0
- package/dist/extensions/types/surface/events.d.ts +2 -3
- package/dist/extensions/types/wrapper.d.ts +23 -22
- package/dist/extensions/types/wrapper.js +34 -6
- package/dist/extensions/update.d.ts +2 -2
- package/dist/extensions/update.js +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/layout/factory.js +3 -3
- package/dist/layout/geometry/factory.d.ts +2 -11
- package/dist/layout/geometry/factory.js +16 -17
- package/dist/layout/geometry/helpers.d.ts +5 -0
- package/dist/layout/geometry/helpers.js +33 -0
- package/dist/layout/geometry/types.d.ts +13 -12
- package/dist/layout/helpers.d.ts +3 -4
- package/dist/layout/helpers.js +5 -5
- package/dist/layout/reducers.js +9 -8
- package/dist/layout/types.d.ts +5 -5
- package/dist/render/mount.js +2 -2
- package/dist/render/rendering/state.js +7 -7
- package/dist/runtime/factory/events.d.ts +3 -0
- package/dist/runtime/factory/events.js +18 -0
- package/dist/runtime/factory/helpers.js +12 -12
- package/dist/runtime/factory/input.js +17 -10
- package/dist/runtime/factory/main.js +44 -4
- package/dist/runtime/input/adapter/event.d.ts +3 -0
- package/dist/runtime/input/adapter/event.js +19 -0
- package/dist/runtime/input/adapter/factory.js +19 -38
- package/dist/runtime/input/adapter/helpers.d.ts +3 -5
- package/dist/runtime/input/adapter/helpers.js +60 -12
- package/dist/runtime/input/adapter/pointer.d.ts +6 -10
- package/dist/runtime/input/adapter/pointer.js +37 -70
- package/dist/runtime/input/adapter/types.d.ts +6 -3
- package/dist/runtime/input/adapter/types.js +6 -1
- package/dist/runtime/input/controller/factory.js +12 -11
- package/dist/runtime/input/controller/pointer.d.ts +5 -6
- package/dist/runtime/input/controller/pointer.js +36 -35
- package/dist/runtime/input/controller/transient-visuals.d.ts +2 -2
- package/dist/runtime/input/controller/transient-visuals.js +12 -5
- package/dist/runtime/input/controller/types.d.ts +5 -4
- package/dist/runtime/lifecycle.js +6 -6
- package/dist/runtime/mutation/interaction.js +1 -5
- package/dist/runtime/mutation/types.d.ts +10 -8
- package/dist/runtime/types/main.d.ts +2 -0
- package/dist/state/change/{factory.d.ts → factory/main.d.ts} +1 -1
- package/dist/state/change/{factory.js → factory/main.js} +8 -5
- package/dist/state/change/factory/ui-move.d.ts +4 -0
- package/dist/{runtime → state/change}/factory/ui-move.js +9 -9
- package/dist/state/change/helpers.d.ts +4 -2
- package/dist/state/change/helpers.js +11 -1
- package/dist/state/change/mutation.d.ts +1 -1
- package/dist/state/change/reducers.d.ts +3 -3
- package/dist/state/change/reducers.js +4 -4
- package/dist/state/change/types/main.d.ts +18 -0
- package/dist/state/change/types/main.js +1 -0
- package/dist/state/change/types/ui-move.d.ts +25 -0
- package/dist/state/change/types/ui-move.js +1 -0
- package/dist/state/factory.js +1 -1
- package/dist/state/interaction/factory.js +4 -2
- package/dist/state/interaction/helpers.d.ts +2 -0
- package/dist/state/interaction/helpers.js +3 -0
- package/dist/state/interaction/types/internal.d.ts +9 -1
- package/dist/state/types.d.ts +1 -1
- package/dist/wrapper/factory.js +2 -26
- package/package.json +17 -11
- package/dist/runtime/factory/ui-move.d.ts +0 -4
- package/dist/runtime/types/ui-move.d.ts +0 -9
- package/dist/state/change/types.d.ts +0 -17
- /package/dist/{runtime/types/ui-move.js → extensions/first-party/promotion/types/input.js} +0 -0
- /package/dist/{state/change/types.js → extensions/types/basic/interaction.js} +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { cloneDeep } from 'es-toolkit/object';
|
|
2
|
-
import {
|
|
2
|
+
import { changeStateSetDeferredUIMoveRequest, changeStateSetLastMove } from '../reducers.js';
|
|
3
3
|
function createChangeStateInternal() {
|
|
4
4
|
return {
|
|
5
5
|
lastMove: null,
|
|
6
|
-
|
|
6
|
+
deferredUIMoveRequest: null
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
9
|
export function createChangeState() {
|
|
@@ -12,17 +12,20 @@ export function createChangeState() {
|
|
|
12
12
|
get lastMove() {
|
|
13
13
|
return cloneDeep(internalState.lastMove);
|
|
14
14
|
},
|
|
15
|
+
get deferredUIMoveRequest() {
|
|
16
|
+
return cloneDeep(internalState.deferredUIMoveRequest);
|
|
17
|
+
},
|
|
15
18
|
setLastMove(move, mutationSession) {
|
|
16
19
|
return mutationSession.addMutation('state.change.setLastMove', changeStateSetLastMove(internalState, move));
|
|
17
20
|
},
|
|
18
21
|
getSnapshot() {
|
|
19
22
|
return {
|
|
20
23
|
...cloneDeep(internalState),
|
|
21
|
-
|
|
24
|
+
deferredUIMoveRequest: internalState.deferredUIMoveRequest?.getSnapshot() ?? null
|
|
22
25
|
};
|
|
23
26
|
},
|
|
24
|
-
|
|
25
|
-
return mutationSession.addMutation('state.change.
|
|
27
|
+
setDeferredUIMoveRequest(request, mutationSession) {
|
|
28
|
+
return mutationSession.addMutation('state.change.setDeferredUIMoveRequest', changeStateSetDeferredUIMoveRequest(internalState, request));
|
|
26
29
|
}
|
|
27
30
|
};
|
|
28
31
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Square } from '../../board/types/internal.js';
|
|
2
|
+
import { MoveDestinationSnapshot } from '../../interaction/types/internal.js';
|
|
3
|
+
import { PendingUIMoveRequest } from '../types/ui-move.js';
|
|
4
|
+
export declare function createPendingUIMoveRequest(sourceSquare: Square, destination: MoveDestinationSnapshot): PendingUIMoveRequest;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function
|
|
1
|
+
function createPendingUIMoveRequestInternal(sourceSquare, destination) {
|
|
2
2
|
return {
|
|
3
3
|
sourceSquare,
|
|
4
4
|
destination,
|
|
@@ -6,7 +6,7 @@ function createMoveRequestContextInternal(sourceSquare, destination) {
|
|
|
6
6
|
resolvedMoveRequest: null
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function pendingUIMoveRequestCanBeAutoResolved(state) {
|
|
10
10
|
return (state.status === 'unresolved' &&
|
|
11
11
|
(state.destination.promotedTo === undefined || state.destination.promotedTo.length <= 1));
|
|
12
12
|
}
|
|
@@ -21,11 +21,11 @@ function assertCanBeResolved(state) {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
function assertCanBeAutoResolved(state) {
|
|
24
|
-
if (!
|
|
24
|
+
if (!pendingUIMoveRequestCanBeAutoResolved(state)) {
|
|
25
25
|
throw new Error('Move request cannot be auto-resolved. Either it is already resolved or deferred, or it requires a promotion choice.');
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function pendingUIMoveRequestAutoResolve(state) {
|
|
29
29
|
assertCanBeAutoResolved(state);
|
|
30
30
|
const promotedTo = state.destination.promotedTo?.length === 1 ? state.destination.promotedTo[0] : undefined;
|
|
31
31
|
state.status = 'resolved';
|
|
@@ -41,8 +41,8 @@ function moveRequestContextAutoResolve(state) {
|
|
|
41
41
|
...(promotedTo !== undefined ? { promotedTo } : {})
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
|
-
export function
|
|
45
|
-
const internalState =
|
|
44
|
+
export function createPendingUIMoveRequest(sourceSquare, destination) {
|
|
45
|
+
const internalState = createPendingUIMoveRequestInternal(sourceSquare, destination);
|
|
46
46
|
return {
|
|
47
47
|
get status() {
|
|
48
48
|
return internalState.status;
|
|
@@ -54,7 +54,7 @@ export function createUIMoveRequestContext(sourceSquare, destination) {
|
|
|
54
54
|
return internalState.destination;
|
|
55
55
|
},
|
|
56
56
|
get canBeAutoResolved() {
|
|
57
|
-
return
|
|
57
|
+
return pendingUIMoveRequestCanBeAutoResolved(internalState);
|
|
58
58
|
},
|
|
59
59
|
get resolvedMoveRequest() {
|
|
60
60
|
return internalState.resolvedMoveRequest;
|
|
@@ -69,14 +69,14 @@ export function createUIMoveRequestContext(sourceSquare, destination) {
|
|
|
69
69
|
internalState.resolvedMoveRequest = request;
|
|
70
70
|
},
|
|
71
71
|
autoresolve() {
|
|
72
|
-
|
|
72
|
+
pendingUIMoveRequestAutoResolve(internalState);
|
|
73
73
|
},
|
|
74
74
|
getSnapshot() {
|
|
75
75
|
return {
|
|
76
76
|
status: internalState.status,
|
|
77
77
|
sourceSquare: internalState.sourceSquare,
|
|
78
78
|
destination: internalState.destination,
|
|
79
|
-
canBeAutoResolved:
|
|
79
|
+
canBeAutoResolved: pendingUIMoveRequestCanBeAutoResolved(internalState),
|
|
80
80
|
resolvedMoveRequest: internalState.resolvedMoveRequest
|
|
81
81
|
};
|
|
82
82
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { ExtensionUIMoveRequestContextSnapshot } from '../../extensions/types/context/ui-move.js';
|
|
2
1
|
import type { MoveRequest, MoveRequestBase, MoveSnapshot } from '../board/types/internal.js';
|
|
3
2
|
import { MoveDestinationSnapshot } from '../interaction/types/internal.js';
|
|
3
|
+
import { ChangeStateSnapshot } from './types/main.js';
|
|
4
|
+
import { PendingUIMoveRequestSnapshot } from './types/ui-move.js';
|
|
4
5
|
export declare function movesEqual(moveA: MoveSnapshot | null, moveB: MoveSnapshot | null): boolean;
|
|
5
6
|
export declare function moveRequestBasesEqual(requestA: MoveRequestBase | null, requestB: MoveRequestBase | null): boolean;
|
|
6
7
|
export declare function moveRequestsEqual(requestA: MoveRequest | null, requestB: MoveRequest | null): boolean;
|
|
7
8
|
export declare function moveDestinationsEqual(destA: MoveDestinationSnapshot | null, destB: MoveDestinationSnapshot | null): boolean;
|
|
8
|
-
export declare function
|
|
9
|
+
export declare function pendingUIMoveRequestsEqual(contextA: PendingUIMoveRequestSnapshot | null, contextB: PendingUIMoveRequestSnapshot | null): boolean;
|
|
10
|
+
export declare function changeStatesEqual(stateA: ChangeStateSnapshot | null, stateB: ChangeStateSnapshot | null): boolean;
|
|
@@ -69,7 +69,7 @@ export function moveDestinationsEqual(destA, destB) {
|
|
|
69
69
|
setsEqual(new Set(destA.promotedTo ?? []), new Set(destB.promotedTo ?? [])) &&
|
|
70
70
|
moveRequestBasesEqual(destA.secondary ?? null, destB.secondary ?? null));
|
|
71
71
|
}
|
|
72
|
-
export function
|
|
72
|
+
export function pendingUIMoveRequestsEqual(contextA, contextB) {
|
|
73
73
|
if (contextA === null && contextB === null) {
|
|
74
74
|
return true;
|
|
75
75
|
}
|
|
@@ -84,3 +84,13 @@ export function uiMoveRequestContextsEqual(contextA, contextB) {
|
|
|
84
84
|
contextA.canBeAutoResolved === contextB.canBeAutoResolved &&
|
|
85
85
|
moveRequestsEqual(contextA.resolvedMoveRequest, contextB.resolvedMoveRequest));
|
|
86
86
|
}
|
|
87
|
+
export function changeStatesEqual(stateA, stateB) {
|
|
88
|
+
if (stateA === null && stateB === null) {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
if (stateA === null || stateB === null) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
return (pendingUIMoveRequestsEqual(stateA.deferredUIMoveRequest, stateB.deferredUIMoveRequest) &&
|
|
95
|
+
movesEqual(stateA.lastMove, stateB.lastMove));
|
|
96
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MutationSession } from '../../mutation/types.js';
|
|
2
2
|
export type ChangeStateMutationPayloadByCause = {
|
|
3
3
|
'state.change.setLastMove': undefined;
|
|
4
|
-
'state.change.
|
|
4
|
+
'state.change.setDeferredUIMoveRequest': undefined;
|
|
5
5
|
};
|
|
6
6
|
export type ChangeStateMutationSession = MutationSession<ChangeStateMutationPayloadByCause>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ExtensionUIMoveRequestContext } from '../../extensions/types/context/ui-move.js';
|
|
2
1
|
import type { MoveSnapshot } from '../board/types/internal.js';
|
|
3
|
-
import
|
|
2
|
+
import { ChangeStateInternal } from './types/main.js';
|
|
3
|
+
import { PendingUIMoveRequest } from './types/ui-move.js';
|
|
4
4
|
export declare function changeStateSetLastMove(state: ChangeStateInternal, move: MoveSnapshot | null): boolean;
|
|
5
|
-
export declare function
|
|
5
|
+
export declare function changeStateSetDeferredUIMoveRequest(state: ChangeStateInternal, request: PendingUIMoveRequest | null): boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cloneDeep } from 'es-toolkit/object';
|
|
2
|
-
import { movesEqual,
|
|
2
|
+
import { movesEqual, pendingUIMoveRequestsEqual } from './helpers.js';
|
|
3
3
|
export function changeStateSetLastMove(state, move) {
|
|
4
4
|
if (movesEqual(state.lastMove, move)) {
|
|
5
5
|
return false; // No change
|
|
@@ -7,10 +7,10 @@ export function changeStateSetLastMove(state, move) {
|
|
|
7
7
|
state.lastMove = cloneDeep(move);
|
|
8
8
|
return true;
|
|
9
9
|
}
|
|
10
|
-
export function
|
|
11
|
-
if (
|
|
10
|
+
export function changeStateSetDeferredUIMoveRequest(state, request) {
|
|
11
|
+
if (pendingUIMoveRequestsEqual(state.deferredUIMoveRequest, request)) {
|
|
12
12
|
return false; // No change
|
|
13
13
|
}
|
|
14
|
-
state.
|
|
14
|
+
state.deferredUIMoveRequest = request;
|
|
15
15
|
return true;
|
|
16
16
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ReadonlyDeep } from 'type-fest';
|
|
2
|
+
import { MoveSnapshot } from '../../board/types/internal.js';
|
|
3
|
+
import type { ChangeStateMutationSession } from '../mutation.js';
|
|
4
|
+
import { PendingUIMoveRequest, PendingUIMoveRequestSnapshot } from './ui-move.js';
|
|
5
|
+
export interface ChangeStateInternal {
|
|
6
|
+
lastMove: MoveSnapshot | null;
|
|
7
|
+
deferredUIMoveRequest: PendingUIMoveRequest | null;
|
|
8
|
+
}
|
|
9
|
+
export type ChangeStateSnapshot = ReadonlyDeep<Omit<ChangeStateInternal, 'deferredUIMoveRequest'>> & {
|
|
10
|
+
deferredUIMoveRequest: PendingUIMoveRequestSnapshot | null;
|
|
11
|
+
};
|
|
12
|
+
export interface ChangeState {
|
|
13
|
+
readonly lastMove: MoveSnapshot | null;
|
|
14
|
+
readonly deferredUIMoveRequest: PendingUIMoveRequest | null;
|
|
15
|
+
setLastMove(move: MoveSnapshot | null, mutationSession: ChangeStateMutationSession): boolean;
|
|
16
|
+
setDeferredUIMoveRequest(request: PendingUIMoveRequest | null, mutationSession: ChangeStateMutationSession): boolean;
|
|
17
|
+
getSnapshot(): ChangeStateSnapshot;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { MoveRequest, RolePromotionCode, Square } from '../../board/types/internal.js';
|
|
2
|
+
import { MoveDestinationSnapshot } from '../../interaction/types/internal.js';
|
|
3
|
+
export type PendingUIMoveRequestStatus = 'unresolved' | 'deferred' | 'resolved';
|
|
4
|
+
export interface PendingUIMoveRequestSnapshot {
|
|
5
|
+
readonly status: PendingUIMoveRequestStatus;
|
|
6
|
+
readonly sourceSquare: Square;
|
|
7
|
+
readonly destination: MoveDestinationSnapshot;
|
|
8
|
+
readonly canBeAutoResolved: boolean;
|
|
9
|
+
readonly resolvedMoveRequest: MoveRequest | null;
|
|
10
|
+
}
|
|
11
|
+
export interface PendingUIMoveRequest extends PendingUIMoveRequestSnapshot {
|
|
12
|
+
defer(): void;
|
|
13
|
+
resolve(request: MoveRequest): void;
|
|
14
|
+
autoresolve(): void;
|
|
15
|
+
getSnapshot(): PendingUIMoveRequestSnapshot;
|
|
16
|
+
}
|
|
17
|
+
export interface PendingUIMoveRequestInternal {
|
|
18
|
+
readonly sourceSquare: Square;
|
|
19
|
+
readonly destination: MoveDestinationSnapshot;
|
|
20
|
+
status: PendingUIMoveRequestStatus;
|
|
21
|
+
resolvedMoveRequest: MoveRequest | null;
|
|
22
|
+
}
|
|
23
|
+
export interface DeferredUIMoveResolutionDetails {
|
|
24
|
+
readonly promotedTo: RolePromotionCode;
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/state/factory.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createBoardState } from './board/factory.js';
|
|
2
|
-
import { createChangeState } from './change/factory.js';
|
|
2
|
+
import { createChangeState } from './change/factory/main.js';
|
|
3
3
|
import { createInteractionState } from './interaction/factory.js';
|
|
4
4
|
import { createViewState } from './view/factory.js';
|
|
5
5
|
function createRuntimeStateInternal(options) {
|
|
@@ -51,8 +51,10 @@ export function createInteractionState(options) {
|
|
|
51
51
|
return internalState.dragSession ? { ...internalState.dragSession } : null;
|
|
52
52
|
},
|
|
53
53
|
setDragSession(session, mutationSession) {
|
|
54
|
-
//
|
|
55
|
-
|
|
54
|
+
// assert that there is no active session when setting a new session.
|
|
55
|
+
assert(session === null || internalState.dragSession === null, 'Cannot set a new drag session while another session is active');
|
|
56
|
+
if (session && session.owner === 'core') {
|
|
57
|
+
// Assert that the selected is the same as the source of the drag session when setting a lifted-piece-drag session
|
|
56
58
|
assert(internalState.selected, 'There must be a selected piece to start a drag session');
|
|
57
59
|
if (session.type === 'lifted-piece-drag') {
|
|
58
60
|
assert(internalState.selected, 'There must be a selected piece to start a lifted-piece-drag session');
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { InteractionStateMutationSession } from './mutation.js';
|
|
2
|
+
import { DragSessionCoreOwnedSnapshot, DragSessionSnapshot } from './types/internal.js';
|
|
2
3
|
import { InteractionStateInternal, InteractionStateSelected } from './types/main.js';
|
|
3
4
|
export declare function selectedEqual(a: InteractionStateSelected | null, b: InteractionStateSelected | null): boolean;
|
|
4
5
|
export declare function updateActiveDestinations(state: InteractionStateInternal, mutationSession: InteractionStateMutationSession): boolean;
|
|
6
|
+
export declare function isDragSessionCoreOwned(session: DragSessionSnapshot): session is DragSessionCoreOwnedSnapshot;
|
|
@@ -14,3 +14,6 @@ export function updateActiveDestinations(state, mutationSession) {
|
|
|
14
14
|
const activeDests = getActiveDestinations(state, state.selected.square);
|
|
15
15
|
return mutationSession.addMutation('state.interaction.updateActiveDestinations', interactionSetActiveDestinations(state, activeDests));
|
|
16
16
|
}
|
|
17
|
+
export function isDragSessionCoreOwned(session) {
|
|
18
|
+
return session.owner === 'core';
|
|
19
|
+
}
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import type { ReadonlyDeep } from 'type-fest';
|
|
2
|
+
import type { ExtensionDragSession, ExtensionDragSessionBase } from '../../../extensions/types/basic/interaction.js';
|
|
2
3
|
import type { MoveRequest, PieceCode, RolePromotionCode, Square } from '../../board/types/internal.js';
|
|
3
|
-
export
|
|
4
|
+
export type DragSessionExtensionOwned = ExtensionDragSession & {
|
|
5
|
+
owner: string;
|
|
6
|
+
};
|
|
7
|
+
export type DragSessionExtensionOwnedSnapshot = ReadonlyDeep<DragSessionExtensionOwned>;
|
|
8
|
+
export interface DragSessionCoreOwned extends ExtensionDragSessionBase {
|
|
9
|
+
owner: 'core';
|
|
4
10
|
type: 'lifted-piece-drag' | 'release-targeting';
|
|
5
11
|
sourceSquare: Square;
|
|
6
12
|
sourcePieceCode: PieceCode;
|
|
7
13
|
targetSquare: Square | null;
|
|
8
14
|
}
|
|
15
|
+
export type DragSessionCoreOwnedSnapshot = ReadonlyDeep<DragSessionCoreOwned>;
|
|
16
|
+
export type DragSession = DragSessionCoreOwned | DragSessionExtensionOwned;
|
|
9
17
|
export type DragSessionSnapshot = ReadonlyDeep<DragSession>;
|
|
10
18
|
export interface MoveDestination extends Omit<MoveRequest, 'from' | 'promotedTo'> {
|
|
11
19
|
promotedTo?: RolePromotionCode[];
|
package/dist/state/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PositionInput } from './board/types/input.js';
|
|
2
2
|
import { BoardState, BoardStateSnapshot } from './board/types/main.js';
|
|
3
|
-
import type { ChangeState, ChangeStateSnapshot } from './change/types.js';
|
|
3
|
+
import type { ChangeState, ChangeStateSnapshot } from './change/types/main.js';
|
|
4
4
|
import { InteractionState, InteractionStateInitOptions, InteractionStateSnapshot } from './interaction/types/main.js';
|
|
5
5
|
import { ViewStateSnapshot } from './view/types/internal.js';
|
|
6
6
|
import { ViewState, ViewStateInitOptions } from './view/types/main.js';
|
package/dist/wrapper/factory.js
CHANGED
|
@@ -1,36 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createBoardEvents } from '../extensions/first-party/board-events/factory.js';
|
|
3
|
-
import { createLastMove } from '../extensions/first-party/last-move/factory.js';
|
|
4
|
-
import { createLegalMoves } from '../extensions/first-party/legal-moves/factory.js';
|
|
5
|
-
import { createMainRenderer } from '../extensions/first-party/main-renderer/factory.js';
|
|
6
|
-
import { createSelectedSquare } from '../extensions/first-party/selected-square/factory.js';
|
|
7
|
-
import { DefaultBuiltinChessboardExtensions } from '../extensions/types/wrapper.js';
|
|
1
|
+
import { builtInExtensionFactoryMap, DefaultBuiltinChessboardExtensions } from '../extensions/types/wrapper.js';
|
|
8
2
|
import { createRuntime } from '../runtime/factory/main.js';
|
|
9
|
-
function createBuiltInExtensionDefinition(id) {
|
|
10
|
-
switch (id) {
|
|
11
|
-
case 'mainRenderer':
|
|
12
|
-
return createMainRenderer();
|
|
13
|
-
case 'events':
|
|
14
|
-
return createBoardEvents();
|
|
15
|
-
case 'selectedSquare':
|
|
16
|
-
return createSelectedSquare();
|
|
17
|
-
case 'activeTarget':
|
|
18
|
-
return createActiveTarget();
|
|
19
|
-
case 'legalMoves':
|
|
20
|
-
return createLegalMoves();
|
|
21
|
-
case 'lastMove':
|
|
22
|
-
return createLastMove();
|
|
23
|
-
default:
|
|
24
|
-
throw new Error(`Unknown built-in extension id: ${id}`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
3
|
export function createBoard(options) {
|
|
28
4
|
// prepare init options for runtime
|
|
29
5
|
const extensionsInput = options.extensions ?? DefaultBuiltinChessboardExtensions;
|
|
30
6
|
const extensions = extensionsInput.map((ext) => {
|
|
31
7
|
if (typeof ext === 'string') {
|
|
32
8
|
// built-in extension, convert to definition
|
|
33
|
-
return
|
|
9
|
+
return builtInExtensionFactoryMap[ext]();
|
|
34
10
|
}
|
|
35
11
|
// assume it's already a definition
|
|
36
12
|
return ext;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mirasen/chessboard",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "0.
|
|
3
|
+
"description": "Framework-agnostic TypeScript chessboard platform with real chess interaction built in.",
|
|
4
|
+
"version": "1.0.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Mirasen",
|
|
@@ -10,10 +10,14 @@
|
|
|
10
10
|
"keywords": [
|
|
11
11
|
"mirasen",
|
|
12
12
|
"chessboard",
|
|
13
|
-
"chess-ui",
|
|
14
13
|
"chess",
|
|
14
|
+
"chess-ui",
|
|
15
|
+
"chessboard-ui",
|
|
16
|
+
"typescript",
|
|
17
|
+
"framework-agnostic",
|
|
15
18
|
"svg",
|
|
16
|
-
"
|
|
19
|
+
"extensions",
|
|
20
|
+
"chessboard-platform"
|
|
17
21
|
],
|
|
18
22
|
"homepage": "https://mirasen.io/chessboard",
|
|
19
23
|
"repository": {
|
|
@@ -34,7 +38,11 @@
|
|
|
34
38
|
"types": "./dist/extensions/index.d.ts",
|
|
35
39
|
"import": "./dist/extensions/index.js"
|
|
36
40
|
},
|
|
37
|
-
"./
|
|
41
|
+
"./extensions/build": {
|
|
42
|
+
"types": "./dist/extensions/build/index.d.ts",
|
|
43
|
+
"import": "./dist/extensions/build/index.js"
|
|
44
|
+
},
|
|
45
|
+
"./unstable/*": {
|
|
38
46
|
"types": "./dist/*.d.ts",
|
|
39
47
|
"import": "./dist/*.js"
|
|
40
48
|
}
|
|
@@ -48,11 +56,9 @@
|
|
|
48
56
|
"lint": "prettier --check . && eslint .",
|
|
49
57
|
"check": "tsc --skipLibCheck --noEmit",
|
|
50
58
|
"check:test": "tsc --project tsconfig-test.json --skipLibCheck --noEmit",
|
|
51
|
-
"test": "
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"coverage-backup": "vitest run --coverage",
|
|
55
|
-
"changeset:version": "changeset version && npm install && git add --all",
|
|
59
|
+
"test": "npm run check:test && vitest run --run",
|
|
60
|
+
"coverage": "vitest run --coverage",
|
|
61
|
+
"changeset:version": "changeset version && npm install && npm run format && git add --all",
|
|
56
62
|
"changeset:publish": "changeset publish"
|
|
57
63
|
},
|
|
58
64
|
"files": [
|
|
@@ -87,7 +93,7 @@
|
|
|
87
93
|
"vitest": "^4.0.18"
|
|
88
94
|
},
|
|
89
95
|
"engines": {
|
|
90
|
-
"node": ">=
|
|
96
|
+
"node": ">=20"
|
|
91
97
|
},
|
|
92
98
|
"dependencies": {
|
|
93
99
|
"@echecs/fen": "^2.1.0",
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { ExtensionUIMoveRequestContext } from '../../extensions/types/context/ui-move.js';
|
|
2
|
-
import { Square } from '../../state/board/types/internal.js';
|
|
3
|
-
import { MoveDestinationSnapshot } from '../../state/interaction/types/internal.js';
|
|
4
|
-
export declare function createUIMoveRequestContext(sourceSquare: Square, destination: MoveDestinationSnapshot): ExtensionUIMoveRequestContext;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ExtensionUIMoveRequestStatus } from '../../extensions/types/context/ui-move.js';
|
|
2
|
-
import { MoveRequest, Square } from '../../state/board/types/internal.js';
|
|
3
|
-
import { MoveDestinationSnapshot } from '../../state/interaction/types/internal.js';
|
|
4
|
-
export interface UIMoveRequestContextInternal {
|
|
5
|
-
readonly sourceSquare: Square;
|
|
6
|
-
readonly destination: MoveDestinationSnapshot;
|
|
7
|
-
status: ExtensionUIMoveRequestStatus;
|
|
8
|
-
resolvedMoveRequest: MoveRequest | null;
|
|
9
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { ReadonlyDeep } from 'type-fest';
|
|
2
|
-
import { ExtensionUIMoveRequestContext, ExtensionUIMoveRequestContextSnapshot } from '../../extensions/types/context/ui-move.js';
|
|
3
|
-
import type { MoveSnapshot } from '../board/types/internal.js';
|
|
4
|
-
import type { ChangeStateMutationSession } from './mutation.js';
|
|
5
|
-
export interface ChangeStateInternal {
|
|
6
|
-
lastMove: MoveSnapshot | null;
|
|
7
|
-
deferredUIMoveRequestContext: ExtensionUIMoveRequestContext | null;
|
|
8
|
-
}
|
|
9
|
-
export type ChangeStateSnapshot = ReadonlyDeep<Omit<ChangeStateInternal, 'deferredUIMoveRequestContext'>> & {
|
|
10
|
-
deferredUIMoveRequestContext: ExtensionUIMoveRequestContextSnapshot | null;
|
|
11
|
-
};
|
|
12
|
-
export interface ChangeState {
|
|
13
|
-
readonly lastMove: MoveSnapshot | null;
|
|
14
|
-
setLastMove(move: MoveSnapshot | null, mutationSession: ChangeStateMutationSession): boolean;
|
|
15
|
-
setDeferredUIMoveRequestContext(context: ExtensionUIMoveRequestContext, mutationSession: ChangeStateMutationSession): boolean;
|
|
16
|
-
getSnapshot(): ChangeStateSnapshot;
|
|
17
|
-
}
|
|
File without changes
|
|
File without changes
|