@dxos/plugin-chess 0.9.1-main.c7dcc2e112 → 0.10.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/dist/lib/neutral/{ChessCard-4TUTIFB6.mjs → ChessCard-VJ3I6MIB.mjs} +8 -3
- package/dist/lib/neutral/ChessCard-VJ3I6MIB.mjs.map +7 -0
- package/dist/lib/neutral/ChessPlugin.mjs +1 -1
- package/dist/lib/neutral/ChessPlugin.node.mjs +3 -3
- package/dist/lib/neutral/ChessPlugin.node.mjs.map +3 -3
- package/dist/lib/neutral/capabilities/index.mjs +3 -3
- package/dist/lib/neutral/capabilities/index.mjs.map +3 -3
- package/dist/lib/neutral/{chunk-ZSC5H6M4.mjs → chunk-AMXVX7V2.mjs} +2 -2
- package/dist/lib/neutral/{chunk-S66CCWNQ.mjs → chunk-DXIET5G2.mjs} +11 -11
- package/dist/lib/neutral/chunk-DXIET5G2.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-IQCSIZXM.mjs → chunk-EXZ3XFEG.mjs} +5 -5
- package/dist/lib/neutral/chunk-EXZ3XFEG.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-3WMTSPOZ.mjs → chunk-IKWULCKX.mjs} +10 -10
- package/dist/lib/neutral/chunk-IKWULCKX.mjs.map +7 -0
- package/dist/lib/neutral/components/index.mjs +45 -44
- package/dist/lib/neutral/components/index.mjs.map +3 -3
- package/dist/lib/neutral/containers/index.mjs +1 -1
- package/dist/lib/neutral/index.mjs +4 -4
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/lib/neutral/{move-6W6APHVW.mjs → move-UMDTQST4.mjs} +2 -2
- package/dist/lib/neutral/operations/index.mjs +1 -1
- package/dist/lib/neutral/{play-T5TY3ZWY.mjs → play-7XTJZ4N6.mjs} +2 -2
- package/dist/lib/neutral/plugin.mjs +1 -1
- package/dist/lib/neutral/{print-5KYMJ2SU.mjs → print-JR4VB3UX.mjs} +2 -2
- package/dist/lib/neutral/skill-definition-ZGQBUE4R.mjs +15 -0
- package/dist/lib/neutral/skill-definition-ZGQBUE4R.mjs.map +7 -0
- package/dist/lib/neutral/skills/index.mjs +8 -0
- package/dist/lib/neutral/testing.mjs +1 -1
- package/dist/lib/neutral/types/index.mjs +1 -1
- package/dist/types/src/capabilities/game-variant.d.ts +1 -2
- package/dist/types/src/capabilities/game-variant.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +1 -1
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/skill-definition.d.ts +5 -0
- package/dist/types/src/capabilities/skill-definition.d.ts.map +1 -0
- package/dist/types/src/components/Chessboard/Chessboard.d.ts +1 -1
- package/dist/types/src/components/Chessboard/Chessboard.d.ts.map +1 -1
- package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts +2 -2
- package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts.map +1 -1
- package/dist/types/src/containers/ChessArticle/ChessArticle.stories.d.ts +2 -2
- package/dist/types/src/containers/ChessArticle/ChessArticle.stories.d.ts.map +1 -1
- package/dist/types/src/containers/ChessCard/ChessCard.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +4 -0
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/skills/chess-skill.d.ts +4 -0
- package/dist/types/src/skills/chess-skill.d.ts.map +1 -0
- package/dist/types/src/skills/index.d.ts +2 -0
- package/dist/types/src/skills/index.d.ts.map +1 -0
- package/dist/types/src/types/Chess.d.ts +8 -7
- package/dist/types/src/types/Chess.d.ts.map +1 -1
- package/dist/types/src/types/ChessOperation.d.ts +2 -8
- package/dist/types/src/types/ChessOperation.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +38 -38
- package/src/ChessPlugin.node.ts +2 -2
- package/src/ChessPlugin.test.ts +1 -1
- package/src/ChessPlugin.tsx +3 -3
- package/src/capabilities/index.ts +1 -1
- package/src/capabilities/skill-definition.ts +14 -0
- package/src/components/Chessboard/Chessboard.stories.tsx +2 -2
- package/src/components/Chessboard/Chessboard.tsx +47 -45
- package/src/components/Chessboard/Info.tsx +3 -1
- package/src/containers/ChessArticle/ChessArticle.stories.tsx +2 -2
- package/src/containers/ChessCard/ChessCard.tsx +12 -5
- package/src/index.ts +1 -1
- package/src/{blueprints/chess-blueprint.ts → skills/chess-skill.ts} +7 -7
- package/src/skills/index.ts +5 -0
- package/src/types/Chess.ts +20 -21
- package/dist/lib/neutral/ChessCard-4TUTIFB6.mjs.map +0 -7
- package/dist/lib/neutral/blueprint-definition-4MOWVVWD.mjs +0 -15
- package/dist/lib/neutral/blueprint-definition-4MOWVVWD.mjs.map +0 -7
- package/dist/lib/neutral/blueprints/index.mjs +0 -8
- package/dist/lib/neutral/chunk-3WMTSPOZ.mjs.map +0 -7
- package/dist/lib/neutral/chunk-IQCSIZXM.mjs.map +0 -7
- package/dist/lib/neutral/chunk-S66CCWNQ.mjs.map +0 -7
- package/dist/types/src/blueprints/chess-blueprint.d.ts +0 -4
- package/dist/types/src/blueprints/chess-blueprint.d.ts.map +0 -1
- package/dist/types/src/blueprints/index.d.ts +0 -2
- package/dist/types/src/blueprints/index.d.ts.map +0 -1
- package/dist/types/src/capabilities/blueprint-definition.d.ts +0 -6
- package/dist/types/src/capabilities/blueprint-definition.d.ts.map +0 -1
- package/src/blueprints/index.ts +0 -5
- package/src/capabilities/blueprint-definition.ts +0 -19
- /package/dist/lib/neutral/{chunk-ZSC5H6M4.mjs.map → chunk-AMXVX7V2.mjs.map} +0 -0
- /package/dist/lib/neutral/{move-6W6APHVW.mjs.map → move-UMDTQST4.mjs.map} +0 -0
- /package/dist/lib/neutral/{play-T5TY3ZWY.mjs.map → play-7XTJZ4N6.mjs.map} +0 -0
- /package/dist/lib/neutral/{print-5KYMJ2SU.mjs.map → print-JR4VB3UX.mjs.map} +0 -0
- /package/dist/lib/neutral/{blueprints → skills}/index.mjs.map +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/plugin-chess",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Chess for new plugin",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"sideEffects": true,
|
|
14
14
|
"type": "module",
|
|
15
15
|
"imports": {
|
|
16
|
-
"#
|
|
17
|
-
"source": "./src/
|
|
18
|
-
"types": "./dist/types/src/
|
|
19
|
-
"default": "./dist/lib/neutral/
|
|
16
|
+
"#skills": {
|
|
17
|
+
"source": "./src/skills/index.ts",
|
|
18
|
+
"types": "./dist/types/src/skills/index.d.ts",
|
|
19
|
+
"default": "./dist/lib/neutral/skills/index.mjs"
|
|
20
20
|
},
|
|
21
21
|
"#capabilities": {
|
|
22
22
|
"source": "./src/capabilities/index.ts",
|
|
@@ -72,10 +72,10 @@
|
|
|
72
72
|
"default": "./dist/lib/neutral/index.mjs"
|
|
73
73
|
},
|
|
74
74
|
"./assets/PLUGIN.mdl": "./PLUGIN.mdl",
|
|
75
|
-
"./
|
|
76
|
-
"source": "./src/
|
|
77
|
-
"types": "./dist/types/src/
|
|
78
|
-
"default": "./dist/lib/neutral/
|
|
75
|
+
"./skills": {
|
|
76
|
+
"source": "./src/skills/index.ts",
|
|
77
|
+
"types": "./dist/types/src/skills/index.d.ts",
|
|
78
|
+
"default": "./dist/lib/neutral/skills/index.mjs"
|
|
79
79
|
},
|
|
80
80
|
"./plugin": {
|
|
81
81
|
"source": "./src/plugin.ts",
|
|
@@ -108,41 +108,41 @@
|
|
|
108
108
|
"dependencies": {
|
|
109
109
|
"@effect-atom/atom-react": "^0.5.0",
|
|
110
110
|
"chess.js": "^1.0.0",
|
|
111
|
-
"effect": "3.21.
|
|
112
|
-
"@dxos/app-framework": "0.
|
|
113
|
-
"@dxos/
|
|
114
|
-
"@dxos/
|
|
115
|
-
"@dxos/
|
|
116
|
-
"@dxos/
|
|
117
|
-
"@dxos/
|
|
118
|
-
"@dxos/echo-react": "0.
|
|
119
|
-
"@dxos/log": "0.
|
|
120
|
-
"@dxos/
|
|
121
|
-
"@dxos/plugin-
|
|
122
|
-
"@dxos/
|
|
123
|
-
"@dxos/react-
|
|
124
|
-
"@dxos/
|
|
125
|
-
"@dxos/react-ui-gameboard": "0.
|
|
126
|
-
"@dxos/
|
|
127
|
-
"@dxos/
|
|
111
|
+
"effect": "3.21.4",
|
|
112
|
+
"@dxos/app-framework": "0.10.0",
|
|
113
|
+
"@dxos/app-toolkit": "0.10.0",
|
|
114
|
+
"@dxos/async": "0.10.0",
|
|
115
|
+
"@dxos/compute": "0.10.0",
|
|
116
|
+
"@dxos/echo": "0.10.0",
|
|
117
|
+
"@dxos/invariant": "0.10.0",
|
|
118
|
+
"@dxos/echo-react": "0.10.0",
|
|
119
|
+
"@dxos/log": "0.10.0",
|
|
120
|
+
"@dxos/keys": "0.10.0",
|
|
121
|
+
"@dxos/plugin-client": "0.10.0",
|
|
122
|
+
"@dxos/plugin-game": "0.10.0",
|
|
123
|
+
"@dxos/react-client": "0.10.0",
|
|
124
|
+
"@dxos/react-ui-audio": "0.10.0",
|
|
125
|
+
"@dxos/react-ui-gameboard": "0.10.0",
|
|
126
|
+
"@dxos/util": "0.10.0",
|
|
127
|
+
"@dxos/react-ui-mosaic": "0.10.0"
|
|
128
128
|
},
|
|
129
129
|
"devDependencies": {
|
|
130
|
-
"@types/react": "~19.2.
|
|
130
|
+
"@types/react": "~19.2.17",
|
|
131
131
|
"@types/react-dom": "~19.2.3",
|
|
132
|
-
"react": "~19.2.
|
|
133
|
-
"react-dom": "~19.2.
|
|
132
|
+
"react": "~19.2.7",
|
|
133
|
+
"react-dom": "~19.2.7",
|
|
134
134
|
"vite": "^8.0.16",
|
|
135
|
-
"@dxos/plugin-testing": "0.
|
|
136
|
-
"@dxos/
|
|
137
|
-
"@dxos/
|
|
138
|
-
"@dxos/ui-theme": "0.
|
|
139
|
-
"@dxos/
|
|
135
|
+
"@dxos/plugin-testing": "0.10.0",
|
|
136
|
+
"@dxos/react-ui": "0.10.0",
|
|
137
|
+
"@dxos/storybook-utils": "0.10.0",
|
|
138
|
+
"@dxos/ui-theme": "0.10.0",
|
|
139
|
+
"@dxos/plugin-theme": "0.10.0"
|
|
140
140
|
},
|
|
141
141
|
"peerDependencies": {
|
|
142
|
-
"react": "~19.2.
|
|
143
|
-
"react-dom": "~19.2.
|
|
144
|
-
"@dxos/react-ui": "0.
|
|
145
|
-
"@dxos/ui-theme": "0.
|
|
142
|
+
"react": "~19.2.7",
|
|
143
|
+
"react-dom": "~19.2.7",
|
|
144
|
+
"@dxos/react-ui": "0.10.0",
|
|
145
|
+
"@dxos/ui-theme": "0.10.0"
|
|
146
146
|
},
|
|
147
147
|
"publishConfig": {
|
|
148
148
|
"access": "public"
|
package/src/ChessPlugin.node.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { Plugin } from '@dxos/app-framework';
|
|
6
6
|
import { AppPlugin } from '@dxos/app-toolkit';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { OperationHandler, SkillDefinition } from '#capabilities';
|
|
9
9
|
import { meta } from '#meta';
|
|
10
10
|
import { Chess } from '#types';
|
|
11
11
|
|
|
@@ -15,7 +15,7 @@ import { Chess } from '#types';
|
|
|
15
15
|
*/
|
|
16
16
|
export const ChessPlugin = Plugin.define(meta).pipe(
|
|
17
17
|
AppPlugin.addSchemaModule({ schema: [Chess.State] }),
|
|
18
|
-
AppPlugin.
|
|
18
|
+
AppPlugin.addSkillDefinitionModule({ activate: SkillDefinition }),
|
|
19
19
|
AppPlugin.addOperationHandlerModule({ activate: OperationHandler }),
|
|
20
20
|
Plugin.make,
|
|
21
21
|
);
|
package/src/ChessPlugin.test.ts
CHANGED
|
@@ -28,7 +28,7 @@ describe('ChessPlugin', () => {
|
|
|
28
28
|
|
|
29
29
|
// SetupArtifactDefinition is fired by AssistantPlugin, which can't be included here due to a workspace cycle.
|
|
30
30
|
await harness.fire(AppActivationEvents.SetupArtifactDefinition);
|
|
31
|
-
expect(harness.manager.getActive()).toContain(moduleId('
|
|
31
|
+
expect(harness.manager.getActive()).toContain(moduleId('SkillDefinition'));
|
|
32
32
|
|
|
33
33
|
// Operation handlers are not loaded on startup — SetupProcessManager fires lazily when an operation is invoked.
|
|
34
34
|
await harness.fire(ActivationEvents.SetupProcessManager);
|
package/src/ChessPlugin.tsx
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { Plugin } from '@dxos/app-framework';
|
|
6
|
-
import {
|
|
6
|
+
import { AppActivationEvents, AppPlugin } from '@dxos/app-toolkit';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { GameVariant, OperationHandler, SkillDefinition } from '#capabilities';
|
|
9
9
|
import { meta } from '#meta';
|
|
10
10
|
import { translations } from '#translations';
|
|
11
11
|
import { Chess } from '#types';
|
|
@@ -19,7 +19,7 @@ export const ChessPlugin = Plugin.define(meta).pipe(
|
|
|
19
19
|
activatesOn: AppActivationEvents.SetupSchema,
|
|
20
20
|
activate: GameVariant,
|
|
21
21
|
}),
|
|
22
|
-
AppPlugin.
|
|
22
|
+
AppPlugin.addSkillDefinitionModule({ activate: SkillDefinition }),
|
|
23
23
|
AppPlugin.addOperationHandlerModule({ activate: OperationHandler }),
|
|
24
24
|
AppPlugin.addPluginAssetModule({
|
|
25
25
|
asset: { pluginId: meta.profile.key, path: 'PLUGIN.mdl', content: pluginSpec, mimeType: 'application/x-mdl' },
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { Capability } from '@dxos/app-framework';
|
|
6
6
|
import type { OperationHandlerSet } from '@dxos/compute';
|
|
7
7
|
|
|
8
|
-
export const
|
|
8
|
+
export const SkillDefinition = Capability.lazy('SkillDefinition', () => import('./skill-definition'));
|
|
9
9
|
export const GameVariant = Capability.lazy('GameVariant', () => import('./game-variant'));
|
|
10
10
|
export const OperationHandler = Capability.lazy<OperationHandlerSet.OperationHandlerSet>(
|
|
11
11
|
'OperationHandler',
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import { Capability } from '@dxos/app-framework';
|
|
8
|
+
import { AppCapabilities } from '@dxos/app-toolkit';
|
|
9
|
+
|
|
10
|
+
import { ChessSkill } from '#skills';
|
|
11
|
+
|
|
12
|
+
const skillDefinition = () => Effect.succeed([Capability.contributes(AppCapabilities.SkillDefinition, ChessSkill)]);
|
|
13
|
+
|
|
14
|
+
export default skillDefinition;
|
|
@@ -20,11 +20,11 @@ const SAMPLE_PGN =
|
|
|
20
20
|
const PROMOTION_PGN =
|
|
21
21
|
'1. e4 e5 2. Nf3 Nc6 3. Bc4 Bc5 4. c3 Nf6 5. d4 exd4 6. cxd4 Bb4+ 7. Nc3 d5 8. exd5 Nxd5 9. O-O Be6 10. Qb3 Na5 11. Qa4+ c6 12. Bxd5 Bxc3 13. Bxe6 fxe6 14. d5 Qg5 15. dxe6 Kf8 16. e7+ Kg8 *';
|
|
22
22
|
|
|
23
|
-
type
|
|
23
|
+
type StoryArgs = {
|
|
24
24
|
pgn?: string;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
const DefaultStory = ({ pgn }:
|
|
27
|
+
const DefaultStory = ({ pgn }: StoryArgs) => {
|
|
28
28
|
const state = useMemo(() => Chess.make(pgn ? { pgn } : undefined), [pgn]);
|
|
29
29
|
const [orientation, setOrientation] = useState<Player>('white');
|
|
30
30
|
const [showInfo, setShowInfo] = useState(true);
|
|
@@ -11,10 +11,8 @@ import React, {
|
|
|
11
11
|
useEffect,
|
|
12
12
|
useImperativeHandle,
|
|
13
13
|
useMemo,
|
|
14
|
-
useRef,
|
|
15
14
|
} from 'react';
|
|
16
15
|
|
|
17
|
-
import { addEventListener } from '@dxos/async';
|
|
18
16
|
import { useObject } from '@dxos/echo-react';
|
|
19
17
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
20
18
|
import { useSoundEffect } from '@dxos/react-ui-audio';
|
|
@@ -25,7 +23,6 @@ import {
|
|
|
25
23
|
Chessboard as NaturalChessboard,
|
|
26
24
|
type ChessboardProps as NaturalChessboardProps,
|
|
27
25
|
getRawPgn,
|
|
28
|
-
useGameboardContext,
|
|
29
26
|
} from '@dxos/react-ui-gameboard';
|
|
30
27
|
|
|
31
28
|
import { type Chess } from '#types';
|
|
@@ -88,9 +85,48 @@ const Root = forwardRef<ChessboardController, RootProps>(({ state, children }, f
|
|
|
88
85
|
[model],
|
|
89
86
|
);
|
|
90
87
|
|
|
88
|
+
// Keyboard navigation — fires regardless of which descendant (Board or Info) has focus.
|
|
89
|
+
// Gated to elements marked data-chessboard-arrow-navigation to avoid intercepting toolbar controls.
|
|
90
|
+
const handleKeyDown = useCallback(
|
|
91
|
+
(ev: React.KeyboardEvent) => {
|
|
92
|
+
const target = ev.target instanceof HTMLElement ? ev.target : undefined;
|
|
93
|
+
if (!target?.closest('[data-chessboard-arrow-navigation]')) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const moveIndex = registry.get(model.moveIndex);
|
|
98
|
+
switch (ev.key) {
|
|
99
|
+
case 'ArrowUp':
|
|
100
|
+
ev.preventDefault();
|
|
101
|
+
model.setMoveIndex(0);
|
|
102
|
+
break;
|
|
103
|
+
case 'ArrowDown':
|
|
104
|
+
ev.preventDefault();
|
|
105
|
+
model.setMoveIndex(model.game.history().length);
|
|
106
|
+
break;
|
|
107
|
+
case 'ArrowLeft':
|
|
108
|
+
if (moveIndex > 0) {
|
|
109
|
+
ev.preventDefault();
|
|
110
|
+
model.setMoveIndex(moveIndex - 1);
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
case 'ArrowRight':
|
|
114
|
+
if (moveIndex < model.game.history().length) {
|
|
115
|
+
ev.preventDefault();
|
|
116
|
+
model.setMoveIndex(moveIndex + 1);
|
|
117
|
+
}
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
[registry, model],
|
|
122
|
+
);
|
|
123
|
+
|
|
91
124
|
return (
|
|
92
125
|
<Gameboard.Root model={model} onDrop={handleDrop}>
|
|
93
|
-
{
|
|
126
|
+
{/* display:contents is layout-transparent; catches keydown bubbled from any focused descendant. */}
|
|
127
|
+
<div className='contents' onKeyDown={handleKeyDown}>
|
|
128
|
+
{children}
|
|
129
|
+
</div>
|
|
94
130
|
</Gameboard.Root>
|
|
95
131
|
);
|
|
96
132
|
});
|
|
@@ -119,45 +155,11 @@ const BOARD_NAME = 'Chessboard.Board';
|
|
|
119
155
|
|
|
120
156
|
type BoardProps = NaturalChessboardProps;
|
|
121
157
|
|
|
122
|
-
const Board = (props: BoardProps) =>
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const ref = useRef<HTMLDivElement>(null);
|
|
128
|
-
useEffect(() => {
|
|
129
|
-
if (!ref.current) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Participate in keyboard navigation (set tabIndex={0})
|
|
134
|
-
ref.current.setAttribute('data-arrow-keys', 'all');
|
|
135
|
-
|
|
136
|
-
return addEventListener(ref.current, 'keydown', (ev) => {
|
|
137
|
-
const moveIndex = registry.get(model.moveIndex);
|
|
138
|
-
switch (ev.key) {
|
|
139
|
-
case 'ArrowUp':
|
|
140
|
-
model.setMoveIndex(0);
|
|
141
|
-
break;
|
|
142
|
-
case 'ArrowDown':
|
|
143
|
-
model.setMoveIndex(model.game.history().length);
|
|
144
|
-
break;
|
|
145
|
-
case 'ArrowLeft':
|
|
146
|
-
if (moveIndex > 0) {
|
|
147
|
-
model.setMoveIndex(moveIndex - 1);
|
|
148
|
-
}
|
|
149
|
-
break;
|
|
150
|
-
case 'ArrowRight':
|
|
151
|
-
if (moveIndex < model.game.history().length) {
|
|
152
|
-
model.setMoveIndex(moveIndex + 1);
|
|
153
|
-
}
|
|
154
|
-
break;
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}, [registry, model]);
|
|
158
|
-
|
|
159
|
-
return <NaturalChessboard {...props} ref={ref} />;
|
|
160
|
-
};
|
|
158
|
+
const Board = (props: BoardProps) => (
|
|
159
|
+
<div className='contents' data-chessboard-arrow-navigation>
|
|
160
|
+
<NaturalChessboard {...props} />
|
|
161
|
+
</div>
|
|
162
|
+
);
|
|
161
163
|
|
|
162
164
|
Board.displayName = BOARD_NAME;
|
|
163
165
|
|
|
@@ -173,8 +175,8 @@ export const Chessboard = {
|
|
|
173
175
|
};
|
|
174
176
|
|
|
175
177
|
export type {
|
|
176
|
-
RootProps as ChessboardRootProps,
|
|
177
|
-
ContentProps as ChessboardContentProps,
|
|
178
178
|
BoardProps as ChessboardBoardProps,
|
|
179
|
+
ContentProps as ChessboardContentProps,
|
|
179
180
|
InfoProps as ChessboardInfoProps,
|
|
181
|
+
RootProps as ChessboardRootProps,
|
|
180
182
|
};
|
|
@@ -131,7 +131,9 @@ const History = ({ classNames, model, min, max, onSelect }: HistoryProps) => {
|
|
|
131
131
|
return (
|
|
132
132
|
<div
|
|
133
133
|
ref={scrollerRef}
|
|
134
|
-
|
|
134
|
+
tabIndex={0}
|
|
135
|
+
data-chessboard-arrow-navigation
|
|
136
|
+
className={mx('overflow-y-auto outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500', classNames)}
|
|
135
137
|
style={{
|
|
136
138
|
minHeight: min === undefined ? 'auto' : `${min * 24}px`,
|
|
137
139
|
maxHeight: max === undefined ? 'auto' : `${max * 24}px`,
|
|
@@ -15,11 +15,11 @@ import { Chess } from '#types';
|
|
|
15
15
|
|
|
16
16
|
import { ChessArticle } from './ChessArticle';
|
|
17
17
|
|
|
18
|
-
type
|
|
18
|
+
type StoryArgs = {
|
|
19
19
|
pgn?: string;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
const DefaultStory = ({ pgn }:
|
|
22
|
+
const DefaultStory = ({ pgn }: StoryArgs) => {
|
|
23
23
|
const { game, state } = useMemo(() => {
|
|
24
24
|
const state = Chess.make(pgn ? { pgn } : undefined);
|
|
25
25
|
const game = makeGame({ name: 'Story game', variant: state as Obj.Unknown });
|
|
@@ -6,6 +6,7 @@ import React from 'react';
|
|
|
6
6
|
|
|
7
7
|
import { Obj } from '@dxos/echo';
|
|
8
8
|
import { type GameVariantSurfaceProps } from '@dxos/plugin-game/types';
|
|
9
|
+
import { Card } from '@dxos/react-ui';
|
|
9
10
|
|
|
10
11
|
import { Chessboard } from '#components';
|
|
11
12
|
import { Chess } from '#types';
|
|
@@ -18,10 +19,16 @@ export const ChessCard = ({ variant }: ChessCardProps) => {
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
return (
|
|
21
|
-
<
|
|
22
|
-
<
|
|
23
|
-
<
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
<Card.Body>
|
|
23
|
+
<Card.Section classNames='aspect-square'>
|
|
24
|
+
<Card.Row fullWidth>
|
|
25
|
+
<Chessboard.Root state={variant}>
|
|
26
|
+
<Chessboard.Content>
|
|
27
|
+
<Chessboard.Board />
|
|
28
|
+
</Chessboard.Content>
|
|
29
|
+
</Chessboard.Root>
|
|
30
|
+
</Card.Row>
|
|
31
|
+
</Card.Section>
|
|
32
|
+
</Card.Body>
|
|
26
33
|
);
|
|
27
34
|
};
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Skill, Template } from '@dxos/compute';
|
|
6
6
|
import { trim } from '@dxos/util';
|
|
7
7
|
|
|
8
8
|
import { Chess, ChessOperation } from '#types';
|
|
@@ -10,10 +10,10 @@ import { Chess, ChessOperation } from '#types';
|
|
|
10
10
|
const operations = [ChessOperation.Move, ChessOperation.Play, ChessOperation.Print];
|
|
11
11
|
|
|
12
12
|
const make = () =>
|
|
13
|
-
|
|
14
|
-
key: Chess.
|
|
13
|
+
Skill.make({
|
|
14
|
+
key: Chess.SKILL_KEY,
|
|
15
15
|
name: 'Chess',
|
|
16
|
-
tools:
|
|
16
|
+
tools: Skill.toolDefinitions({ operations }),
|
|
17
17
|
instructions: Template.make({
|
|
18
18
|
source: trim`
|
|
19
19
|
You are an expert chess player.
|
|
@@ -28,9 +28,9 @@ const make = () =>
|
|
|
28
28
|
}),
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
const
|
|
32
|
-
key: Chess.
|
|
31
|
+
const skill: Skill.Definition = {
|
|
32
|
+
key: Chess.SKILL_KEY,
|
|
33
33
|
make,
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
export default
|
|
36
|
+
export default skill;
|
package/src/types/Chess.ts
CHANGED
|
@@ -6,35 +6,34 @@ import { Chess as ChessJS } from 'chess.js';
|
|
|
6
6
|
import * as Schema from 'effect/Schema';
|
|
7
7
|
|
|
8
8
|
import { AppAnnotation } from '@dxos/app-toolkit';
|
|
9
|
-
import {
|
|
9
|
+
import { Annotation, DXN, Obj, Type } from '@dxos/echo';
|
|
10
10
|
import { FormInputAnnotation, HiddenAnnotation } from '@dxos/echo/Annotation';
|
|
11
11
|
import { log } from '@dxos/log';
|
|
12
12
|
|
|
13
|
-
export const
|
|
13
|
+
export const SKILL_KEY = 'org.dxos.skill.chess';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Chess variant state. Referenced by the base `Game` object via `Game.variant`.
|
|
17
17
|
* Players, name, and other game-shared fields live on the base `Game`.
|
|
18
18
|
*/
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}).pipe(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
export type State = Type.InstanceType<typeof State>;
|
|
19
|
+
export class State extends Type.makeObject<State>(DXN.make('org.dxos.type.chess.state', '0.1.0'))(
|
|
20
|
+
Schema.Struct({
|
|
21
|
+
pgn: Schema.String.annotations({
|
|
22
|
+
description: 'Portable Game Notation.',
|
|
23
|
+
}).pipe(FormInputAnnotation.set(false), Schema.optional),
|
|
24
|
+
fen: Schema.String.annotations({
|
|
25
|
+
description: 'Forsyth-Edwards Notation.',
|
|
26
|
+
}).pipe(FormInputAnnotation.set(false), Schema.optional),
|
|
27
|
+
}).pipe(
|
|
28
|
+
Annotation.IconAnnotation.set({ icon: 'ph--shield-chevron--regular', hue: 'amber' }),
|
|
29
|
+
AppAnnotation.SkillsAnnotation.set([SKILL_KEY]),
|
|
30
|
+
// Implementation detail of the unified `Game` schema. The user-facing object is `Game`;
|
|
31
|
+
// this state is only ever referenced via `Game.variant`. HiddenAnnotation keeps it out of the
|
|
32
|
+
// navtree's typed branches so an orphaned state object doesn't reappear after the
|
|
33
|
+
// wrapping Game is deleted.
|
|
34
|
+
HiddenAnnotation.set(true),
|
|
35
|
+
),
|
|
36
|
+
) {}
|
|
38
37
|
|
|
39
38
|
export const make = ({ pgn, fen }: { pgn?: string; fen?: string } = {}): State => {
|
|
40
39
|
const chess = new ChessJS();
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/containers/ChessCard/ChessCard.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport React from 'react';\n\nimport { Obj } from '@dxos/echo';\nimport { type GameVariantSurfaceProps } from '@dxos/plugin-game/types';\n\nimport { Chessboard } from '#components';\nimport { Chess } from '#types';\n\nexport type ChessCardProps = GameVariantSurfaceProps;\n\nexport const ChessCard = ({ variant }: ChessCardProps) => {\n if (!Obj.instanceOf(Chess.State, variant)) {\n return null;\n }\n\n return (\n <Chessboard.Root state={variant}>\n <Chessboard.Content>\n <Chessboard.Board />\n </Chessboard.Content>\n </Chessboard.Root>\n );\n};\n"],
|
|
5
|
-
"mappings": ";;;AAIA,OAAOA,WAAW;AAElB,SAASC,WAAW;AAGpB,SAASC,kBAAkB;AAC3B,SAASC,aAAa;AAIf,IAAMC,YAAY,CAAC,EAAEC,QAAO,MAAkB;AACnD,MAAI,CAACJ,IAAIK,WAAWH,MAAMI,OAAOF,OAAAA,GAAU;AACzC,WAAO;EACT;AAEA,SACE,sBAAA,cAACH,WAAWM,MAAI;IAACC,OAAOJ;KACtB,sBAAA,cAACH,WAAWQ,SAAO,MACjB,sBAAA,cAACR,WAAWS,OAAK,IAAA,CAAA,CAAA;AAIzB;",
|
|
6
|
-
"names": ["React", "Obj", "Chessboard", "Chess", "ChessCard", "variant", "instanceOf", "State", "Root", "state", "Content", "Board"]
|
|
7
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import "./chunk-J5LGTIGS.mjs";
|
|
2
|
-
|
|
3
|
-
// src/capabilities/blueprint-definition.ts
|
|
4
|
-
import * as Effect from "effect/Effect";
|
|
5
|
-
import { Capability } from "@dxos/app-framework";
|
|
6
|
-
import { AppCapabilities } from "@dxos/app-toolkit";
|
|
7
|
-
import { ChessBlueprint } from "#blueprints";
|
|
8
|
-
var blueprintDefinition = () => Effect.succeed([
|
|
9
|
-
Capability.contributes(AppCapabilities.BlueprintDefinition, ChessBlueprint)
|
|
10
|
-
]);
|
|
11
|
-
var blueprint_definition_default = blueprintDefinition;
|
|
12
|
-
export {
|
|
13
|
-
blueprint_definition_default as default
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=blueprint-definition-4MOWVVWD.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/capabilities/blueprint-definition.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\n\nimport { Capability } from '@dxos/app-framework';\nimport { AppCapabilities } from '@dxos/app-toolkit';\n\nimport { ChessBlueprint } from '#blueprints';\n\n// NOTE: Explicit annotation required: d.ts emit cannot portably name the inferred @dxos/compute types (TS2883).\nconst blueprintDefinition: () => Effect.Effect<\n Capability.Capability<typeof AppCapabilities.BlueprintDefinition>[],\n never,\n Capability.Service\n> = () => Effect.succeed([Capability.contributes(AppCapabilities.BlueprintDefinition, ChessBlueprint)]);\n\nexport default blueprintDefinition;\n"],
|
|
5
|
-
"mappings": ";;;AAIA,YAAYA,YAAY;AAExB,SAASC,kBAAkB;AAC3B,SAASC,uBAAuB;AAEhC,SAASC,sBAAsB;AAG/B,IAAMC,sBAIF,MAAaC,eAAQ;EAACJ,WAAWK,YAAYJ,gBAAgBK,qBAAqBJ,cAAAA;CAAgB;AAEtG,IAAA,+BAAeC;",
|
|
6
|
-
"names": ["Effect", "Capability", "AppCapabilities", "ChessBlueprint", "blueprintDefinition", "succeed", "contributes", "BlueprintDefinition"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/blueprints/chess-blueprint.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Blueprint, Template } from '@dxos/compute';\nimport { trim } from '@dxos/util';\n\nimport { Chess, ChessOperation } from '#types';\n\nconst operations = [ChessOperation.Move, ChessOperation.Play, ChessOperation.Print];\n\nconst make = () =>\n Blueprint.make({\n key: Chess.BLUEPRINT_KEY,\n name: 'Chess',\n tools: Blueprint.toolDefinitions({ operations }),\n instructions: Template.make({\n source: trim`\n You are an expert chess player.\n To analyze a game you can access the \"pgn\" property by loading the context object that represents the current game.\n You could suggest a good next move or offer to play a move.\n Don't actually make a move unless you are asked to.\n\n When setting a chess position, always set the \"pgn\" field (move list in standard PGN notation) on the org.dxos.type.chess.state object.\n The \"fen\" field is not used by the UI for display — the board is driven exclusively from \"pgn\".\n Setting \"fen\" alone or leaving \"pgn\" empty will result in the initial position being shown.\n `,\n }),\n });\n\nconst blueprint: Blueprint.Definition = {\n key: Chess.BLUEPRINT_KEY,\n make,\n};\n\nexport default blueprint;\n"],
|
|
5
|
-
"mappings": ";AAIA,SAASA,WAAWC,gBAAgB;AACpC,SAASC,YAAY;AAErB,SAASC,OAAOC,sBAAsB;AAEtC,IAAMC,aAAa;EAACD,eAAeE;EAAMF,eAAeG;EAAMH,eAAeI;;AAE7E,IAAMC,OAAO,MACXT,UAAUS,KAAK;EACbC,KAAKP,MAAMQ;EACXC,MAAM;EACNC,OAAOb,UAAUc,gBAAgB;IAAET;EAAW,CAAA;EAC9CU,cAAcd,SAASQ,KAAK;IAC1BO,QAAQd;;;;;;;;;;EAUV,CAAA;AACF,CAAA;AAEF,IAAMe,YAAkC;EACtCP,KAAKP,MAAMQ;EACXF;AACF;AAEA,IAAA,0BAAeQ;",
|
|
6
|
-
"names": ["Blueprint", "Template", "trim", "Chess", "ChessOperation", "operations", "Move", "Play", "Print", "make", "key", "BLUEPRINT_KEY", "name", "tools", "toolDefinitions", "instructions", "source", "blueprint"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/ChessPlugin.tsx", "raw-loader:/__w/dxos/dxos/packages/plugins/plugin-chess/PLUGIN.mdl"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Plugin } from '@dxos/app-framework';\nimport { AppPlugin, AppActivationEvents } from '@dxos/app-toolkit';\n\nimport { BlueprintDefinition, GameVariant, OperationHandler } from '#capabilities';\nimport { meta } from '#meta';\nimport { translations } from '#translations';\nimport { Chess } from '#types';\n\n// eslint-disable-next-line import/no-relative-packages\nimport pluginSpec from '../PLUGIN.mdl?raw';\n\nexport const ChessPlugin = Plugin.define(meta).pipe(\n Plugin.addModule({\n id: 'game-variant',\n activatesOn: AppActivationEvents.SetupSchema,\n activate: GameVariant,\n }),\n AppPlugin.addBlueprintDefinitionModule({ activate: BlueprintDefinition }),\n AppPlugin.addOperationHandlerModule({ activate: OperationHandler }),\n AppPlugin.addPluginAssetModule({\n asset: { pluginId: meta.profile.key, path: 'PLUGIN.mdl', content: pluginSpec, mimeType: 'application/x-mdl' },\n }),\n AppPlugin.addSchemaModule({ schema: [Chess.State] }),\n AppPlugin.addTranslationsModule({ translations }),\n Plugin.make,\n);\n\nexport default ChessPlugin;\n", "---\nid: org.dxos.plugin.chess\nname: ChessPlugin\nversion: 0.1.0\n---\n\nA two-player chess game plugin for `DXOS` Composer.\n\n## Extensions\n\nThe following extension dialects are used in this document.\nEach extension is defined in the Appendix or resolved via its URI.\n\n| Term | URI |\n|-------------|--------------------------------|\n| `type` | `org.dxos.mdl.type@1.0` |\n| `feat` | `org.dxos.mdl.feat@1.0` |\n| `test` | `org.dxos.mdl.test@1.0` |\n| `component` | `org.dxos.mdl.component@1.0` |\n| `op` | `org.dxos.mdl.op@1.0` |\n| `service` | `org.dxos.mdl.service@1.0` |\n\n## Types\n\n```mdl\ntype Color\n literals: white | black\n```\n\n```mdl\ntype PieceKind\n literals: pawn | rook | knight | bishop | queen | king\n```\n\n```mdl\ntype Piece\n fields:\n kind: PieceKind\n color: Color\n```\n\n```mdl\ntype Square\n fields:\n file: a | b | c | d | e | f | g | h\n rank: 1..8\n piece?: Piece\n```\n\n```mdl\ntype Move\n fields:\n from: Square\n to: Square\n promotion?: PieceKind # only valid for pawn reaching back rank\n```\n\n```mdl\ntype Board\n fields:\n squares: Square[8][8]\n turn: Color\n status: playing | check | checkmate | stalemate\n moves: Move[] # full move history\n```\n\n```mdl\ntype Player\n fields:\n id: string\n name: string\n color: Color\n```\n\n```mdl\ntype GameStatus\n literals: waiting | active | finished\n```\n\n```mdl\ntype Game\n fields:\n id: string\n players: Player[2]\n board: Board\n status: GameStatus\n winner?: Player\n```\n\n## Components\n\n```mdl\ncomponent Lobby\n desc: Entry point where players create or join a game.\n props:\n playerId: string\n state:\n games: Game[] # list of open/active games\n selected?: Game\n slots:\n header?: ReactNode\n empty?: ReactNode # shown when games list is empty\n actions:\n createGame() \u2192 Game\n joinGame(game: Game) \u2192 Game\n spectate(game: Game)\n emits:\n onJoin(game: Game)\n layout: |\n \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n \u2502 [header slot] \u2502\n \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n \u2502 Game list \u2502\n \u2502 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u2502\n \u2502 \u2502 game row \u2502 \u2502\n \u2502 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2502\n \u2502 [empty slot] \u2502\n \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n \u2502 [Create Game] \u2502\n \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n```\n\n```mdl\ncomponent Gameboard\n desc: Interactive chess board for an active game.\n props:\n game: Game\n playerId: string # identifies which side the viewer plays\n state:\n selected?: Square # currently selected square\n highlights: Square[] # legal move targets for selected piece\n perspective: Color # which side is at the bottom (default: player's color)\n slots:\n toolbar?: ReactNode\n sidebar?: ReactNode\n overlay?: ReactNode # e.g. checkmate / promotion dialogs\n actions:\n selectSquare(square: Square)\n submitMove(move: Move)\n flipBoard()\n emits:\n onMove(move: Move)\n onResign()\n layout: |\n \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n \u2502 [toolbar slot] \u2502\n \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n \u2502 \u2502 [sidebar] \u2502\n \u2502 8\u00D78 \u2502 \u2502\n \u2502 board \u2502 move history \u2502\n \u2502 \u2502 \u2502\n \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n \u2502 [overlay slot] \u2502\n \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n```\n\n## Services\n\n```mdl\nservice ChessEngine\n desc: Validates moves and computes game state. May be local (WASM) or remote.\n loading: lazy\n ops:\n validate(board: Board, move: Move) \u2192 Move\n legalMoves(board: Board, square: Square) \u2192 Square[]\n applyMove(board: Board, move: Move) \u2192 Board\n errors:\n EngineNotReady: engine has not finished loading\n```\n\n```mdl\nservice GameStore\n desc: Persists and replicates Game state via ECHO.\n ops:\n create(white: Player, black: Player) \u2192 Game\n load(id: string) \u2192 Game\n save(game: Game) \u2192 Game\n list() \u2192 Game[]\n effects: [echo:write, echo:read]\n```\n\n## Operations\n\nPure operations (no effects, no service dependencies) \u2014 safe to call anywhere.\n\n```mdl\nop getLegalMoves\n desc: Returns legal target squares for the piece on the given square.\n input:\n board: Board\n square: Square\n output: Square[]\n errors:\n EmptySquare: no piece on square\n WrongSide: piece does not belong to the active side\n requires: [ChessEngine]\n```\n\n```mdl\nop validateMove\n desc: Checks a move against chess rules without mutating state.\n input:\n board: Board\n move: Move\n output: Move\n errors:\n IllegalMove: move violates chess rules\n WrongTurn: piece does not belong to the active side\n GameOver: game has already ended\n requires: [ChessEngine]\n```\n\n```mdl\nop applyMove\n desc: Applies a validated move and returns the next board state.\n input:\n board: Board\n move: Move # must be pre-validated\n output: Board\n requires: [ChessEngine]\n note: does not persist; use submitMove for the full transactional flow\n```\n\nEffectful operations \u2014 mutate persistent state.\n\n```mdl\nop startGame\n desc: Creates a new Game with two players and an initial Board.\n input:\n white: Player\n black: Player\n output: Game\n effects: [echo:write]\n requires: [GameStore]\n```\n\n```mdl\nop submitMove\n desc: Validates and applies a move, then persists the updated Game.\n input:\n game: Game\n player: Player\n move: Move\n output: Game\n errors:\n WrongTurn: player is not the active side\n IllegalMove: move violates chess rules\n GameOver: game has already ended\n effects: [echo:write]\n requires: [ChessEngine, GameStore]\n note: |\n Composes validateMove \u2192 applyMove \u2192 GameStore.save.\n Atomic: Game is not persisted if validation fails.\n```\n\n```mdl\nop resignGame\n desc: Player forfeits; opponent wins.\n input:\n game: Game\n player: Player\n output: Game # Game.status === finished, Game.winner set\n errors:\n GameOver: game has already ended\n effects: [echo:write]\n requires: [GameStore]\n```\n\n## Features\n\n```mdl\nfeat F-1: Start Game\n\n req F-1.1: New Board created with pieces in standard starting positions.\n req F-1.2: White moves first.\n```\n\n```mdl\nfeat F-2: Make Move\n\n req F-2.1:\n when: player submits a Move on their turn\n then: Move validated against chess rules\n errors: [InvalidMove, WrongTurn, GameOver]\n\n req F-2.2:\n when: Move is valid\n then: Board updated; turn advances to opponent\n\n req F-2.3:\n when: resulting position leaves opponent's king in check\n then: Board.status set to check\n\n req F-2.4:\n when: no legal moves remain for the side to move\n then: Board.status set to checkmate (if in check) or stalemate\n```\n\n```mdl\nfeat F-3: Lobby\n\n req F-3.1: Player sees list of open games on entering the Lobby.\n req F-3.2:\n when: player creates a game\n then: new Game created with status waiting; player assigned white\n\n req F-3.3:\n when: second player joins an open game\n then: Game.status transitions to active; joining player assigned black\n\n req F-3.4:\n when: Game.status becomes active\n then: both players navigated to Gameboard\n```\n\n```mdl\nfeat F-4: Gameboard\n\n req F-4.1:\n when: player selects a square containing their piece\n then: legal move targets highlighted on board\n\n req F-4.2:\n when: player selects a highlighted target square\n then: Move submitted via submitMove(); board updated on success\n\n req F-4.3:\n when: pawn reaches the back rank\n then: promotion dialog shown via overlay slot; player selects piece kind\n\n req F-4.4:\n when: Game.status is finished\n then: result overlay shown (winner or draw); further moves disabled\n```\n\n```mdl\nfeat F-5: Move Validation\n\n req F-5.1:\n when: Gameboard calls submitMove\n then: op:validateMove runs before any state change\n\n req F-5.2:\n when: validation fails\n then: error returned to caller; Game state unchanged\n\n req F-5.3:\n when: square is selected on Gameboard\n then: op:getLegalMoves called; results drive component:Gameboard.highlights\n```\n\n```mdl\nfeat F-6: Game Persistence\n\n req F-6.1:\n when: op:startGame completes\n then: Game written to ECHO and visible in component:Lobby game list\n\n req F-6.2:\n when: op:submitMove completes\n then: updated Game replicated to all peers via ECHO\n\n req F-6.3:\n when: peer receives a Game update\n then: component:Gameboard re-renders with new Board state\n tags: [collaborative]\n```\n\n## Acceptance\n\n```mdl\ntest T-1: New game starting position\n given: a new game is started\n then:\n - Board.turn === white\n - Board.status === playing\n - each player has 16 pieces in standard positions\n```\n\n```mdl\ntest T-2: Illegal move rejected\n given: it is white's turn\n when: white attempts to move a black piece\n then: WrongTurn error; Board unchanged\n```\n\n```mdl\ntest T-3: Create and join game\n given: two players are in the Lobby\n when: player A creates a game, player B joins it\n then:\n - Game.status === active\n - Game.players[0].color === white # creator\n - Game.players[1].color === black # joiner\n - both players see the Gameboard\n```\n\n```mdl\ntest T-4: Legal move highlight\n given: Gameboard is shown, it is white's turn\n when: white selects the e2 pawn\n then:\n - squares e3 and e4 are highlighted\n - no other squares are highlighted\n```\n\n```mdl\ntest T-5: Pawn promotion\n given: white pawn is on e7, it is white's turn\n when: white moves pawn to e8\n then:\n - promotion overlay appears\n - after player selects queen, Move recorded with promotion: queen\n - board shows white queen on e8\n```\n\n```mdl\ntest T-6: Submit valid move\n given: active game, white's turn, white player logged in\n when: white submits pawn e2\u2192e4\n then:\n - op:validateMove returns move without error\n - Board updated: e4 occupied by white pawn, e2 empty\n - Game.board.turn === black\n - Game persisted to ECHO\n```\n\n```mdl\ntest T-7: Submit invalid move rejected atomically\n given: active game, white's turn\n when: white submits an illegal move (e2\u2192e5)\n then:\n - IllegalMove error returned\n - Game.board unchanged\n - no ECHO write occurs\n```\n\n```mdl\ntest T-8: Legal moves highlighted\n given: new game, white's turn, Gameboard shown\n when: player selects e2\n then:\n - op:getLegalMoves returns [e3, e4]\n - Gameboard.highlights === [e3, e4]\n```\n\n---\n\n## Appendix: Extension Definitions\n\nExtension block types used in this document are defined below using\nthe core `ext` primitive \u2014 the only construct the base language provides.\n\n```mdl\next type\n uri: dxos.spec/ext/type@1.0\n desc: A named data structure with typed fields and optional literals.\n fields:\n desc?: Prose\n fields?: FieldMap # name[?]: TypeExpr (# inline comment)\n literals?: UnionList # a | b | c\n extends?: TypeRef[]\n```\n\n```mdl\next feat\n uri: dxos.spec/ext/feat@1.0\n desc: A named feature grouping one or more requirements.\n fields:\n desc?: Prose\n req: RequirementList\n nesting: self # feat blocks may contain feat blocks\n```\n\n```mdl\next test\n uri: dxos.spec/ext/test@1.0\n desc: An acceptance scenario expressed as given / when / then steps.\n fields:\n given?: Step | Step[]\n when?: Step | Step[]\n then: Step | Step[]\n tags?: TagList\n```\n\n```mdl\next component\n uri: org.dxos.mdl.component@1.0\n desc: A UI component with props, internal state, slots, actions, and events.\n fields:\n desc?: Prose\n props?: FieldMap # external inputs (immutable inside component)\n state?: FieldMap # internal reactive state\n slots?: FieldMap # named ReactNode injection points\n actions?: ActionMap # methods the component exposes or handles\n emits?: EventMap # events the component raises to its parent\n layout?: CodeBlock # ASCII sketch of visual structure (non-normative)\n```\n\n```mdl\next op\n uri: org.dxos.mdl.op@1.0\n desc: |\n A named operation with typed inputs, outputs, and declared errors.\n Pure ops have no effects or requires. Effectful ops declare both.\n fields:\n desc?: Prose\n input?: FieldMap # named input parameters\n output?: TypeExpr # return type\n errors?: ErrorMap # name: Prose (when this error occurs)\n effects?: EffectList # echo:read | echo:write | http | fs | ...\n requires?: ServiceList # injected service dependencies\n note?: Prose # implementation guidance (non-normative)\n```\n\n```mdl\next service\n uri: org.dxos.mdl.service@1.0\n desc: An external or system-level dependency providing named operations.\n fields:\n desc?: Prose\n loading?: eager | lazy\n ops?: OpMap # name(params) \u2192 ReturnType\n errors?: ErrorMap\n note?: Prose\n```\n"],
|
|
5
|
-
"mappings": ";AAIA,SAASA,cAAc;AACvB,SAASC,WAAWC,2BAA2B;AAE/C,SAASC,qBAAqBC,aAAaC,wBAAwB;AACnE,SAASC,YAAY;AACrB,SAASC,oBAAoB;AAC7B,SAASC,aAAa;;;ACVtB;;;ADeO,IAAMC,cAAcC,OAAOC,OAAOC,IAAAA,EAAMC,KAC7CH,OAAOI,UAAU;EACfC,IAAI;EACJC,aAAaC,oBAAoBC;EACjCC,UAAUC;AACZ,CAAA,GACAC,UAAUC,6BAA6B;EAAEH,UAAUI;AAAoB,CAAA,GACvEF,UAAUG,0BAA0B;EAAEL,UAAUM;AAAiB,CAAA,GACjEJ,UAAUK,qBAAqB;EAC7BC,OAAO;IAAEC,UAAUhB,KAAKiB,QAAQC;IAAKC,MAAM;IAAcC,SAASC;IAAYC,UAAU;EAAoB;AAC9G,CAAA,GACAb,UAAUc,gBAAgB;EAAEC,QAAQ;IAACC,MAAMC;;AAAO,CAAA,GAClDjB,UAAUkB,sBAAsB;EAAEC;AAAa,CAAA,GAC/C9B,OAAO+B,IAAI;AAGb,IAAA,sBAAehC;",
|
|
6
|
-
"names": ["Plugin", "AppPlugin", "AppActivationEvents", "BlueprintDefinition", "GameVariant", "OperationHandler", "meta", "translations", "Chess", "ChessPlugin", "Plugin", "define", "meta", "pipe", "addModule", "id", "activatesOn", "AppActivationEvents", "SetupSchema", "activate", "GameVariant", "AppPlugin", "addBlueprintDefinitionModule", "BlueprintDefinition", "addOperationHandlerModule", "OperationHandler", "addPluginAssetModule", "asset", "pluginId", "profile", "key", "path", "content", "pluginSpec", "mimeType", "addSchemaModule", "schema", "Chess", "State", "addTranslationsModule", "translations", "make"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/types/Chess.ts", "../../../src/types/ChessOperation.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Chess as ChessJS } from 'chess.js';\nimport * as Schema from 'effect/Schema';\n\nimport { AppAnnotation } from '@dxos/app-toolkit';\nimport { DXN, Annotation, Obj, Type } from '@dxos/echo';\nimport { FormInputAnnotation, HiddenAnnotation } from '@dxos/echo/Annotation';\nimport { log } from '@dxos/log';\n\nexport const BLUEPRINT_KEY = 'org.dxos.blueprint.chess';\n\n/**\n * Chess variant state. Referenced by the base `Game` object via `Game.variant`.\n * Players, name, and other game-shared fields live on the base `Game`.\n */\nexport const State = Schema.Struct({\n pgn: Schema.String.annotations({\n description: 'Portable Game Notation.',\n }).pipe(FormInputAnnotation.set(false), Schema.optional),\n fen: Schema.String.annotations({\n description: 'Forsyth-Edwards Notation.',\n }).pipe(FormInputAnnotation.set(false), Schema.optional),\n}).pipe(\n Annotation.IconAnnotation.set({ icon: 'ph--shield-chevron--regular', hue: 'amber' }),\n AppAnnotation.BlueprintsAnnotation.set([BLUEPRINT_KEY]),\n // Implementation detail of the unified `Game` schema. The user-facing object is `Game`;\n // this state is only ever referenced via `Game.variant`. HiddenAnnotation keeps it out of the\n // navtree's typed branches so an orphaned state object doesn't reappear after the\n // wrapping Game is deleted.\n HiddenAnnotation.set(true),\n Type.makeObject(DXN.make('org.dxos.type.chess.state', '0.1.0')),\n);\n\nexport type State = Type.InstanceType<typeof State>;\n\nexport const make = ({ pgn, fen }: { pgn?: string; fen?: string } = {}): State => {\n const chess = new ChessJS();\n if (pgn) {\n try {\n chess.loadPgn(pgn);\n } catch {\n log.warn(pgn);\n }\n }\n\n return Obj.make(State, {\n pgn,\n fen,\n });\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Schema from 'effect/Schema';\n\nimport { Operation } from '@dxos/compute';\nimport { Database, DXN } from '@dxos/echo';\nimport { GameRef } from '@dxos/plugin-game/types';\n\nimport * as Chess from './Chess';\n\nexport const Move = Operation.make({\n meta: {\n key: DXN.make('org.dxos.function.chess.move'),\n name: 'Move',\n description: 'Makes a move in the given chess game.',\n icon: 'ph--play--regular',\n },\n input: Schema.Struct({\n game: GameRef(Chess.State).annotations({\n description: 'The ID of the game object (variant must be Chess).',\n }),\n move: Schema.String.annotations({\n description: 'The move to make in the chess game.',\n examples: ['e4', 'Bf3'],\n }),\n }),\n output: Schema.Struct({\n pgn: Schema.String.annotations({\n description: 'The PGN of the game after the move was played.',\n }),\n }),\n services: [Database.Service],\n});\n\nexport const Play = Operation.make({\n meta: {\n key: DXN.make('org.dxos.function.chess.play'),\n name: 'Play',\n description: 'Uses the chess engine to play the next move.',\n icon: 'ph--play--regular',\n },\n input: Schema.Struct({\n game: GameRef(Chess.State).annotations({\n description: 'The ID of the game object (variant must be Chess).',\n }),\n side: Schema.optional(Schema.Literal('white', 'black', 'any')).annotations({\n description: 'The side to play.',\n defaultValue: 'any',\n }),\n }),\n output: Schema.Struct({\n pgn: Schema.String.annotations({\n description: 'The PGN of the game after the move was played.',\n }),\n move: Schema.optional(Schema.String).annotations({\n description: 'The move that was played.',\n }),\n }),\n services: [Database.Service],\n});\n\nexport const Print = Operation.make({\n meta: {\n key: DXN.make('org.dxos.function.chess.print'),\n name: 'Print game',\n description: 'Prints the chess game to ASCII.',\n icon: 'ph--clipboard-text--regular',\n },\n input: Schema.Struct({\n pgn: Schema.optional(\n Schema.String.annotations({\n description: 'Portable Game Notation.',\n }),\n ),\n fen: Schema.optional(\n Schema.String.annotations({\n description: 'Forsyth-Edwards Notation.',\n }),\n ),\n }),\n output: Schema.Struct({\n ascii: Schema.String,\n }),\n});\n"],
|
|
5
|
-
"mappings": ";;;;;AAAA;;;;;;AAIA,SAASA,SAASC,eAAe;AACjC,YAAYC,YAAY;AAExB,SAASC,qBAAqB;AAC9B,SAASC,KAAKC,YAAYC,KAAKC,YAAY;AAC3C,SAASC,qBAAqBC,wBAAwB;AACtD,SAASC,WAAW;AAEpB,IAAA,eAAaC;;AAQTC,IAAAA,QAAa,cAAA;EACf,KAAQJ,cAAAA,YAAuB;IAC/BK,aAAYC;UACVF,oBAAa,IAAA,KAAA,GAAA,eAAA;EACf,KAAQJ,cAAAA,YAAuB;IAE/BH,aAAWU;EAAqBC,CAAAA,EAAAA,KAAM,oBAAA,IAAA,KAAA,GAAA,eAAA;;EAA+BC,WAAK,eAAA,IAAA;IAC1Ed,MAAAA;IAAwCQ,KAAAA;GAAc;EACtD,cAAA,qBAAA,IAAA;IACA;EACA,CAAA;;;;;mBASMO,IAAQ,IAAIjB;EAAAA,KAAAA,WAAAA,IAAAA,KAAAA,6BAAAA,OAAAA,CAAAA;AAAAA;AAClB,IAAS,OAAA,CAAA,EAAA,KAAA,IAAA,IAAA,CAAA,MAAA;QACP,QAAI,IAAA,QAAA;WACFiB;AACF,QAAE;AACAR,YAAIS,QAAKC,GAAAA;IACX,QAAA;AACF,UAAA,KAAA,KAAA,QAAA,EAAA,YAAA,YAAA,GAAA,cAAA,GAAA,IAAA,GAAA,OAAA,CAAA;IAEA;;SAEEP,IAAAA,KAAAA,OAAAA;IACF;IACA;;;;;ACpDF;;;;;;AAMA,YAAYQ,aAAY;AAExB,SAASC,iBAAiB;AAC1B,SAASC,UAAUC,OAAAA,YAAW;AAC9B,SAASC,eAAe;AAIjB,IAAMC,OAAOC,UAAUC,KAAK;EACjCC,MAAM;IACJC,KAAKC,KAAIH,KAAK,8BAAA;IACdI,MAAM;IACNC,aAAa;IACbC,MAAM;EACR;EACAC,OAAcC,eAAO;IACnBC,MAAMC,QAAcC,KAAK,EAAEC,YAAY;MACrCP,aAAa;IACf,CAAA;IACAQ,MAAaC,eAAOF,YAAY;MAC9BP,aAAa;MACbU,UAAU;QAAC;QAAM;;IACnB,CAAA;EACF,CAAA;EACAC,QAAeR,eAAO;IACpBS,KAAYH,eAAOF,YAAY;MAC7BP,aAAa;IACf,CAAA;EACF,CAAA;EACAa,UAAU;IAACC,SAASC;;AACtB,CAAA;AAEO,IAAMC,OAAOtB,UAAUC,KAAK;EACjCC,MAAM;IACJC,KAAKC,KAAIH,KAAK,8BAAA;IACdI,MAAM;IACNC,aAAa;IACbC,MAAM;EACR;EACAC,OAAcC,eAAO;IACnBC,MAAMC,QAAcC,KAAK,EAAEC,YAAY;MACrCP,aAAa;IACf,CAAA;IACAiB,MAAaC,iBAAgBC,gBAAQ,SAAS,SAAS,KAAA,CAAA,EAAQZ,YAAY;MACzEP,aAAa;MACboB,cAAc;IAChB,CAAA;EACF,CAAA;EACAT,QAAeR,eAAO;IACpBS,KAAYH,eAAOF,YAAY;MAC7BP,aAAa;IACf,CAAA;IACAQ,MAAaU,iBAAgBT,cAAM,EAAEF,YAAY;MAC/CP,aAAa;IACf,CAAA;EACF,CAAA;EACAa,UAAU;IAACC,SAASC;;AACtB,CAAA;AAEO,IAAMM,QAAQ3B,UAAUC,KAAK;EAClCC,MAAM;IACJC,KAAKC,KAAIH,KAAK,+BAAA;IACdI,MAAM;IACNC,aAAa;IACbC,MAAM;EACR;EACAC,OAAcC,eAAO;IACnBS,KAAYM,iBACHT,eAAOF,YAAY;MACxBP,aAAa;IACf,CAAA,CAAA;IAEFsB,KAAYJ,iBACHT,eAAOF,YAAY;MACxBP,aAAa;IACf,CAAA,CAAA;EAEJ,CAAA;EACAW,QAAeR,eAAO;IACpBoB,OAAcd;EAChB,CAAA;AACF,CAAA;",
|
|
6
|
-
"names": ["Chess", "ChessJS", "Schema", "AppAnnotation", "DXN", "Annotation", "Obj", "Type", "FormInputAnnotation", "HiddenAnnotation", "log", "BLUEPRINT_KEY", "description", "fen", "String", "IconAnnotation", "icon", "hue", "chess", "warn", "pgn", "Schema", "Operation", "Database", "DXN", "GameRef", "Move", "Operation", "make", "meta", "key", "DXN", "name", "description", "icon", "input", "Struct", "game", "GameRef", "State", "annotations", "move", "String", "examples", "output", "pgn", "services", "Database", "Service", "Play", "side", "optional", "Literal", "defaultValue", "Print", "fen", "ascii"]
|
|
7
|
-
}
|