@dxos/plugin-chess 0.8.4-main.1da679c → 0.8.4-main.21d9917
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/browser/ChessboardContainer-IS4PXWJD.mjs +81 -0
- package/dist/lib/browser/ChessboardContainer-IS4PXWJD.mjs.map +7 -0
- package/dist/lib/browser/blueprint-definition-5RUGJ64Z.mjs +18 -0
- package/dist/lib/browser/blueprint-definition-5RUGJ64Z.mjs.map +7 -0
- package/dist/lib/browser/blueprints/index.mjs +11 -0
- package/dist/lib/browser/{chunk-T275KG4U.mjs → chunk-7OZ7J7LF.mjs} +19 -39
- package/dist/lib/browser/chunk-7OZ7J7LF.mjs.map +7 -0
- package/dist/lib/browser/chunk-DH4WQRZH.mjs +229 -0
- package/dist/lib/browser/chunk-DH4WQRZH.mjs.map +7 -0
- package/dist/lib/browser/chunk-H3NUMCQ6.mjs +21 -0
- package/dist/lib/browser/chunk-H3NUMCQ6.mjs.map +7 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/browser/{chunk-KD4I5VTZ.mjs → chunk-MV2GQK7M.mjs} +2 -2
- package/dist/lib/browser/chunk-UUMPZ2FM.mjs +271 -0
- package/dist/lib/browser/chunk-UUMPZ2FM.mjs.map +7 -0
- package/dist/lib/browser/cli/index.mjs +28 -0
- package/dist/lib/browser/cli/index.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +53 -79
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/react-surface-GQE7XMWH.mjs +37 -0
- package/dist/lib/browser/react-surface-GQE7XMWH.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +3 -5
- package/dist/lib/node-esm/ChessboardContainer-S3T6OE7P.mjs +82 -0
- package/dist/lib/node-esm/ChessboardContainer-S3T6OE7P.mjs.map +7 -0
- package/dist/lib/node-esm/blueprint-definition-RYKASBIJ.mjs +19 -0
- package/dist/lib/node-esm/blueprint-definition-RYKASBIJ.mjs.map +7 -0
- package/dist/lib/node-esm/blueprints/index.mjs +12 -0
- package/dist/lib/node-esm/blueprints/index.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-Q5LJYIMO.mjs → chunk-DOBR6ILE.mjs} +2 -2
- package/dist/lib/node-esm/{chunk-6OWCPDUA.mjs → chunk-F5OMIM4F.mjs} +5 -11
- package/dist/lib/node-esm/chunk-F5OMIM4F.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-LKJ5GDAB.mjs +272 -0
- package/dist/lib/node-esm/chunk-LKJ5GDAB.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-5DYLCQBR.mjs → chunk-NAYRVJR4.mjs} +19 -39
- package/dist/lib/node-esm/chunk-NAYRVJR4.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-NFDJU7XQ.mjs +230 -0
- package/dist/lib/node-esm/chunk-NFDJU7XQ.mjs.map +7 -0
- package/dist/lib/node-esm/cli/index.mjs +29 -0
- package/dist/lib/node-esm/cli/index.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +53 -79
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{react-surface-SBM22GEU.mjs → react-surface-7UZLIVN6.mjs} +15 -16
- package/dist/lib/node-esm/react-surface-7UZLIVN6.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +3 -5
- package/dist/types/src/ChessPlugin.d.ts +2 -1
- package/dist/types/src/ChessPlugin.d.ts.map +1 -1
- package/dist/types/src/blueprints/chess-blueprint.d.ts +21 -0
- package/dist/types/src/blueprints/chess-blueprint.d.ts.map +1 -0
- package/dist/types/src/blueprints/functions/create.d.ts +15 -0
- package/dist/types/src/blueprints/functions/create.d.ts.map +1 -0
- package/dist/types/src/{functions → blueprints/functions}/index.d.ts +1 -0
- package/dist/types/src/blueprints/functions/index.d.ts.map +1 -0
- package/dist/types/src/{functions → blueprints/functions}/move.d.ts +1 -1
- package/dist/types/src/blueprints/functions/move.d.ts.map +1 -0
- package/dist/types/src/{functions → blueprints/functions}/play.d.ts +1 -1
- package/dist/types/src/blueprints/functions/play.d.ts.map +1 -0
- package/dist/types/src/blueprints/functions/print.d.ts +8 -0
- package/dist/types/src/blueprints/functions/print.d.ts.map +1 -0
- package/dist/types/src/blueprints/index.d.ts +3 -0
- package/dist/types/src/blueprints/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/artifact-definition/artifact-definition.d.ts +12 -0
- package/dist/types/src/capabilities/artifact-definition/artifact-definition.d.ts.map +1 -0
- package/dist/types/src/capabilities/artifact-definition/index.d.ts +3 -0
- package/dist/types/src/capabilities/artifact-definition/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts +9 -0
- package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts.map +1 -0
- package/dist/types/src/capabilities/blueprint-definition/index.d.ts +3 -0
- package/dist/types/src/capabilities/blueprint-definition/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +1 -3
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface/index.d.ts +3 -0
- package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts +5 -0
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -0
- package/dist/types/src/cli/index.d.ts +2 -0
- package/dist/types/src/cli/index.d.ts.map +1 -0
- package/dist/types/src/cli/plugin.d.ts +3 -0
- package/dist/types/src/cli/plugin.d.ts.map +1 -0
- package/dist/types/src/components/Card.stories.d.ts +10 -9
- package/dist/types/src/components/Card.stories.d.ts.map +1 -1
- package/dist/types/src/components/Chessboard.d.ts +2 -1
- package/dist/types/src/components/Chessboard.d.ts.map +1 -1
- package/dist/types/src/components/Chessboard.stories.d.ts +15 -13
- package/dist/types/src/components/Chessboard.stories.d.ts.map +1 -1
- package/dist/types/src/components/ChessboardArticle.d.ts +3 -4
- package/dist/types/src/components/ChessboardArticle.d.ts.map +1 -1
- package/dist/types/src/components/ChessboardContainer.d.ts +3 -5
- package/dist/types/src/components/ChessboardContainer.d.ts.map +1 -1
- package/dist/types/src/components/Info.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -1
- package/dist/types/src/components/index.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 +2 -3
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +9 -8
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Chess.d.ts +17 -17
- package/dist/types/src/types/Chess.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +0 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +64 -50
- package/src/ChessPlugin.tsx +26 -53
- package/src/blueprints/chess-blueprint.ts +28 -0
- package/src/blueprints/functions/create.ts +38 -0
- package/src/{functions → blueprints/functions}/index.ts +1 -0
- package/src/{functions → blueprints/functions}/move.ts +13 -7
- package/src/{functions → blueprints/functions}/play.ts +13 -7
- package/src/blueprints/functions/print.ts +42 -0
- package/src/blueprints/index.ts +6 -0
- package/src/capabilities/artifact-definition/artifact-definition.ts +135 -0
- package/src/capabilities/artifact-definition/index.ts +7 -0
- package/src/capabilities/blueprint-definition/blueprint-definition.ts +23 -0
- package/src/capabilities/blueprint-definition/index.ts +7 -0
- package/src/capabilities/index.ts +1 -6
- package/src/capabilities/react-surface/index.ts +7 -0
- package/src/capabilities/react-surface/react-surface.tsx +27 -0
- package/src/cli/index.ts +5 -0
- package/src/cli/plugin.ts +26 -0
- package/src/components/Card.stories.tsx +19 -40
- package/src/components/Chessboard.stories.tsx +18 -15
- package/src/components/Chessboard.tsx +21 -10
- package/src/components/ChessboardArticle.tsx +13 -11
- package/src/components/ChessboardContainer.tsx +9 -13
- package/src/components/Info.tsx +17 -13
- package/src/index.ts +1 -1
- package/src/meta.ts +6 -6
- package/src/translations.ts +9 -8
- package/src/types/Chess.ts +23 -31
- package/src/types/index.ts +0 -1
- package/dist/lib/browser/ChessboardContainer-LIZDOGHI.mjs +0 -97
- package/dist/lib/browser/ChessboardContainer-LIZDOGHI.mjs.map +0 -7
- package/dist/lib/browser/blueprint-definition-I6UFJHT6.mjs +0 -11
- package/dist/lib/browser/chunk-EKNL3H3U.mjs +0 -306
- package/dist/lib/browser/chunk-EKNL3H3U.mjs.map +0 -7
- package/dist/lib/browser/chunk-M2MBU2O6.mjs +0 -163
- package/dist/lib/browser/chunk-M2MBU2O6.mjs.map +0 -7
- package/dist/lib/browser/chunk-PE3IWOFR.mjs +0 -28
- package/dist/lib/browser/chunk-PE3IWOFR.mjs.map +0 -7
- package/dist/lib/browser/chunk-T275KG4U.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-RV2DQSJP.mjs +0 -25
- package/dist/lib/browser/intent-resolver-RV2DQSJP.mjs.map +0 -7
- package/dist/lib/browser/react-surface-I6CZUR5C.mjs +0 -38
- package/dist/lib/browser/react-surface-I6CZUR5C.mjs.map +0 -7
- package/dist/lib/node-esm/ChessboardContainer-XWVQ5K7N.mjs +0 -98
- package/dist/lib/node-esm/ChessboardContainer-XWVQ5K7N.mjs.map +0 -7
- package/dist/lib/node-esm/blueprint-definition-F7WQTNQ7.mjs +0 -12
- package/dist/lib/node-esm/chunk-5DYLCQBR.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-6OWCPDUA.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-EGBWRJWH.mjs +0 -307
- package/dist/lib/node-esm/chunk-EGBWRJWH.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-TUWE7Y5Z.mjs +0 -164
- package/dist/lib/node-esm/chunk-TUWE7Y5Z.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-TJF7I4UB.mjs +0 -26
- package/dist/lib/node-esm/intent-resolver-TJF7I4UB.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-SBM22GEU.mjs.map +0 -7
- package/dist/types/src/capabilities/artifact-definition.d.ts +0 -11
- package/dist/types/src/capabilities/artifact-definition.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/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-surface.d.ts +0 -4
- package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
- package/dist/types/src/functions/create.d.ts +0 -14
- package/dist/types/src/functions/create.d.ts.map +0 -1
- package/dist/types/src/functions/index.d.ts.map +0 -1
- package/dist/types/src/functions/move.d.ts.map +0 -1
- package/dist/types/src/functions/play.d.ts.map +0 -1
- package/dist/types/src/types/ChessAction.d.ts +0 -24
- package/dist/types/src/types/ChessAction.d.ts.map +0 -1
- package/src/capabilities/artifact-definition.ts +0 -128
- package/src/capabilities/blueprint-definition.ts +0 -36
- package/src/capabilities/intent-resolver.ts +0 -22
- package/src/capabilities/react-surface.tsx +0 -23
- package/src/functions/create.ts +0 -30
- package/src/types/ChessAction.ts +0 -19
- /package/dist/lib/browser/{blueprint-definition-I6UFJHT6.mjs.map → blueprints/index.mjs.map} +0 -0
- /package/dist/lib/{node-esm/blueprint-definition-F7WQTNQ7.mjs.map → browser/chunk-J5LGTIGS.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-KD4I5VTZ.mjs.map → chunk-MV2GQK7M.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-Q5LJYIMO.mjs.map → chunk-DOBR6ILE.mjs.map} +0 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
|
|
8
|
+
import { Capability, Common } from '@dxos/app-framework';
|
|
9
|
+
import { Obj } from '@dxos/echo';
|
|
10
|
+
|
|
11
|
+
import { ChessboardContainer } from '../../components';
|
|
12
|
+
import { meta } from '../../meta';
|
|
13
|
+
import { Chess } from '../../types';
|
|
14
|
+
|
|
15
|
+
export default Capability.makeModule(() =>
|
|
16
|
+
Effect.succeed(
|
|
17
|
+
Capability.contributes(Common.Capability.ReactSurface, [
|
|
18
|
+
Common.createSurface({
|
|
19
|
+
id: meta.id,
|
|
20
|
+
role: ['article', 'section', 'card--content'],
|
|
21
|
+
// TODO(burdon): Could this be standardized so that we don't require a subject property.
|
|
22
|
+
filter: (data): data is { subject: Chess.Game } => Obj.instanceOf(Chess.Game, data.subject),
|
|
23
|
+
component: ({ data, role }) => <ChessboardContainer role={role} subject={data.subject} />,
|
|
24
|
+
}),
|
|
25
|
+
]),
|
|
26
|
+
),
|
|
27
|
+
);
|
package/src/cli/index.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import { Common, Plugin } from '@dxos/app-framework';
|
|
8
|
+
import { type CreateObject } from '@dxos/plugin-space/types';
|
|
9
|
+
|
|
10
|
+
import { meta } from '../meta';
|
|
11
|
+
import { Chess } from '../types';
|
|
12
|
+
|
|
13
|
+
// TODO(wittjosiah): Factor out shared modules.
|
|
14
|
+
export const ChessPlugin = Plugin.define(meta).pipe(
|
|
15
|
+
Common.Plugin.addSchemaModule({ schema: [Chess.Game] }),
|
|
16
|
+
Common.Plugin.addMetadataModule({
|
|
17
|
+
metadata: {
|
|
18
|
+
id: Chess.Game.typename,
|
|
19
|
+
metadata: {
|
|
20
|
+
createObject: ((props) => Effect.sync(() => Chess.make(props))) satisfies CreateObject,
|
|
21
|
+
addToCollectionOnCreate: true,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
}),
|
|
25
|
+
Plugin.make,
|
|
26
|
+
);
|
|
@@ -2,67 +2,46 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@dxos-theme';
|
|
6
|
-
|
|
7
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
|
-
import React from 'react';
|
|
6
|
+
import React, { useMemo } from 'react';
|
|
9
7
|
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
8
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
9
|
+
import { CardContainer } from '@dxos/react-ui-mosaic/testing';
|
|
12
10
|
|
|
13
11
|
import { meta as pluginMeta } from '../meta';
|
|
14
12
|
import { Chess } from '../types';
|
|
15
13
|
|
|
16
14
|
import { Chessboard } from './Chessboard';
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
game: Chess.Game;
|
|
21
|
-
};
|
|
16
|
+
const SAMPLE_PGN =
|
|
17
|
+
'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 Qg4 16. e7 Kf7 17. bxc3 Kg6 *';
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
// TODO(wittjosiah): ECHO objects don't work when passed via Storybook args.
|
|
20
|
+
const CardStory = () => {
|
|
21
|
+
const game = useMemo(() => Chess.make({ pgn: SAMPLE_PGN }), []);
|
|
22
|
+
return (
|
|
23
|
+
<CardContainer icon={pluginMeta.icon}>
|
|
27
24
|
<Chessboard.Root game={game}>
|
|
28
|
-
<Chessboard.Content
|
|
25
|
+
<Chessboard.Content>
|
|
29
26
|
<Chessboard.Board />
|
|
30
27
|
</Chessboard.Content>
|
|
31
28
|
</Chessboard.Root>
|
|
32
29
|
</CardContainer>
|
|
33
|
-
)
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const meta = {
|
|
34
|
+
title: 'plugins/plugin-chess/Card',
|
|
35
|
+
render: () => <CardStory />,
|
|
34
36
|
decorators: [withTheme],
|
|
35
37
|
parameters: {
|
|
36
38
|
layout: 'centered',
|
|
37
39
|
},
|
|
38
40
|
tags: ['cards'],
|
|
39
|
-
};
|
|
41
|
+
} satisfies Meta;
|
|
40
42
|
|
|
41
43
|
export default meta;
|
|
42
44
|
|
|
43
|
-
const game = Chess.makeGame({
|
|
44
|
-
pgn: '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 Qg4 16. e7 Kf7 17. bxc3 Kg6 *',
|
|
45
|
-
});
|
|
46
|
-
|
|
47
45
|
type Story = StoryObj<typeof meta>;
|
|
48
46
|
|
|
49
|
-
export const Popover: Story = {
|
|
50
|
-
args: {
|
|
51
|
-
role: 'card--popover',
|
|
52
|
-
game: game,
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export const Intrinsic: Story = {
|
|
57
|
-
args: {
|
|
58
|
-
role: 'card--intrinsic',
|
|
59
|
-
game: game,
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export const Extrinsic: Story = {
|
|
64
|
-
args: {
|
|
65
|
-
role: 'card--extrinsic',
|
|
66
|
-
game: game,
|
|
67
|
-
},
|
|
68
|
-
};
|
|
47
|
+
export const Popover: Story = {};
|
|
@@ -2,49 +2,52 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@dxos-theme';
|
|
6
|
-
|
|
7
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
+
import React, { useMemo } from 'react';
|
|
8
7
|
|
|
9
8
|
import { withClientProvider } from '@dxos/react-client/testing';
|
|
10
|
-
import {
|
|
9
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
11
10
|
|
|
12
11
|
import { translations } from '../translations';
|
|
13
12
|
import { Chess } from '../types';
|
|
14
13
|
|
|
15
14
|
import { ChessboardArticle } from './ChessboardArticle';
|
|
16
15
|
|
|
16
|
+
type StoryProps = {
|
|
17
|
+
pgn?: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const DefaultStory = ({ pgn }: StoryProps) => {
|
|
21
|
+
const game = useMemo(() => Chess.make(pgn ? { pgn } : undefined), [pgn]);
|
|
22
|
+
return <ChessboardArticle subject={game} />;
|
|
23
|
+
};
|
|
24
|
+
|
|
17
25
|
const meta = {
|
|
18
26
|
title: 'plugins/plugin-chess/Chessboard',
|
|
19
|
-
component:
|
|
20
|
-
decorators: [
|
|
27
|
+
component: DefaultStory,
|
|
28
|
+
decorators: [withTheme, withClientProvider({ createIdentity: true })],
|
|
21
29
|
parameters: {
|
|
30
|
+
layout: 'fullscreen',
|
|
22
31
|
translations,
|
|
23
32
|
},
|
|
24
|
-
} satisfies Meta<typeof
|
|
33
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
25
34
|
|
|
26
35
|
export default meta;
|
|
27
36
|
|
|
28
37
|
type Story = StoryObj<typeof meta>;
|
|
29
38
|
|
|
30
39
|
export const Default: Story = {
|
|
31
|
-
args: {
|
|
32
|
-
game: Chess.makeGame(),
|
|
33
|
-
},
|
|
40
|
+
args: {},
|
|
34
41
|
};
|
|
35
42
|
|
|
36
43
|
export const EndGame: Story = {
|
|
37
44
|
args: {
|
|
38
|
-
|
|
39
|
-
pgn: '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 *',
|
|
40
|
-
}),
|
|
45
|
+
pgn: '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 *',
|
|
41
46
|
},
|
|
42
47
|
};
|
|
43
48
|
|
|
44
49
|
export const Promption: Story = {
|
|
45
50
|
args: {
|
|
46
|
-
|
|
47
|
-
pgn: '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 Qg4 16. e7 Kf7 17. bxc3 Kg6 *',
|
|
48
|
-
}),
|
|
51
|
+
pgn: '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 Qg4 16. e7 Kf7 17. bxc3 Kg6 *',
|
|
49
52
|
},
|
|
50
53
|
};
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { type Registry, RegistryContext } from '@effect-atom/atom-react';
|
|
5
6
|
import React, {
|
|
6
7
|
type PropsWithChildren,
|
|
7
8
|
forwardRef,
|
|
8
9
|
useCallback,
|
|
10
|
+
useContext,
|
|
9
11
|
useEffect,
|
|
10
12
|
useImperativeHandle,
|
|
11
13
|
useMemo,
|
|
@@ -13,6 +15,7 @@ import React, {
|
|
|
13
15
|
} from 'react';
|
|
14
16
|
|
|
15
17
|
import { addEventListener } from '@dxos/async';
|
|
18
|
+
import { Obj } from '@dxos/echo';
|
|
16
19
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
17
20
|
import {
|
|
18
21
|
ChessModel,
|
|
@@ -24,7 +27,7 @@ import {
|
|
|
24
27
|
useGameboardContext,
|
|
25
28
|
} from '@dxos/react-ui-gameboard';
|
|
26
29
|
import { useSoundEffect } from '@dxos/react-ui-sfx';
|
|
27
|
-
import { mx } from '@dxos/
|
|
30
|
+
import { mx } from '@dxos/ui-theme';
|
|
28
31
|
|
|
29
32
|
import { type Chess } from '../types';
|
|
30
33
|
|
|
@@ -35,8 +38,11 @@ export interface ChessboardController {
|
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
export class ExtendedChessModel extends ChessModel {
|
|
38
|
-
constructor(
|
|
39
|
-
|
|
41
|
+
constructor(
|
|
42
|
+
registry: Registry.Registry,
|
|
43
|
+
readonly object: Chess.Game,
|
|
44
|
+
) {
|
|
45
|
+
super(registry);
|
|
40
46
|
}
|
|
41
47
|
}
|
|
42
48
|
|
|
@@ -49,7 +55,8 @@ type RootProps = PropsWithChildren<{
|
|
|
49
55
|
}>;
|
|
50
56
|
|
|
51
57
|
const Root = forwardRef<ChessboardController, RootProps>(({ game, children }, forwardedRef) => {
|
|
52
|
-
const
|
|
58
|
+
const registry = useContext(RegistryContext);
|
|
59
|
+
const model = useMemo(() => new ExtendedChessModel(registry, game), [registry]);
|
|
53
60
|
const click = useSoundEffect('Click');
|
|
54
61
|
|
|
55
62
|
// Controller.
|
|
@@ -79,7 +86,9 @@ const Root = forwardRef<ChessboardController, RootProps>(({ game, children }, fo
|
|
|
79
86
|
}
|
|
80
87
|
|
|
81
88
|
void click.play();
|
|
82
|
-
game
|
|
89
|
+
Obj.change(game, (g) => {
|
|
90
|
+
g.pgn = model.pgn;
|
|
91
|
+
});
|
|
83
92
|
return true;
|
|
84
93
|
},
|
|
85
94
|
[model],
|
|
@@ -119,6 +128,7 @@ const Content = ({ classNames, children, role }: ContentProps) => {
|
|
|
119
128
|
type BoardProps = NaturalChessboardProps;
|
|
120
129
|
|
|
121
130
|
const Board = (props: BoardProps) => {
|
|
131
|
+
const registry = useContext(RegistryContext);
|
|
122
132
|
const { model } = useGameboardContext<ChessModel>(Board.displayName);
|
|
123
133
|
|
|
124
134
|
// Keyboard navigation.
|
|
@@ -132,6 +142,7 @@ const Board = (props: BoardProps) => {
|
|
|
132
142
|
ref.current.setAttribute('data-arrow-keys', 'all');
|
|
133
143
|
|
|
134
144
|
return addEventListener(ref.current, 'keydown', (ev) => {
|
|
145
|
+
const moveIndex = registry.get(model.moveIndex);
|
|
135
146
|
switch (ev.key) {
|
|
136
147
|
case 'ArrowUp':
|
|
137
148
|
model.setMoveIndex(0);
|
|
@@ -140,18 +151,18 @@ const Board = (props: BoardProps) => {
|
|
|
140
151
|
model.setMoveIndex(model.game.history().length);
|
|
141
152
|
break;
|
|
142
153
|
case 'ArrowLeft':
|
|
143
|
-
if (
|
|
144
|
-
model.setMoveIndex(
|
|
154
|
+
if (moveIndex > 0) {
|
|
155
|
+
model.setMoveIndex(moveIndex - 1);
|
|
145
156
|
}
|
|
146
157
|
break;
|
|
147
158
|
case 'ArrowRight':
|
|
148
|
-
if (
|
|
149
|
-
model.setMoveIndex(
|
|
159
|
+
if (moveIndex < model.game.history().length) {
|
|
160
|
+
model.setMoveIndex(moveIndex + 1);
|
|
150
161
|
}
|
|
151
162
|
break;
|
|
152
163
|
}
|
|
153
164
|
});
|
|
154
|
-
}, [model]);
|
|
165
|
+
}, [registry, model]);
|
|
155
166
|
|
|
156
167
|
return <NaturalChessboard ref={ref} {...props} />;
|
|
157
168
|
};
|
|
@@ -4,17 +4,20 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { useCallback, useRef, useState } from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { type SurfaceComponentProps } from '@dxos/app-framework/react';
|
|
8
|
+
import { Toolbar, useTranslation } from '@dxos/react-ui';
|
|
8
9
|
import { type Player } from '@dxos/react-ui-gameboard';
|
|
9
|
-
import {
|
|
10
|
-
import { mx } from '@dxos/
|
|
10
|
+
import { Layout } from '@dxos/react-ui-mosaic';
|
|
11
|
+
import { mx } from '@dxos/ui-theme';
|
|
11
12
|
|
|
12
13
|
import { meta } from '../meta';
|
|
13
14
|
import { type Chess } from '../types';
|
|
14
15
|
|
|
15
16
|
import { Chessboard, type ChessboardController, type ChessboardInfoProps } from './Chessboard';
|
|
16
17
|
|
|
17
|
-
export
|
|
18
|
+
export type ChessboardArticleProps = SurfaceComponentProps<Chess.Game>;
|
|
19
|
+
|
|
20
|
+
export const ChessboardArticle = ({ role, subject: game }: ChessboardArticleProps) => {
|
|
18
21
|
const { t } = useTranslation(meta.id);
|
|
19
22
|
const [orientation, setOrientation] = useState<Player>('white');
|
|
20
23
|
const [open, setOpen] = useState(true);
|
|
@@ -26,22 +29,21 @@ export const ChessboardArticle = ({ game, role }: { game: Chess.Game; role?: str
|
|
|
26
29
|
}, []);
|
|
27
30
|
|
|
28
31
|
return (
|
|
29
|
-
<
|
|
32
|
+
<Layout.Main toolbar classNames='@container'>
|
|
30
33
|
<Chessboard.Root game={game} ref={controller}>
|
|
31
34
|
<Toolbar.Root>
|
|
32
|
-
<IconButton
|
|
33
|
-
variant='ghost'
|
|
35
|
+
<Toolbar.IconButton
|
|
34
36
|
icon='ph--info--regular'
|
|
35
37
|
iconOnly
|
|
36
38
|
label={t('toggle info button')}
|
|
37
|
-
|
|
38
|
-
classNames={mx('invisible
|
|
39
|
+
disabled={open}
|
|
40
|
+
classNames={mx('invisible @3xl:visible')}
|
|
39
41
|
onClick={() => setOpen((open) => !open)}
|
|
40
42
|
/>
|
|
41
43
|
</Toolbar.Root>
|
|
42
44
|
<div
|
|
43
45
|
className={mx(
|
|
44
|
-
'grid
|
|
46
|
+
'grid bs-full is-full gap-2',
|
|
45
47
|
open && '@3xl:grid-cols-[1fr_320px]',
|
|
46
48
|
role === 'section' && 'aspect-square',
|
|
47
49
|
role === 'section' && open && '@3xl:aspect-auto',
|
|
@@ -64,6 +66,6 @@ export const ChessboardArticle = ({ game, role }: { game: Chess.Game; role?: str
|
|
|
64
66
|
)}
|
|
65
67
|
</div>
|
|
66
68
|
</Chessboard.Root>
|
|
67
|
-
</
|
|
69
|
+
</Layout.Main>
|
|
68
70
|
);
|
|
69
71
|
};
|
|
@@ -4,31 +4,27 @@
|
|
|
4
4
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { type SurfaceComponentProps } from '@dxos/app-framework/react';
|
|
8
|
+
import { Obj } from '@dxos/echo';
|
|
8
9
|
|
|
9
10
|
import { type Chess } from '../types';
|
|
10
11
|
|
|
11
12
|
import { Chessboard } from './Chessboard';
|
|
12
13
|
import { ChessboardArticle } from './ChessboardArticle';
|
|
13
14
|
|
|
14
|
-
export type ChessboardContainerProps =
|
|
15
|
-
game: Chess.Game;
|
|
16
|
-
role?: string;
|
|
17
|
-
};
|
|
15
|
+
export type ChessboardContainerProps = SurfaceComponentProps<Chess.Game>;
|
|
18
16
|
|
|
19
|
-
export const ChessboardContainer = ({
|
|
20
|
-
const
|
|
21
|
-
if (!
|
|
17
|
+
export const ChessboardContainer = ({ role, subject: game }: ChessboardContainerProps) => {
|
|
18
|
+
const db = Obj.getDatabase(game);
|
|
19
|
+
if (!db) {
|
|
22
20
|
return null;
|
|
23
21
|
}
|
|
24
22
|
|
|
25
23
|
switch (role) {
|
|
26
|
-
case 'card--
|
|
27
|
-
case 'card--intrinsic':
|
|
28
|
-
case 'card--extrinsic': {
|
|
24
|
+
case 'card--content': {
|
|
29
25
|
return (
|
|
30
26
|
<Chessboard.Root game={game}>
|
|
31
|
-
<Chessboard.Content
|
|
27
|
+
<Chessboard.Content>
|
|
32
28
|
<Chessboard.Board />
|
|
33
29
|
</Chessboard.Content>
|
|
34
30
|
</Chessboard.Root>
|
|
@@ -36,7 +32,7 @@ export const ChessboardContainer = ({ game, role }: ChessboardContainerProps) =>
|
|
|
36
32
|
}
|
|
37
33
|
|
|
38
34
|
default: {
|
|
39
|
-
return <ChessboardArticle
|
|
35
|
+
return <ChessboardArticle role={role} subject={game} />;
|
|
40
36
|
}
|
|
41
37
|
}
|
|
42
38
|
};
|
package/src/components/Info.tsx
CHANGED
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { useAtomValue } from '@effect-atom/atom-react';
|
|
5
6
|
import React, { type JSX, type PropsWithChildren, useEffect, useMemo, useRef } from 'react';
|
|
6
7
|
|
|
7
8
|
import { generateName } from '@dxos/display-name';
|
|
8
|
-
import {
|
|
9
|
+
import { Obj } from '@dxos/echo';
|
|
10
|
+
import { type SpaceMember, useMembers } from '@dxos/react-client/echo';
|
|
9
11
|
import { Icon, IconButton, Select, type ThemedClassName, useTranslation } from '@dxos/react-ui';
|
|
10
12
|
import { type Player, useGameboardContext } from '@dxos/react-ui-gameboard';
|
|
11
|
-
import { mx } from '@dxos/
|
|
13
|
+
import { mx } from '@dxos/ui-theme';
|
|
12
14
|
|
|
13
15
|
import { meta } from '../meta';
|
|
14
16
|
|
|
@@ -25,7 +27,8 @@ export type InfoProps = ThemedClassName<
|
|
|
25
27
|
export const Info = ({ classNames, orientation = 'white', onOrientationChange, onClose, ...props }: InfoProps) => {
|
|
26
28
|
const { t } = useTranslation(meta.id);
|
|
27
29
|
const { model } = useGameboardContext<ExtendedChessModel>(Info.displayName);
|
|
28
|
-
const
|
|
30
|
+
const db = Obj.getDatabase(model.object);
|
|
31
|
+
const members = useMembers(db?.spaceId);
|
|
29
32
|
|
|
30
33
|
return (
|
|
31
34
|
<div
|
|
@@ -97,14 +100,15 @@ type HistoryProps = ThemedClassName<{
|
|
|
97
100
|
|
|
98
101
|
const History = ({ classNames, model, min, max, onSelect }: HistoryProps) => {
|
|
99
102
|
const { t } = useTranslation(meta.id);
|
|
103
|
+
const moveIndex = useAtomValue(model.moveIndex);
|
|
100
104
|
const label = model.game.isGameOver()
|
|
101
105
|
? model.game.isCheckmate()
|
|
102
|
-
? t('game.checkmate')
|
|
106
|
+
? t('game.checkmate label')
|
|
103
107
|
: model.game.isStalemate()
|
|
104
|
-
? t('game.stalemate')
|
|
105
|
-
: t('game.draw')
|
|
108
|
+
? t('game.stalemate label')
|
|
109
|
+
: t('game.draw label')
|
|
106
110
|
: model.game.isCheck()
|
|
107
|
-
? t('game.check')
|
|
111
|
+
? t('game.check label')
|
|
108
112
|
: undefined;
|
|
109
113
|
|
|
110
114
|
const history = model.game.history();
|
|
@@ -130,16 +134,16 @@ const History = ({ classNames, model, min, max, onSelect }: HistoryProps) => {
|
|
|
130
134
|
}, [history.length]);
|
|
131
135
|
|
|
132
136
|
useEffect(() => {
|
|
133
|
-
const div = scrollerRef.current?.querySelector(`[data-index="${
|
|
137
|
+
const div = scrollerRef.current?.querySelector(`[data-index="${moveIndex - 1}"]`);
|
|
134
138
|
scrollerRef.current?.classList.add('scrollbar-none');
|
|
135
139
|
div?.scrollIntoView({ behavior: 'smooth' });
|
|
136
140
|
scrollerRef.current?.classList.remove('scrollbar-none');
|
|
137
|
-
}, [
|
|
141
|
+
}, [moveIndex]);
|
|
138
142
|
|
|
139
143
|
return (
|
|
140
144
|
<div
|
|
141
145
|
ref={scrollerRef}
|
|
142
|
-
className={mx('overflow-y-
|
|
146
|
+
className={mx('overflow-y-auto', classNames)}
|
|
143
147
|
style={{
|
|
144
148
|
minHeight: min === undefined ? 'auto' : `${min * 24}px`,
|
|
145
149
|
maxHeight: max === undefined ? 'auto' : `${max * 24}px`,
|
|
@@ -151,7 +155,7 @@ const History = ({ classNames, model, min, max, onSelect }: HistoryProps) => {
|
|
|
151
155
|
{a && (
|
|
152
156
|
<div
|
|
153
157
|
data-index={a.index}
|
|
154
|
-
className={mx('pis-2 cursor-pointer', a.index ===
|
|
158
|
+
className={mx('pis-2 cursor-pointer', a.index === moveIndex - 1 && 'bg-primary-500')}
|
|
155
159
|
onClick={() => onSelect?.(a.index + 1)}
|
|
156
160
|
>
|
|
157
161
|
{a.move}
|
|
@@ -160,7 +164,7 @@ const History = ({ classNames, model, min, max, onSelect }: HistoryProps) => {
|
|
|
160
164
|
{b && (
|
|
161
165
|
<div
|
|
162
166
|
data-index={b.index}
|
|
163
|
-
className={mx('pis-2 cursor-pointer', b.index ===
|
|
167
|
+
className={mx('pis-2 cursor-pointer', b.index === moveIndex - 1 && 'bg-primary-500')}
|
|
164
168
|
onClick={() => onSelect?.(b.index + 1)}
|
|
165
169
|
>
|
|
166
170
|
{b.move}
|
|
@@ -186,7 +190,7 @@ type PlayerIndicatorProps = PropsWithChildren<{
|
|
|
186
190
|
const PlayerIndicator = ({ children, model, player, icon }: PlayerIndicatorProps) => {
|
|
187
191
|
const turn = player === (model.game.turn() === 'w' ? 'white' : 'black');
|
|
188
192
|
return (
|
|
189
|
-
<div className='grid grid-cols-[2rem_1fr_2rem] gap-2 bs-[--rail-size]
|
|
193
|
+
<div className='grid grid-cols-[2rem_1fr_2rem] gap-2 bs-[--rail-size] pli-1 flex items-center overflow-hidden'>
|
|
190
194
|
<div className='place-items-center'>
|
|
191
195
|
<Icon
|
|
192
196
|
icon={turn ? 'ph--circle--fill' : 'ph--circle--thin'}
|
package/src/index.ts
CHANGED
package/src/meta.ts
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
5
|
+
import { type Plugin } from '@dxos/app-framework';
|
|
6
6
|
import { trim } from '@dxos/util';
|
|
7
7
|
|
|
8
|
-
export const
|
|
9
|
-
|
|
10
|
-
export const meta: PluginMeta = {
|
|
11
|
-
id: CHESS_PLUGIN,
|
|
8
|
+
export const meta: Plugin.Meta = {
|
|
9
|
+
id: 'dxos.org/plugin/chess',
|
|
12
10
|
name: 'Chess',
|
|
13
11
|
description: trim`
|
|
14
|
-
|
|
12
|
+
Full-featured chess game supporting multiplayer matches with friends or practice sessions against AI opponents.
|
|
13
|
+
Track game history and analyze moves in real-time.
|
|
15
14
|
`,
|
|
16
15
|
icon: 'ph--shield-chevron--regular',
|
|
16
|
+
iconHue: 'amber',
|
|
17
17
|
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-chess',
|
|
18
18
|
screenshots: ['https://dxos.network/plugin-details-chess-dark.png'],
|
|
19
19
|
};
|
package/src/translations.ts
CHANGED
|
@@ -18,18 +18,19 @@ export const translations = [
|
|
|
18
18
|
'object name placeholder': 'New game',
|
|
19
19
|
'rename object label': 'Rename game',
|
|
20
20
|
'delete object label': 'Delete game',
|
|
21
|
-
'
|
|
22
|
-
'close info button': 'Close info',
|
|
23
|
-
'flip board button': 'Flip board',
|
|
24
|
-
'select player button': 'Select player',
|
|
21
|
+
'object deleted label': 'Game deleted',
|
|
25
22
|
},
|
|
26
23
|
[meta.id]: {
|
|
27
24
|
'plugin name': 'Chess',
|
|
28
25
|
'delete game label': 'Delete',
|
|
29
|
-
'game.checkmate': 'Checkmate',
|
|
30
|
-
'game.stalemate': 'Stalemate',
|
|
31
|
-
'game.draw': 'Draw',
|
|
32
|
-
'game.check': 'Check',
|
|
26
|
+
'game.checkmate label': 'Checkmate',
|
|
27
|
+
'game.stalemate label': 'Stalemate',
|
|
28
|
+
'game.draw label': 'Draw',
|
|
29
|
+
'game.check label': 'Check',
|
|
30
|
+
'select player button': 'Select player',
|
|
31
|
+
'toggle info button': 'Toggle info',
|
|
32
|
+
'close info button': 'Close info',
|
|
33
|
+
'flip board button': 'Flip board',
|
|
33
34
|
},
|
|
34
35
|
},
|
|
35
36
|
},
|