@mirasen/chessboard 1.0.4 → 1.0.5
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 +9 -0
- package/dist/extensions/build/index.d.ts +1 -0
- package/dist/extensions/build/index.js +1 -0
- package/dist/extensions/first-party/promotion/normalize.js +6 -4
- package/dist/extensions/types/wrapper.d.ts +0 -3
- package/dist/extensions/types/wrapper.js +0 -3
- package/dist/runtime/factory/input.js +6 -7
- package/dist/runtime/mutation/interaction.js +1 -1
- package/dist/runtime/mutation/types.d.ts +3 -2
- package/dist/wrapper/factory.d.ts +1 -1
- package/dist/wrapper/factory.js +8 -0
- package/dist/wrapper/types.d.ts +15 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @mirasen/chessboard
|
|
2
2
|
|
|
3
|
+
## 1.0.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0422020: Fix fast drag-and-drop sometimes leaving a stale drag visual due to an unsynced target square.
|
|
8
|
+
- 0422020: Update dependencies
|
|
9
|
+
- 0422020: Fix promotion extension to accept renderer-compatible piece URL maps without throwing on extra entries.
|
|
10
|
+
- 0422020: Allow createBoard options to configure built-in extensions without direct factory calls.
|
|
11
|
+
|
|
3
12
|
## 1.0.4
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { cleanAnimationPlan, prepareAnimationPlan, renderAnimationPlan } from '../../animation/render/plan.js';
|
|
1
2
|
export { clearElementChildren, createSvgElement, updateElementAttributes } from '../../render/svg/helpers.js';
|
|
2
3
|
export type { RuntimeReadonlyMutationSession } from '../../runtime/mutation/types.js';
|
|
3
4
|
export { isNonEmptyPieceCode } from '../../state/board/check.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { cleanAnimationPlan, prepareAnimationPlan, renderAnimationPlan } from '../../animation/render/plan.js';
|
|
1
2
|
export { clearElementChildren, createSvgElement, updateElementAttributes } from '../../render/svg/helpers.js';
|
|
2
3
|
export { isNonEmptyPieceCode } from '../../state/board/check.js';
|
|
3
4
|
export { fileOf, rankOf, squareOf } from '../../state/board/coords.js';
|
|
@@ -6,21 +6,23 @@ function assertPieceUrlsComplete(pieceUrls) {
|
|
|
6
6
|
assert(pieceCode in pieceUrls, `Missing URL for piece code: ${pieceCode}`);
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
|
|
9
|
+
function isPromotionPieceCode(pieceCode) {
|
|
10
|
+
return (pieceCode === 5 /* PieceCode.WhiteQueen */ ||
|
|
11
11
|
pieceCode === 4 /* PieceCode.WhiteRook */ ||
|
|
12
12
|
pieceCode === 3 /* PieceCode.WhiteBishop */ ||
|
|
13
13
|
pieceCode === 2 /* PieceCode.WhiteKnight */ ||
|
|
14
14
|
pieceCode === 13 /* PieceCode.BlackQueen */ ||
|
|
15
15
|
pieceCode === 12 /* PieceCode.BlackRook */ ||
|
|
16
16
|
pieceCode === 11 /* PieceCode.BlackBishop */ ||
|
|
17
|
-
pieceCode === 10 /* PieceCode.BlackKnight
|
|
17
|
+
pieceCode === 10 /* PieceCode.BlackKnight */);
|
|
18
18
|
}
|
|
19
19
|
function normalizePromotionPieceUrls(input) {
|
|
20
20
|
const normalized = {};
|
|
21
21
|
for (const [key, url] of Object.entries(input)) {
|
|
22
22
|
const pieceCode = normalizePiece(key);
|
|
23
|
-
|
|
23
|
+
if (!isPromotionPieceCode(pieceCode)) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
24
26
|
normalized[pieceCode] = url;
|
|
25
27
|
}
|
|
26
28
|
assertPieceUrlsComplete(normalized);
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Public built-in extension ids accepted by createBoard({ extensions })
|
|
3
|
-
*/
|
|
4
1
|
import { createActiveTarget } from '../first-party/active-target/factory.js';
|
|
5
2
|
import { createAutoPromote } from '../first-party/auto-promote/factory.js';
|
|
6
3
|
import { createBoardEvents } from '../first-party/board-events/factory.js';
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Public built-in extension ids accepted by createBoard({ extensions })
|
|
3
|
-
*/
|
|
4
1
|
import { createActiveTarget } from '../first-party/active-target/factory.js';
|
|
5
2
|
import { EXTENSION_ID as EXTENSION_ID_ACTIVE_TARGET } from '../first-party/active-target/types.js';
|
|
6
3
|
import { createAutoPromote } from '../first-party/auto-promote/factory.js';
|
|
@@ -42,23 +42,24 @@ export function createRuntimeInteractionSurface(state) {
|
|
|
42
42
|
const internalState = state();
|
|
43
43
|
const mutationSession = internalState.mutation.getSession();
|
|
44
44
|
const interaction = internalState.state.interaction;
|
|
45
|
+
interaction.updateDragSessionCurrentTarget(target, mutationSession);
|
|
45
46
|
const dragSession = interaction.dragSession;
|
|
46
|
-
assert(dragSession !== null, 'completeDragTo requires an active drag session');
|
|
47
47
|
assert(isDragSessionCoreOwned(dragSession), 'completeDragTo can only be called for core-owned drag sessions');
|
|
48
48
|
uiMoveCompleteTo(internalState, target);
|
|
49
|
-
mutationSession.addMutation('runtime.interaction.
|
|
49
|
+
mutationSession.addMutation('runtime.interaction.completeCoreDragTo', true, dragSession);
|
|
50
50
|
runtimeRunMutationPipeline(internalState);
|
|
51
51
|
},
|
|
52
52
|
completeExtensionDrag(target) {
|
|
53
53
|
const internalState = state();
|
|
54
54
|
const mutationSession = internalState.mutation.getSession();
|
|
55
55
|
const interaction = internalState.state.interaction;
|
|
56
|
+
interaction.updateDragSessionCurrentTarget(target, mutationSession);
|
|
56
57
|
const dragSession = interaction.dragSession;
|
|
57
|
-
assert(dragSession !== null, 'completeExtensionDrag requires an active drag session');
|
|
58
58
|
assert(!isDragSessionCoreOwned(dragSession), 'completeExtensionDrag can only be called for extension-owned drag sessions');
|
|
59
|
-
assert(dragSession.targetSquare === target, 'The target square in completeExtensionDrag must match the current target square of the drag session');
|
|
60
59
|
internalState.extensionSystem.completeDrag(dragSession);
|
|
61
60
|
internalState.state.interaction.setDragSession(null, mutationSession);
|
|
61
|
+
mutationSession.addMutation('runtime.interaction.completeExtensionDragTo', true, dragSession);
|
|
62
|
+
runtimeRunMutationPipeline(internalState);
|
|
62
63
|
},
|
|
63
64
|
startReleaseTargetingDrag(source, target) {
|
|
64
65
|
const internalState = state();
|
|
@@ -92,9 +93,7 @@ export function createRuntimeInteractionSurface(state) {
|
|
|
92
93
|
const internalState = state();
|
|
93
94
|
const interactionMutationSession = internalState.mutation.getSession();
|
|
94
95
|
const interaction = internalState.state.interaction;
|
|
95
|
-
|
|
96
|
-
assert(currentDragSession !== null, 'No active drag session to update');
|
|
97
|
-
internalState.state.interaction.updateDragSessionCurrentTarget(target, interactionMutationSession);
|
|
96
|
+
interaction.updateDragSessionCurrentTarget(target, interactionMutationSession);
|
|
98
97
|
runtimeRunMutationPipeline(internalState);
|
|
99
98
|
},
|
|
100
99
|
onEvent(context) {
|
|
@@ -4,7 +4,7 @@ export const reconcileInteractionSelectionAfterBoardStateChange = (context, muta
|
|
|
4
4
|
const { current } = context;
|
|
5
5
|
if (!mutationSession.hasMutation({ prefixes: ['state.board.'] }) ||
|
|
6
6
|
mutationSession.hasMutation({
|
|
7
|
-
causes: ['state.interaction.clear', 'runtime.interaction.
|
|
7
|
+
causes: ['state.interaction.clear', 'runtime.interaction.completeCoreDragTo']
|
|
8
8
|
})) {
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
@@ -3,10 +3,11 @@ import type { MutationSession, ReadonlyMutationSession } from '../../mutation/ty
|
|
|
3
3
|
import type { BoardStateMutationPayloadByCause } from '../../state/board/mutation.js';
|
|
4
4
|
import type { ChangeStateMutationPayloadByCause } from '../../state/change/mutation.js';
|
|
5
5
|
import type { InteractionStateMutationPayloadByCause } from '../../state/interaction/mutation.js';
|
|
6
|
-
import type { DragSessionCoreOwnedSnapshot } from '../../state/interaction/types/internal.js';
|
|
6
|
+
import type { DragSessionCoreOwnedSnapshot, DragSessionExtensionOwnedSnapshot } from '../../state/interaction/types/internal.js';
|
|
7
7
|
import type { ViewStateMutationPayloadByCause } from '../../state/view/mutation.js';
|
|
8
8
|
type RuntimeOwnMutationPayloadByCause = {
|
|
9
|
-
'runtime.interaction.
|
|
9
|
+
'runtime.interaction.completeCoreDragTo': DragSessionCoreOwnedSnapshot;
|
|
10
|
+
'runtime.interaction.completeExtensionDragTo': DragSessionExtensionOwnedSnapshot;
|
|
10
11
|
'runtime.interaction.resolveDeferredUIMoveRequest': undefined;
|
|
11
12
|
'runtime.interaction.cancelDeferredUIMoveRequest': undefined;
|
|
12
13
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { DefaultBuiltinChessboardExtensions } from '../extensions/types/wrapper.js';
|
|
2
|
-
import { Chessboard, ChessboardExtensionInput, ChessboardInitOptions } from './types.js';
|
|
2
|
+
import { type Chessboard, type ChessboardExtensionInput, type ChessboardInitOptions } from './types.js';
|
|
3
3
|
export declare function createBoard<TExtensions extends readonly ChessboardExtensionInput[] = DefaultBuiltinChessboardExtensions>(options: ChessboardInitOptions<TExtensions>): Chessboard<TExtensions>;
|
package/dist/wrapper/factory.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { builtInExtensionFactoryMap, DefaultBuiltinChessboardExtensions } from '../extensions/types/wrapper.js';
|
|
2
2
|
import { createRuntime } from '../runtime/factory/main.js';
|
|
3
|
+
function resolveBuiltInExtensionWithOptions(input) {
|
|
4
|
+
const factory = builtInExtensionFactoryMap[input.builtin];
|
|
5
|
+
return factory(input.options);
|
|
6
|
+
}
|
|
3
7
|
export function createBoard(options) {
|
|
4
8
|
// prepare init options for runtime
|
|
5
9
|
const extensionsInput = options.extensions ?? DefaultBuiltinChessboardExtensions;
|
|
@@ -8,6 +12,10 @@ export function createBoard(options) {
|
|
|
8
12
|
// built-in extension, convert to definition
|
|
9
13
|
return builtInExtensionFactoryMap[ext]();
|
|
10
14
|
}
|
|
15
|
+
if ('builtin' in ext) {
|
|
16
|
+
// built-in extension with options, convert to definition
|
|
17
|
+
return resolveBuiltInExtensionWithOptions(ext);
|
|
18
|
+
}
|
|
11
19
|
// assume it's already a definition
|
|
12
20
|
return ext;
|
|
13
21
|
});
|
package/dist/wrapper/types.d.ts
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
import type { AnyExtensionDefinition, ExtensionDefinitionId, ExtensionDefinitionPublicApi } from '../extensions/types/extension.js';
|
|
2
|
-
import { BuiltInExtensionDefinitionMap, BuiltInExtensionId, DefaultBuiltinChessboardExtensions } from '../extensions/types/wrapper.js';
|
|
3
|
-
import { Runtime } from '../runtime/types/main.js';
|
|
4
|
-
import { RuntimeStateInitOptions } from '../state/types.js';
|
|
2
|
+
import { type BuiltInExtensionDefinitionMap, type BuiltInExtensionId, type DefaultBuiltinChessboardExtensions, builtInExtensionFactoryMap } from '../extensions/types/wrapper.js';
|
|
3
|
+
import type { Runtime } from '../runtime/types/main.js';
|
|
4
|
+
import type { RuntimeStateInitOptions } from '../state/types.js';
|
|
5
5
|
/**
|
|
6
6
|
* What createBoard accepts in options.extensions
|
|
7
7
|
*/
|
|
8
|
-
export type
|
|
8
|
+
export type BuiltInExtensionFactoryInitOptions<TId extends BuiltInExtensionId> = Parameters<(typeof builtInExtensionFactoryMap)[TId]> extends [] ? never : NonNullable<Parameters<(typeof builtInExtensionFactoryMap)[TId]>[0]>;
|
|
9
|
+
type BuiltInExtensionIdsWithOptions = {
|
|
10
|
+
[TId in BuiltInExtensionId]: [BuiltInExtensionFactoryInitOptions<TId>] extends [never] ? never : TId;
|
|
11
|
+
}[BuiltInExtensionId];
|
|
12
|
+
export type BuiltInExtensionInitOptions = {
|
|
13
|
+
[TId in BuiltInExtensionIdsWithOptions]: {
|
|
14
|
+
builtin: TId;
|
|
15
|
+
options: BuiltInExtensionFactoryInitOptions<TId>;
|
|
16
|
+
};
|
|
17
|
+
}[BuiltInExtensionIdsWithOptions];
|
|
18
|
+
export type ChessboardExtensionInput = BuiltInExtensionId | BuiltInExtensionInitOptions | AnyExtensionDefinition;
|
|
9
19
|
/**
|
|
10
20
|
* Resolve one public input item into a concrete extension definition type
|
|
11
21
|
*/
|
|
12
|
-
export type ResolveChessboardExtensionInput<T> = T extends keyof BuiltInExtensionDefinitionMap ? BuiltInExtensionDefinitionMap[T] : T extends AnyExtensionDefinition ? T : never;
|
|
22
|
+
export type ResolveChessboardExtensionInput<T> = T extends keyof BuiltInExtensionDefinitionMap ? BuiltInExtensionDefinitionMap[T] : T extends BuiltInExtensionInitOptions ? T['builtin'] extends keyof BuiltInExtensionDefinitionMap ? BuiltInExtensionDefinitionMap[T['builtin']] : never : T extends AnyExtensionDefinition ? T : never;
|
|
13
23
|
/**
|
|
14
24
|
* Resolve an input tuple into a tuple of concrete extension definitions
|
|
15
25
|
*/
|
package/package.json
CHANGED