@dxos/plugin-chess 0.8.4-main.7ace549 → 0.8.4-main.937b3ca
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-CCF24VRU.mjs → chunk-7OZ7J7LF.mjs} +9 -28
- package/dist/lib/browser/chunk-7OZ7J7LF.mjs.map +7 -0
- package/dist/lib/browser/{chunk-3LPE2B5J.mjs → chunk-DH4WQRZH.mjs} +105 -45
- package/dist/lib/browser/chunk-DH4WQRZH.mjs.map +7 -0
- package/dist/lib/browser/{chunk-DUO4WTAM.mjs → chunk-H3NUMCQ6.mjs} +1 -8
- package/dist/lib/browser/chunk-H3NUMCQ6.mjs.map +7 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/browser/{chunk-Q5TZCIH7.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 +44 -69
- 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-VVXTAVIS.mjs → chunk-DOBR6ILE.mjs} +2 -2
- package/dist/lib/node-esm/{chunk-KNOOJFIR.mjs → chunk-F5OMIM4F.mjs} +1 -7
- 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-QKXLEJNZ.mjs → chunk-NAYRVJR4.mjs} +9 -28
- package/dist/lib/node-esm/chunk-NAYRVJR4.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-F3HFLDV5.mjs → chunk-NFDJU7XQ.mjs} +105 -45
- 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 +44 -69
- 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-KV2KBSIU.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/{functions → blueprints/functions}/create.d.ts +5 -4
- 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/blueprints/functions/move.d.ts.map +1 -0
- 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 +1 -8
- 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 +6 -6
- 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 -2
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/types/Chess.d.ts +14 -14
- 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 +63 -48
- package/src/ChessPlugin.tsx +25 -46
- package/src/blueprints/chess-blueprint.ts +28 -0
- package/src/{functions → blueprints/functions}/create.ts +10 -4
- package/src/{functions → blueprints/functions}/index.ts +1 -0
- package/src/{functions → blueprints/functions}/move.ts +9 -5
- package/src/{functions → blueprints/functions}/play.ts +9 -5
- 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 +18 -37
- package/src/components/Chessboard.stories.tsx +15 -11
- package/src/components/Chessboard.tsx +21 -10
- package/src/components/ChessboardArticle.tsx +8 -5
- package/src/components/ChessboardContainer.tsx +9 -13
- package/src/components/Info.tsx +11 -7
- package/src/index.ts +1 -1
- package/src/meta.ts +2 -2
- package/src/types/Chess.ts +3 -3
- package/src/types/index.ts +0 -1
- package/dist/lib/browser/ChessboardContainer-5YXEM4VR.mjs +0 -96
- package/dist/lib/browser/ChessboardContainer-5YXEM4VR.mjs.map +0 -7
- package/dist/lib/browser/blueprint-definition-Y5Y4YGNL.mjs +0 -11
- package/dist/lib/browser/chunk-3LPE2B5J.mjs.map +0 -7
- package/dist/lib/browser/chunk-5DOZV3PW.mjs +0 -294
- package/dist/lib/browser/chunk-5DOZV3PW.mjs.map +0 -7
- package/dist/lib/browser/chunk-CCF24VRU.mjs.map +0 -7
- package/dist/lib/browser/chunk-DUO4WTAM.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-KPGHK5JU.mjs +0 -25
- package/dist/lib/browser/intent-resolver-KPGHK5JU.mjs.map +0 -7
- package/dist/lib/browser/react-surface-3YST34QI.mjs +0 -38
- package/dist/lib/browser/react-surface-3YST34QI.mjs.map +0 -7
- package/dist/lib/node-esm/ChessboardContainer-7OQ6TOKB.mjs +0 -97
- package/dist/lib/node-esm/ChessboardContainer-7OQ6TOKB.mjs.map +0 -7
- package/dist/lib/node-esm/blueprint-definition-GR6OLMB6.mjs +0 -12
- package/dist/lib/node-esm/chunk-F3HFLDV5.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-F4C2HVZL.mjs +0 -295
- package/dist/lib/node-esm/chunk-F4C2HVZL.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-KNOOJFIR.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-QKXLEJNZ.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-ZAELGF7I.mjs +0 -26
- package/dist/lib/node-esm/intent-resolver-ZAELGF7I.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-KV2KBSIU.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.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 -129
- 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/types/ChessAction.ts +0 -19
- /package/dist/lib/browser/{blueprint-definition-Y5Y4YGNL.mjs.map → blueprints/index.mjs.map} +0 -0
- /package/dist/lib/{node-esm/blueprint-definition-GR6OLMB6.mjs.map → browser/chunk-J5LGTIGS.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-Q5TZCIH7.mjs.map → chunk-MV2GQK7M.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-VVXTAVIS.mjs.map → chunk-DOBR6ILE.mjs.map} +0 -0
- /package/dist/types/src/{functions → blueprints/functions}/move.d.ts +0 -0
- /package/dist/types/src/{functions → blueprints/functions}/play.d.ts +0 -0
|
@@ -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
|
+
);
|
|
@@ -3,64 +3,45 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
-
import React from 'react';
|
|
6
|
+
import React, { useMemo } from 'react';
|
|
7
7
|
|
|
8
8
|
import { withTheme } from '@dxos/react-ui/testing';
|
|
9
|
-
import { CardContainer } from '@dxos/react-ui-
|
|
9
|
+
import { CardContainer } from '@dxos/react-ui-mosaic/testing';
|
|
10
10
|
|
|
11
11
|
import { meta as pluginMeta } from '../meta';
|
|
12
12
|
import { Chess } from '../types';
|
|
13
13
|
|
|
14
14
|
import { Chessboard } from './Chessboard';
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
game: Chess.Game;
|
|
19
|
-
};
|
|
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 *';
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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}>
|
|
25
24
|
<Chessboard.Root game={game}>
|
|
26
|
-
<Chessboard.Content
|
|
25
|
+
<Chessboard.Content>
|
|
27
26
|
<Chessboard.Board />
|
|
28
27
|
</Chessboard.Content>
|
|
29
28
|
</Chessboard.Root>
|
|
30
29
|
</CardContainer>
|
|
31
|
-
)
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const meta = {
|
|
34
|
+
title: 'plugins/plugin-chess/Card',
|
|
35
|
+
render: () => <CardStory />,
|
|
32
36
|
decorators: [withTheme],
|
|
33
37
|
parameters: {
|
|
34
38
|
layout: 'centered',
|
|
35
39
|
},
|
|
36
40
|
tags: ['cards'],
|
|
37
|
-
} satisfies Meta
|
|
41
|
+
} satisfies Meta;
|
|
38
42
|
|
|
39
43
|
export default meta;
|
|
40
44
|
|
|
41
|
-
const game = Chess.makeGame({
|
|
42
|
-
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 *',
|
|
43
|
-
});
|
|
44
|
-
|
|
45
45
|
type Story = StoryObj<typeof meta>;
|
|
46
46
|
|
|
47
|
-
export const Popover: Story = {
|
|
48
|
-
args: {
|
|
49
|
-
role: 'card--popover',
|
|
50
|
-
game: game,
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export const Intrinsic: Story = {
|
|
55
|
-
args: {
|
|
56
|
-
role: 'card--intrinsic',
|
|
57
|
-
game: game,
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export const Extrinsic: Story = {
|
|
62
|
-
args: {
|
|
63
|
-
role: 'card--extrinsic',
|
|
64
|
-
game: game,
|
|
65
|
-
},
|
|
66
|
-
};
|
|
47
|
+
export const Popover: Story = {};
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
+
import React, { useMemo } from 'react';
|
|
6
7
|
|
|
7
8
|
import { withClientProvider } from '@dxos/react-client/testing';
|
|
8
9
|
import { withTheme } from '@dxos/react-ui/testing';
|
|
@@ -12,38 +13,41 @@ import { Chess } from '../types';
|
|
|
12
13
|
|
|
13
14
|
import { ChessboardArticle } from './ChessboardArticle';
|
|
14
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
|
+
|
|
15
25
|
const meta = {
|
|
16
26
|
title: 'plugins/plugin-chess/Chessboard',
|
|
17
|
-
component:
|
|
27
|
+
component: DefaultStory,
|
|
18
28
|
decorators: [withTheme, withClientProvider({ createIdentity: true })],
|
|
19
29
|
parameters: {
|
|
20
30
|
layout: 'fullscreen',
|
|
21
31
|
translations,
|
|
22
32
|
},
|
|
23
|
-
} satisfies Meta<typeof
|
|
33
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
24
34
|
|
|
25
35
|
export default meta;
|
|
26
36
|
|
|
27
37
|
type Story = StoryObj<typeof meta>;
|
|
28
38
|
|
|
29
39
|
export const Default: Story = {
|
|
30
|
-
args: {
|
|
31
|
-
game: Chess.makeGame(),
|
|
32
|
-
},
|
|
40
|
+
args: {},
|
|
33
41
|
};
|
|
34
42
|
|
|
35
43
|
export const EndGame: Story = {
|
|
36
44
|
args: {
|
|
37
|
-
|
|
38
|
-
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 *',
|
|
39
|
-
}),
|
|
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 *',
|
|
40
46
|
},
|
|
41
47
|
};
|
|
42
48
|
|
|
43
49
|
export const Promption: Story = {
|
|
44
50
|
args: {
|
|
45
|
-
|
|
46
|
-
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 *',
|
|
47
|
-
}),
|
|
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 *',
|
|
48
52
|
},
|
|
49
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 { type SurfaceComponentProps } from '@dxos/app-framework/react';
|
|
7
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,7 +29,7 @@ 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
35
|
<Toolbar.IconButton
|
|
@@ -63,6 +66,6 @@ export const ChessboardArticle = ({ game, role }: { game: Chess.Game; role?: str
|
|
|
63
66
|
)}
|
|
64
67
|
</div>
|
|
65
68
|
</Chessboard.Root>
|
|
66
|
-
</
|
|
69
|
+
</Layout.Main>
|
|
67
70
|
);
|
|
68
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,6 +100,7 @@ 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
106
|
? t('game.checkmate label')
|
|
@@ -130,11 +134,11 @@ 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
|
|
@@ -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}
|
package/src/index.ts
CHANGED
package/src/meta.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
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 meta:
|
|
8
|
+
export const meta: Plugin.Meta = {
|
|
9
9
|
id: 'dxos.org/plugin/chess',
|
|
10
10
|
name: 'Chess',
|
|
11
11
|
description: trim`
|
package/src/types/Chess.ts
CHANGED
|
@@ -30,7 +30,7 @@ export const Game = Schema.Struct({
|
|
|
30
30
|
description: 'Forsyth-Edwards Notation.',
|
|
31
31
|
}).pipe(FormInputAnnotation.set(false), Schema.optional),
|
|
32
32
|
}).pipe(
|
|
33
|
-
Type.
|
|
33
|
+
Type.object({
|
|
34
34
|
typename: 'dxos.org/type/Chess',
|
|
35
35
|
version: '0.2.0',
|
|
36
36
|
}),
|
|
@@ -39,7 +39,7 @@ export const Game = Schema.Struct({
|
|
|
39
39
|
|
|
40
40
|
export interface Game extends Schema.Schema.Type<typeof Game> {}
|
|
41
41
|
|
|
42
|
-
export const
|
|
42
|
+
export const make = ({ name, pgn, fen }: { name?: string; pgn?: string; fen?: string } = {}) => {
|
|
43
43
|
const chess = new ChessJS();
|
|
44
44
|
if (pgn) {
|
|
45
45
|
try {
|
|
@@ -51,8 +51,8 @@ export const makeGame = ({ name, pgn, fen }: { name?: string; pgn?: string; fen?
|
|
|
51
51
|
|
|
52
52
|
return Obj.make(Game, {
|
|
53
53
|
name,
|
|
54
|
-
players: {},
|
|
55
54
|
pgn,
|
|
56
55
|
fen,
|
|
56
|
+
players: {},
|
|
57
57
|
});
|
|
58
58
|
};
|
package/src/types/index.ts
CHANGED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Chessboard
|
|
3
|
-
} from "./chunk-5DOZV3PW.mjs";
|
|
4
|
-
import {
|
|
5
|
-
meta
|
|
6
|
-
} from "./chunk-DUO4WTAM.mjs";
|
|
7
|
-
|
|
8
|
-
// src/components/ChessboardContainer.tsx
|
|
9
|
-
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
10
|
-
import React2 from "react";
|
|
11
|
-
import { getSpace } from "@dxos/react-client/echo";
|
|
12
|
-
|
|
13
|
-
// src/components/ChessboardArticle.tsx
|
|
14
|
-
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
15
|
-
import React, { useCallback, useRef, useState } from "react";
|
|
16
|
-
import { Toolbar, useTranslation } from "@dxos/react-ui";
|
|
17
|
-
import { StackItem } from "@dxos/react-ui-stack";
|
|
18
|
-
import { mx } from "@dxos/react-ui-theme";
|
|
19
|
-
var ChessboardArticle = ({ game, role }) => {
|
|
20
|
-
var _effect = _useSignals();
|
|
21
|
-
try {
|
|
22
|
-
const { t } = useTranslation(meta.id);
|
|
23
|
-
const [orientation, setOrientation] = useState("white");
|
|
24
|
-
const [open, setOpen] = useState(true);
|
|
25
|
-
const controller = useRef(null);
|
|
26
|
-
const handleSelect = useCallback((index) => {
|
|
27
|
-
controller.current?.setMoveNumber(index);
|
|
28
|
-
}, []);
|
|
29
|
-
return /* @__PURE__ */ React.createElement(StackItem.Content, {
|
|
30
|
-
toolbar: true,
|
|
31
|
-
classNames: "@container"
|
|
32
|
-
}, /* @__PURE__ */ React.createElement(Chessboard.Root, {
|
|
33
|
-
game,
|
|
34
|
-
ref: controller
|
|
35
|
-
}, /* @__PURE__ */ React.createElement(Toolbar.Root, null, /* @__PURE__ */ React.createElement(Toolbar.IconButton, {
|
|
36
|
-
icon: "ph--info--regular",
|
|
37
|
-
iconOnly: true,
|
|
38
|
-
label: t("toggle info button"),
|
|
39
|
-
disabled: open,
|
|
40
|
-
classNames: mx("invisible @3xl:visible"),
|
|
41
|
-
onClick: () => setOpen((open2) => !open2)
|
|
42
|
-
})), /* @__PURE__ */ React.createElement("div", {
|
|
43
|
-
className: mx("grid bs-full is-full gap-2", open && "@3xl:grid-cols-[1fr_320px]", role === "section" && "aspect-square", role === "section" && open && "@3xl:aspect-auto")
|
|
44
|
-
}, /* @__PURE__ */ React.createElement(Chessboard.Content, null, /* @__PURE__ */ React.createElement(Chessboard.Board, {
|
|
45
|
-
classNames: "m-4 rounded-sm overflow-hidden",
|
|
46
|
-
orientation
|
|
47
|
-
})), open && /* @__PURE__ */ React.createElement("div", {
|
|
48
|
-
className: "hidden @3xl:flex flex-col p-8 justify-center items-center overflow-hidden"
|
|
49
|
-
}, /* @__PURE__ */ React.createElement(Chessboard.Info, {
|
|
50
|
-
orientation,
|
|
51
|
-
min: 8,
|
|
52
|
-
max: 8,
|
|
53
|
-
onOrientationChange: setOrientation,
|
|
54
|
-
onClose: () => setOpen(false),
|
|
55
|
-
onSelect: handleSelect
|
|
56
|
-
})))));
|
|
57
|
-
} finally {
|
|
58
|
-
_effect.f();
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
// src/components/ChessboardContainer.tsx
|
|
63
|
-
var ChessboardContainer = ({ game, role }) => {
|
|
64
|
-
var _effect = _useSignals2();
|
|
65
|
-
try {
|
|
66
|
-
const space = getSpace(game);
|
|
67
|
-
if (!space) {
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
switch (role) {
|
|
71
|
-
case "card--popover":
|
|
72
|
-
case "card--intrinsic":
|
|
73
|
-
case "card--extrinsic": {
|
|
74
|
-
return /* @__PURE__ */ React2.createElement(Chessboard.Root, {
|
|
75
|
-
game
|
|
76
|
-
}, /* @__PURE__ */ React2.createElement(Chessboard.Content, {
|
|
77
|
-
role
|
|
78
|
-
}, /* @__PURE__ */ React2.createElement(Chessboard.Board, null)));
|
|
79
|
-
}
|
|
80
|
-
default: {
|
|
81
|
-
return /* @__PURE__ */ React2.createElement(ChessboardArticle, {
|
|
82
|
-
game,
|
|
83
|
-
role
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
} finally {
|
|
88
|
-
_effect.f();
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
var ChessboardContainer_default = ChessboardContainer;
|
|
92
|
-
export {
|
|
93
|
-
ChessboardContainer,
|
|
94
|
-
ChessboardContainer_default as default
|
|
95
|
-
};
|
|
96
|
-
//# sourceMappingURL=ChessboardContainer-5YXEM4VR.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/ChessboardContainer.tsx", "../../../src/components/ChessboardArticle.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport React from 'react';\n\nimport { getSpace } from '@dxos/react-client/echo';\n\nimport { type Chess } from '../types';\n\nimport { Chessboard } from './Chessboard';\nimport { ChessboardArticle } from './ChessboardArticle';\n\nexport type ChessboardContainerProps = {\n game: Chess.Game;\n role?: string;\n};\n\nexport const ChessboardContainer = ({ game, role }: ChessboardContainerProps) => {\n const space = getSpace(game);\n if (!space) {\n return null;\n }\n\n switch (role) {\n case 'card--popover':\n case 'card--intrinsic':\n case 'card--extrinsic': {\n return (\n <Chessboard.Root game={game}>\n <Chessboard.Content role={role}>\n <Chessboard.Board />\n </Chessboard.Content>\n </Chessboard.Root>\n );\n }\n\n default: {\n return <ChessboardArticle game={game} role={role} />;\n }\n }\n};\n\nexport default ChessboardContainer;\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { useCallback, useRef, useState } from 'react';\n\nimport { Toolbar, useTranslation } from '@dxos/react-ui';\nimport { type Player } from '@dxos/react-ui-gameboard';\nimport { StackItem } from '@dxos/react-ui-stack';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { meta } from '../meta';\nimport { type Chess } from '../types';\n\nimport { Chessboard, type ChessboardController, type ChessboardInfoProps } from './Chessboard';\n\nexport const ChessboardArticle = ({ game, role }: { game: Chess.Game; role?: string }) => {\n const { t } = useTranslation(meta.id);\n const [orientation, setOrientation] = useState<Player>('white');\n const [open, setOpen] = useState(true);\n const controller = useRef<ChessboardController>(null);\n\n // TODO(burdon): Keyboard handler.\n const handleSelect = useCallback<NonNullable<ChessboardInfoProps['onSelect']>>((index) => {\n controller.current?.setMoveNumber(index);\n }, []);\n\n return (\n <StackItem.Content toolbar classNames='@container'>\n <Chessboard.Root game={game} ref={controller}>\n <Toolbar.Root>\n <Toolbar.IconButton\n icon='ph--info--regular'\n iconOnly\n label={t('toggle info button')}\n disabled={open}\n classNames={mx('invisible @3xl:visible')}\n onClick={() => setOpen((open) => !open)}\n />\n </Toolbar.Root>\n <div\n className={mx(\n 'grid bs-full is-full gap-2',\n open && '@3xl:grid-cols-[1fr_320px]',\n role === 'section' && 'aspect-square',\n role === 'section' && open && '@3xl:aspect-auto',\n )}\n >\n <Chessboard.Content>\n <Chessboard.Board classNames='m-4 rounded-sm overflow-hidden' orientation={orientation} />\n </Chessboard.Content>\n {open && (\n <div className='hidden @3xl:flex flex-col p-8 justify-center items-center overflow-hidden'>\n <Chessboard.Info\n orientation={orientation}\n min={8}\n max={8}\n onOrientationChange={setOrientation}\n onClose={() => setOpen(false)}\n onSelect={handleSelect}\n />\n </div>\n )}\n </div>\n </Chessboard.Root>\n </StackItem.Content>\n );\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;AAIA,OAAOA,YAAW;AAElB,SAASC,gBAAgB;;;;ACFzB,OAAOC,SAASC,aAAaC,QAAQC,gBAAgB;AAErD,SAASC,SAASC,sBAAsB;AAExC,SAASC,iBAAiB;AAC1B,SAASC,UAAU;AAOZ,IAAMC,oBAAoB,CAAC,EAAEC,MAAMC,KAAI,MAAuC;;;AACnF,UAAM,EAAEC,EAAC,IAAKC,eAAeC,KAAKC,EAAE;AACpC,UAAM,CAACC,aAAaC,cAAAA,IAAkBC,SAAiB,OAAA;AACvD,UAAM,CAACC,MAAMC,OAAAA,IAAWF,SAAS,IAAA;AACjC,UAAMG,aAAaC,OAA6B,IAAA;AAGhD,UAAMC,eAAeC,YAA0D,CAACC,UAAAA;AAC9EJ,iBAAWK,SAASC,cAAcF,KAAAA;IACpC,GAAG,CAAA,CAAE;AAEL,WACE,sBAAA,cAACG,UAAUC,SAAO;MAACC,SAAAA;MAAQC,YAAW;OACpC,sBAAA,cAACC,WAAWC,MAAI;MAACvB;MAAYwB,KAAKb;OAChC,sBAAA,cAACc,QAAQF,MAAI,MACX,sBAAA,cAACE,QAAQC,YAAU;MACjBC,MAAK;MACLC,UAAAA;MACAC,OAAO3B,EAAE,oBAAA;MACT4B,UAAUrB;MACVY,YAAYU,GAAG,wBAAA;MACfC,SAAS,MAAMtB,QAAQ,CAACD,UAAS,CAACA,KAAAA;SAGtC,sBAAA,cAACwB,OAAAA;MACCC,WAAWH,GACT,8BACAtB,QAAQ,8BACRR,SAAS,aAAa,iBACtBA,SAAS,aAAaQ,QAAQ,kBAAA;OAGhC,sBAAA,cAACa,WAAWH,SAAO,MACjB,sBAAA,cAACG,WAAWa,OAAK;MAACd,YAAW;MAAiCf;SAE/DG,QACC,sBAAA,cAACwB,OAAAA;MAAIC,WAAU;OACb,sBAAA,cAACZ,WAAWc,MAAI;MACd9B;MACA+B,KAAK;MACLC,KAAK;MACLC,qBAAqBhC;MACrBiC,SAAS,MAAM9B,QAAQ,KAAA;MACvB+B,UAAU5B;;;;;AAQ1B;;;ADjDO,IAAM6B,sBAAsB,CAAC,EAAEC,MAAMC,KAAI,MAA4B;;;AAC1E,UAAMC,QAAQC,SAASH,IAAAA;AACvB,QAAI,CAACE,OAAO;AACV,aAAO;IACT;AAEA,YAAQD,MAAAA;MACN,KAAK;MACL,KAAK;MACL,KAAK,mBAAmB;AACtB,eACE,gBAAAG,OAAA,cAACC,WAAWC,MAAI;UAACN;WACf,gBAAAI,OAAA,cAACC,WAAWE,SAAO;UAACN;WAClB,gBAAAG,OAAA,cAACC,WAAWG,OAAK,IAAA,CAAA,CAAA;MAIzB;MAEA,SAAS;AACP,eAAO,gBAAAJ,OAAA,cAACK,mBAAAA;UAAkBT;UAAYC;;MACxC;IACF;;;;AACF;AAEA,IAAA,8BAAeF;",
|
|
6
|
-
"names": ["React", "getSpace", "React", "useCallback", "useRef", "useState", "Toolbar", "useTranslation", "StackItem", "mx", "ChessboardArticle", "game", "role", "t", "useTranslation", "meta", "id", "orientation", "setOrientation", "useState", "open", "setOpen", "controller", "useRef", "handleSelect", "useCallback", "index", "current", "setMoveNumber", "StackItem", "Content", "toolbar", "classNames", "Chessboard", "Root", "ref", "Toolbar", "IconButton", "icon", "iconOnly", "label", "disabled", "mx", "onClick", "div", "className", "Board", "Info", "min", "max", "onOrientationChange", "onClose", "onSelect", "ChessboardContainer", "game", "role", "space", "getSpace", "React", "Chessboard", "Root", "Content", "Board", "ChessboardArticle"]
|
|
7
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CHESS_BLUEPRINT_KEY,
|
|
3
|
-
blueprint_definition_default
|
|
4
|
-
} from "./chunk-3LPE2B5J.mjs";
|
|
5
|
-
import "./chunk-CCF24VRU.mjs";
|
|
6
|
-
import "./chunk-DUO4WTAM.mjs";
|
|
7
|
-
export {
|
|
8
|
-
CHESS_BLUEPRINT_KEY,
|
|
9
|
-
blueprint_definition_default as default
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=blueprint-definition-Y5Y4YGNL.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/capabilities/blueprint-definition.ts", "../../../src/functions/create.ts", "../../../src/functions/move.ts", "../../../src/functions/play.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Capabilities, contributes } from '@dxos/app-framework';\nimport { Blueprint, Template } from '@dxos/blueprints';\nimport { type FunctionDefinition } from '@dxos/functions';\nimport { trim } from '@dxos/util';\n\nimport { create, move, play } from '../functions';\n\nconst functions: FunctionDefinition[] = [create, move, play];\n\nexport const CHESS_BLUEPRINT_KEY = 'dxos.org/blueprint/chess';\n\nexport default () => {\n return [\n contributes(Capabilities.Functions, functions),\n contributes(\n Capabilities.BlueprintDefinition,\n Blueprint.make({\n key: CHESS_BLUEPRINT_KEY,\n name: 'Chess',\n tools: Blueprint.toolDefinitions({ functions }),\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 }),\n }),\n ),\n ];\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\nimport * as Schema from 'effect/Schema';\n\nimport { DatabaseService, defineFunction } from '@dxos/functions';\n\nimport { Chess } from '../types';\n\nexport default defineFunction({\n key: 'dxos.org/function/chess/create',\n name: 'Create Chess',\n description: 'Creates a new chess game.',\n inputSchema: 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 outputSchema: Chess.Game,\n handler: Effect.fn(function* ({ data: { pgn, fen } }) {\n return yield* DatabaseService.add(Chess.makeGame({ pgn, fen }));\n }),\n});\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Chess as ChessJS } from 'chess.js';\nimport * as Effect from 'effect/Effect';\nimport * as Schema from 'effect/Schema';\n\nimport { ArtifactId } from '@dxos/assistant';\nimport { DatabaseService, defineFunction } from '@dxos/functions';\n\nimport { Chess } from '../types';\n\nexport default defineFunction({\n key: 'dxos.org/function/chess/move',\n name: 'Move',\n description: 'Makes a move in the given chess game.',\n inputSchema: Schema.Struct({\n id: ArtifactId.annotations({\n description: 'The ID of the chess object.',\n }),\n move: Schema.String.annotations({\n description: 'The move to make in the chess game.',\n examples: ['e4', 'Bf3'],\n }),\n }),\n outputSchema: Schema.Struct({\n pgn: Schema.String.annotations({\n description: 'The PGN of the game after the move was played.',\n }),\n }),\n handler: Effect.fn(function* ({ data: { id, move } }) {\n const object = yield* DatabaseService.resolve(ArtifactId.toDXN(id), Chess.Game);\n const chess = new ChessJS();\n if (object.pgn) {\n chess.loadPgn(object.pgn);\n } else if (object.fen) {\n chess.load(object.fen);\n }\n\n chess.move(move, { strict: false });\n object.pgn = chess.pgn();\n return { pgn: object.pgn };\n }),\n});\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Chess as ChessJS } from 'chess.js';\nimport * as Effect from 'effect/Effect';\nimport * as Schema from 'effect/Schema';\n\nimport { ArtifactId } from '@dxos/assistant';\nimport { DatabaseService, defineFunction } from '@dxos/functions';\n\nimport { Chess } from '../types';\n\nexport default defineFunction({\n key: 'dxos.org/function/chess/play',\n name: 'Play',\n description: 'Uses the chess engine to play the next move.',\n inputSchema: Schema.Struct({\n id: ArtifactId.annotations({\n description: 'The ID of the chess object.',\n }),\n side: Schema.optional(Schema.Literal('white', 'black', 'any')).annotations({\n description: 'The side to play.',\n defaultValue: 'any',\n }),\n }),\n outputSchema: 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 handler: Effect.fn(function* ({ data: { id, side = 'any' } }) {\n const object = yield* DatabaseService.resolve(ArtifactId.toDXN(id), Chess.Game);\n const chess = new ChessJS();\n if (object.pgn) {\n chess.loadPgn(object.pgn);\n } else if (object.fen) {\n chess.load(object.fen);\n }\n\n if (!(side === 'any' || (chess.turn() === 'w' && side === 'white') || (chess.turn() === 'b' && side === 'black'))) {\n return { move: undefined, pgn: object.pgn! };\n }\n\n const moves = chess.moves();\n const move = moves[Math.floor(Math.random() * moves.length)];\n\n chess.move(move, { strict: false });\n object.pgn = chess.pgn();\n return { move, pgn: object.pgn };\n }),\n});\n"],
|
|
5
|
-
"mappings": "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",
|
|
6
|
-
"names": ["Capabilities", "contributes", "Blueprint", "Template", "trim", "Effect", "Schema", "DatabaseService", "defineFunction", "defineFunction", "key", "name", "description", "inputSchema", "Struct", "pgn", "optional", "String", "annotations", "fen", "outputSchema", "Chess", "Game", "handler", "fn", "data", "DatabaseService", "add", "makeGame", "Chess", "ChessJS", "Effect", "Schema", "ArtifactId", "DatabaseService", "defineFunction", "defineFunction", "key", "name", "description", "inputSchema", "Struct", "id", "ArtifactId", "annotations", "move", "String", "examples", "outputSchema", "pgn", "handler", "fn", "data", "object", "DatabaseService", "resolve", "toDXN", "Chess", "Game", "chess", "ChessJS", "loadPgn", "fen", "load", "strict", "Chess", "ChessJS", "Effect", "Schema", "ArtifactId", "DatabaseService", "defineFunction", "defineFunction", "key", "name", "description", "inputSchema", "Struct", "id", "ArtifactId", "annotations", "side", "optional", "Literal", "defaultValue", "outputSchema", "pgn", "String", "move", "handler", "fn", "data", "object", "DatabaseService", "resolve", "toDXN", "Chess", "Game", "chess", "ChessJS", "loadPgn", "fen", "load", "turn", "undefined", "moves", "Math", "floor", "random", "length", "strict", "functions", "create", "move", "play", "CHESS_BLUEPRINT_KEY", "contributes", "Capabilities", "Functions", "BlueprintDefinition", "Blueprint", "make", "key", "name", "tools", "toolDefinitions", "instructions", "Template", "source", "trim"]
|
|
7
|
-
}
|