@dxos/plugin-chess 0.8.4-main.f5c0578 → 0.8.4-main.fcc0d83b33
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/blueprints/index.mjs +43 -0
- package/dist/lib/browser/blueprints/index.mjs.map +7 -0
- package/dist/lib/browser/chunk-2DFOUJBD.mjs +28 -0
- package/dist/lib/browser/chunk-2DFOUJBD.mjs.map +7 -0
- package/dist/lib/browser/chunk-IN3LZ2OO.mjs +62 -0
- package/dist/lib/browser/chunk-IN3LZ2OO.mjs.map +7 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/browser/chunk-OBKYFOJA.mjs +110 -0
- package/dist/lib/browser/chunk-OBKYFOJA.mjs.map +7 -0
- package/dist/lib/browser/cli/index.mjs +34 -0
- package/dist/lib/browser/cli/index.mjs.map +7 -0
- package/dist/lib/browser/create-2ME3FNBX.mjs +24 -0
- package/dist/lib/browser/create-2ME3FNBX.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +330 -104
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/move-TTMIPD5J.mjs +36 -0
- package/dist/lib/browser/move-TTMIPD5J.mjs.map +7 -0
- package/dist/lib/browser/operations/index.mjs +19 -0
- package/dist/lib/browser/operations/index.mjs.map +7 -0
- package/dist/lib/browser/play-GHXPV2T2.mjs +45 -0
- package/dist/lib/browser/play-GHXPV2T2.mjs.map +7 -0
- package/dist/lib/browser/print-RNAGAOM7.mjs +30 -0
- package/dist/lib/browser/print-RNAGAOM7.mjs.map +7 -0
- package/dist/lib/browser/translations.mjs +38 -0
- package/dist/lib/browser/translations.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +3 -5
- package/dist/lib/node-esm/blueprints/index.mjs +44 -0
- package/dist/lib/node-esm/blueprints/index.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-G2EHRXHX.mjs +111 -0
- package/dist/lib/node-esm/chunk-G2EHRXHX.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-OHBKSL2Q.mjs +63 -0
- package/dist/lib/node-esm/chunk-OHBKSL2Q.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-V4FN2DZR.mjs +29 -0
- package/dist/lib/node-esm/chunk-V4FN2DZR.mjs.map +7 -0
- package/dist/lib/node-esm/cli/index.mjs +35 -0
- package/dist/lib/node-esm/cli/index.mjs.map +7 -0
- package/dist/lib/node-esm/create-CC2P7GPT.mjs +25 -0
- package/dist/lib/node-esm/create-CC2P7GPT.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +330 -104
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/move-CYHXWHHM.mjs +37 -0
- package/dist/lib/node-esm/move-CYHXWHHM.mjs.map +7 -0
- package/dist/lib/node-esm/operations/index.mjs +20 -0
- package/dist/lib/node-esm/operations/index.mjs.map +7 -0
- package/dist/lib/node-esm/play-KTNK2PBL.mjs +46 -0
- package/dist/lib/node-esm/play-KTNK2PBL.mjs.map +7 -0
- package/dist/lib/node-esm/print-P23VKVNU.mjs +31 -0
- package/dist/lib/node-esm/print-P23VKVNU.mjs.map +7 -0
- package/dist/lib/node-esm/translations.mjs +39 -0
- package/dist/lib/node-esm/translations.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/ChessPlugin.test.d.ts +2 -0
- package/dist/types/src/ChessPlugin.test.d.ts.map +1 -0
- package/dist/types/src/blueprints/chess-blueprint.d.ts +4 -0
- package/dist/types/src/blueprints/chess-blueprint.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.d.ts +3 -2
- package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -1
- package/dist/types/src/capabilities/blueprint-definition.d.ts +4 -2
- package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +5 -3
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
- package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface.d.ts +3 -2
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- 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/Chessboard/Chessboard.d.ts +38 -0
- package/dist/types/src/components/Chessboard/Chessboard.d.ts.map +1 -0
- package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts +65 -0
- package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts.map +1 -0
- package/dist/types/src/components/Chessboard/Info.d.ts +20 -0
- package/dist/types/src/components/Chessboard/Info.d.ts.map +1 -0
- package/dist/types/src/components/Chessboard/index.d.ts +2 -0
- package/dist/types/src/components/Chessboard/index.d.ts.map +1 -0
- package/dist/types/src/components/Chessboard/types.d.ts +8 -0
- package/dist/types/src/components/Chessboard/types.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +0 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/containers/ChessArticle/ChessArticle.d.ts +6 -0
- package/dist/types/src/containers/ChessArticle/ChessArticle.d.ts.map +1 -0
- package/dist/types/src/containers/ChessArticle/ChessArticle.stories.d.ts +64 -0
- package/dist/types/src/containers/ChessArticle/ChessArticle.stories.d.ts.map +1 -0
- package/dist/types/src/containers/ChessArticle/index.d.ts +2 -0
- package/dist/types/src/containers/ChessArticle/index.d.ts.map +1 -0
- package/dist/types/src/containers/ChessCard/ChessCard.d.ts +6 -0
- package/dist/types/src/containers/ChessCard/ChessCard.d.ts.map +1 -0
- package/dist/types/src/containers/ChessCard/ChessCard.stories.d.ts +15 -0
- package/dist/types/src/containers/ChessCard/ChessCard.stories.d.ts.map +1 -0
- package/dist/types/src/containers/ChessCard/index.d.ts +2 -0
- package/dist/types/src/containers/ChessCard/index.d.ts.map +1 -0
- package/dist/types/src/containers/index.d.ts +4 -0
- package/dist/types/src/containers/index.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +1 -4
- 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/operations/create.d.ts +5 -0
- package/dist/types/src/operations/create.d.ts.map +1 -0
- package/dist/types/src/operations/definitions.d.ts +51 -0
- package/dist/types/src/operations/definitions.d.ts.map +1 -0
- package/dist/types/src/operations/index.d.ts +4 -0
- package/dist/types/src/operations/index.d.ts.map +1 -0
- package/dist/types/src/operations/move.d.ts +5 -0
- package/dist/types/src/operations/move.d.ts.map +1 -0
- package/dist/types/src/operations/play.d.ts +5 -0
- package/dist/types/src/operations/play.d.ts.map +1 -0
- package/dist/types/src/operations/print.d.ts +5 -0
- package/dist/types/src/operations/print.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +40 -20
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Chess.d.ts +20 -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 +80 -43
- package/src/ChessPlugin.test.ts +51 -0
- package/src/ChessPlugin.tsx +42 -54
- package/src/blueprints/chess-blueprint.ts +34 -0
- package/src/blueprints/index.ts +6 -0
- package/src/capabilities/artifact-definition.ts +100 -93
- package/src/capabilities/blueprint-definition.ts +10 -27
- package/src/capabilities/index.ts +8 -4
- package/src/capabilities/operation-handler.ts +14 -0
- package/src/capabilities/react-surface.tsx +27 -15
- package/src/cli/index.ts +5 -0
- package/src/cli/plugin.ts +37 -0
- package/src/components/Chessboard/Chessboard.stories.tsx +94 -0
- package/src/components/Chessboard/Chessboard.tsx +180 -0
- package/src/components/Chessboard/Info.tsx +253 -0
- package/src/components/Chessboard/index.ts +5 -0
- package/src/components/Chessboard/types.ts +18 -0
- package/src/components/index.ts +1 -5
- package/src/containers/ChessArticle/ChessArticle.stories.tsx +53 -0
- package/src/containers/ChessArticle/ChessArticle.tsx +73 -0
- package/src/containers/ChessArticle/index.ts +5 -0
- package/src/containers/ChessCard/ChessCard.stories.tsx +42 -0
- package/src/containers/ChessCard/ChessCard.tsx +22 -0
- package/src/containers/ChessCard/index.ts +5 -0
- package/src/containers/index.ts +8 -0
- package/src/index.ts +1 -4
- package/src/meta.ts +6 -6
- package/src/operations/create.ts +21 -0
- package/src/operations/definitions.ts +109 -0
- package/src/operations/index.ts +16 -0
- package/src/operations/move.ts +36 -0
- package/src/operations/play.ts +45 -0
- package/src/operations/print.ts +28 -0
- package/src/translations.ts +21 -17
- package/src/types/Chess.ts +29 -23
- package/src/types/index.ts +0 -1
- package/dist/lib/browser/ChessboardContainer-NNIOQIRP.mjs +0 -90
- package/dist/lib/browser/ChessboardContainer-NNIOQIRP.mjs.map +0 -7
- package/dist/lib/browser/blueprint-definition-OJQYAZGZ.mjs +0 -38
- package/dist/lib/browser/blueprint-definition-OJQYAZGZ.mjs.map +0 -7
- package/dist/lib/browser/chunk-2W3S5N6C.mjs +0 -257
- package/dist/lib/browser/chunk-2W3S5N6C.mjs.map +0 -7
- package/dist/lib/browser/chunk-EJMPHRSR.mjs +0 -94
- package/dist/lib/browser/chunk-EJMPHRSR.mjs.map +0 -7
- package/dist/lib/browser/chunk-OBJAHY6H.mjs +0 -79
- package/dist/lib/browser/chunk-OBJAHY6H.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-PPBBLHAC.mjs +0 -8
- package/dist/lib/browser/chunk-PPBBLHAC.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-JWKKRNGG.mjs +0 -25
- package/dist/lib/browser/intent-resolver-JWKKRNGG.mjs.map +0 -7
- package/dist/lib/browser/react-surface-RIXD6RTS.mjs +0 -38
- package/dist/lib/browser/react-surface-RIXD6RTS.mjs.map +0 -7
- package/dist/lib/node-esm/ChessboardContainer-FCPUV2T2.mjs +0 -91
- package/dist/lib/node-esm/ChessboardContainer-FCPUV2T2.mjs.map +0 -7
- package/dist/lib/node-esm/blueprint-definition-F5SGHCDA.mjs +0 -39
- package/dist/lib/node-esm/blueprint-definition-F5SGHCDA.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-42EKKMOO.mjs +0 -10
- package/dist/lib/node-esm/chunk-42EKKMOO.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-5APYXPBX.mjs +0 -95
- package/dist/lib/node-esm/chunk-5APYXPBX.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-6OWCPDUA.mjs +0 -29
- package/dist/lib/node-esm/chunk-6OWCPDUA.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-LCCUF5X5.mjs +0 -80
- package/dist/lib/node-esm/chunk-LCCUF5X5.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-QAGOXJGH.mjs +0 -258
- package/dist/lib/node-esm/chunk-QAGOXJGH.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-G6XJAW6C.mjs +0 -26
- package/dist/lib/node-esm/intent-resolver-G6XJAW6C.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-GGRDWZJT.mjs +0 -39
- package/dist/lib/node-esm/react-surface-GGRDWZJT.mjs.map +0 -7
- 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/components/Card.stories.d.ts +0 -49
- package/dist/types/src/components/Card.stories.d.ts.map +0 -1
- package/dist/types/src/components/Chessboard.d.ts +0 -32
- package/dist/types/src/components/Chessboard.d.ts.map +0 -1
- package/dist/types/src/components/Chessboard.stories.d.ts +0 -42
- package/dist/types/src/components/Chessboard.stories.d.ts.map +0 -1
- package/dist/types/src/components/ChessboardArticle.d.ts +0 -6
- package/dist/types/src/components/ChessboardArticle.d.ts.map +0 -1
- package/dist/types/src/components/ChessboardContainer.d.ts +0 -9
- package/dist/types/src/components/ChessboardContainer.d.ts.map +0 -1
- package/dist/types/src/components/ChessboardInfo.d.ts +0 -20
- package/dist/types/src/components/ChessboardInfo.d.ts.map +0 -1
- package/dist/types/src/components/ChessboardPlayers.d.ts +0 -8
- package/dist/types/src/components/ChessboardPlayers.d.ts.map +0 -1
- package/dist/types/src/functions/index.d.ts +0 -3
- package/dist/types/src/functions/index.d.ts.map +0 -1
- package/dist/types/src/functions/move.d.ts +0 -6
- package/dist/types/src/functions/move.d.ts.map +0 -1
- package/dist/types/src/functions/play.d.ts +0 -8
- package/dist/types/src/functions/play.d.ts.map +0 -1
- package/dist/types/src/types/ChessAction.d.ts +0 -23
- package/dist/types/src/types/ChessAction.d.ts.map +0 -1
- package/src/capabilities/intent-resolver.ts +0 -22
- package/src/components/Card.stories.tsx +0 -68
- package/src/components/Chessboard.stories.tsx +0 -50
- package/src/components/Chessboard.tsx +0 -101
- package/src/components/ChessboardArticle.tsx +0 -57
- package/src/components/ChessboardContainer.tsx +0 -44
- package/src/components/ChessboardInfo.tsx +0 -140
- package/src/components/ChessboardPlayers.tsx +0 -97
- package/src/functions/index.ts +0 -6
- package/src/functions/move.ts +0 -43
- package/src/functions/play.ts +0 -45
- package/src/types/ChessAction.ts +0 -19
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
+
import React, { useMemo } from 'react';
|
|
7
|
+
|
|
8
|
+
import { withClientProvider } from '@dxos/react-client/testing';
|
|
9
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
10
|
+
|
|
11
|
+
import { translations } from '#translations';
|
|
12
|
+
import { Chess } from '#types';
|
|
13
|
+
|
|
14
|
+
import { ChessArticle } from './ChessArticle';
|
|
15
|
+
|
|
16
|
+
type DefaultStoryProps = {
|
|
17
|
+
pgn?: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const DefaultStory = ({ pgn }: DefaultStoryProps) => {
|
|
21
|
+
const game = useMemo(() => Chess.make(pgn ? { pgn } : undefined), [pgn]);
|
|
22
|
+
return <ChessArticle role='article' subject={game} attendableId='story' />;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const meta = {
|
|
26
|
+
title: 'plugins/plugin-chess/containers/ChessArticle',
|
|
27
|
+
component: DefaultStory,
|
|
28
|
+
decorators: [withTheme(), withLayout({ layout: 'fullscreen' }), withClientProvider({ createIdentity: true })],
|
|
29
|
+
parameters: {
|
|
30
|
+
layout: 'fullscreen',
|
|
31
|
+
translations,
|
|
32
|
+
},
|
|
33
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
34
|
+
|
|
35
|
+
export default meta;
|
|
36
|
+
|
|
37
|
+
type Story = StoryObj<typeof meta>;
|
|
38
|
+
|
|
39
|
+
export const Default: Story = {
|
|
40
|
+
args: {},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const EndGame: Story = {
|
|
44
|
+
args: {
|
|
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 *',
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const Promption: Story = {
|
|
50
|
+
args: {
|
|
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 *',
|
|
52
|
+
},
|
|
53
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { useCallback, useRef, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { type AppSurface } from '@dxos/app-toolkit/ui';
|
|
8
|
+
import { Panel, Toolbar, useTranslation } from '@dxos/react-ui';
|
|
9
|
+
import { type Player } from '@dxos/react-ui-gameboard';
|
|
10
|
+
import { mx } from '@dxos/ui-theme';
|
|
11
|
+
|
|
12
|
+
import { Chessboard, type ChessboardController, type ChessboardInfoProps } from '#components';
|
|
13
|
+
import { meta } from '#meta';
|
|
14
|
+
import { type Chess } from '#types';
|
|
15
|
+
|
|
16
|
+
export type ChessArticleProps = AppSurface.ObjectArticleProps<Chess.Game>;
|
|
17
|
+
|
|
18
|
+
export const ChessArticle = ({ role, attendableId: _attendableId, subject: game }: ChessArticleProps) => {
|
|
19
|
+
const { t } = useTranslation(meta.id);
|
|
20
|
+
const [orientation, setOrientation] = useState<Player>('white');
|
|
21
|
+
const [showInfo, setShowInfo] = useState(true);
|
|
22
|
+
const controller = useRef<ChessboardController>(null);
|
|
23
|
+
|
|
24
|
+
const handleSelect = useCallback<NonNullable<ChessboardInfoProps['onSelect']>>((index) => {
|
|
25
|
+
controller.current?.setMoveNumber(index);
|
|
26
|
+
}, []);
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<Chessboard.Root game={game} ref={controller}>
|
|
30
|
+
<Panel.Root role={role} classNames='@container'>
|
|
31
|
+
<Panel.Toolbar asChild>
|
|
32
|
+
<Toolbar.Root>
|
|
33
|
+
<Toolbar.IconButton
|
|
34
|
+
icon='ph--info--regular'
|
|
35
|
+
iconOnly
|
|
36
|
+
label={t('toggle-info.button')}
|
|
37
|
+
disabled={showInfo}
|
|
38
|
+
classNames={mx('invisible @3xl:visible')}
|
|
39
|
+
onClick={() => setShowInfo((open) => !open)}
|
|
40
|
+
/>
|
|
41
|
+
</Toolbar.Root>
|
|
42
|
+
</Panel.Toolbar>
|
|
43
|
+
<Panel.Content>
|
|
44
|
+
<div
|
|
45
|
+
className={mx(
|
|
46
|
+
'grid h-full w-full',
|
|
47
|
+
showInfo && '@3xl:grid-cols-[1fr_320px] gap-8',
|
|
48
|
+
role === 'article' && 'p-4',
|
|
49
|
+
role === 'section' && 'aspect-square',
|
|
50
|
+
role === 'section' && showInfo && '@3xl:aspect-auto',
|
|
51
|
+
)}
|
|
52
|
+
>
|
|
53
|
+
<Chessboard.Content>
|
|
54
|
+
<Chessboard.Board classNames='border rounded-xs' orientation={orientation} />
|
|
55
|
+
</Chessboard.Content>
|
|
56
|
+
{showInfo && (
|
|
57
|
+
<div className='hidden @3xl:flex flex-col justify-center items-center overflow-hidden'>
|
|
58
|
+
<Chessboard.Info
|
|
59
|
+
orientation={orientation}
|
|
60
|
+
min={8}
|
|
61
|
+
max={8}
|
|
62
|
+
onOrientationChange={setOrientation}
|
|
63
|
+
onClose={() => setShowInfo(false)}
|
|
64
|
+
onSelect={handleSelect}
|
|
65
|
+
/>
|
|
66
|
+
</div>
|
|
67
|
+
)}
|
|
68
|
+
</div>
|
|
69
|
+
</Panel.Content>
|
|
70
|
+
</Panel.Root>
|
|
71
|
+
</Chessboard.Root>
|
|
72
|
+
);
|
|
73
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
+
import React, { useMemo } from 'react';
|
|
7
|
+
|
|
8
|
+
import { CardContainer } from '@dxos/react-ui-mosaic/testing';
|
|
9
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
10
|
+
|
|
11
|
+
import { meta as pluginMeta } from '#meta';
|
|
12
|
+
import { Chess } from '#types';
|
|
13
|
+
|
|
14
|
+
import { ChessCard } from './ChessCard';
|
|
15
|
+
|
|
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 *';
|
|
18
|
+
|
|
19
|
+
const CardStory = () => {
|
|
20
|
+
const game = useMemo(() => Chess.make({ pgn: SAMPLE_PGN }), []);
|
|
21
|
+
return (
|
|
22
|
+
<CardContainer role='popover' icon={pluginMeta.icon}>
|
|
23
|
+
<ChessCard subject={game} role='card--content' />
|
|
24
|
+
</CardContainer>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const meta = {
|
|
29
|
+
title: 'plugins/plugin-chess/containers/ChessCard',
|
|
30
|
+
render: () => <CardStory />,
|
|
31
|
+
decorators: [withTheme(), withLayout({ layout: 'column' })],
|
|
32
|
+
parameters: {
|
|
33
|
+
layout: 'fullscreen',
|
|
34
|
+
},
|
|
35
|
+
tags: ['cards'],
|
|
36
|
+
} satisfies Meta;
|
|
37
|
+
|
|
38
|
+
export default meta;
|
|
39
|
+
|
|
40
|
+
type Story = StoryObj<typeof meta>;
|
|
41
|
+
|
|
42
|
+
export const Popover: Story = {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
import { type AppSurface } from '@dxos/app-toolkit/ui';
|
|
8
|
+
|
|
9
|
+
import { Chessboard } from '#components';
|
|
10
|
+
import { type Chess } from '#types';
|
|
11
|
+
|
|
12
|
+
export type ChessCardProps = AppSurface.ObjectCardProps<Chess.Game>;
|
|
13
|
+
|
|
14
|
+
export const ChessCard = ({ subject: game }: ChessCardProps) => {
|
|
15
|
+
return (
|
|
16
|
+
<Chessboard.Root game={game}>
|
|
17
|
+
<Chessboard.Content>
|
|
18
|
+
<Chessboard.Board />
|
|
19
|
+
</Chessboard.Content>
|
|
20
|
+
</Chessboard.Root>
|
|
21
|
+
);
|
|
22
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './components';
|
|
7
|
-
export * from './functions';
|
|
5
|
+
export * from './components/Chessboard';
|
|
8
6
|
export * from './meta';
|
|
9
|
-
export * from './types';
|
|
10
7
|
|
|
11
8
|
export * from './ChessPlugin';
|
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: 'org.dxos.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
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import { Operation } from '@dxos/compute';
|
|
8
|
+
import { Database } from '@dxos/echo';
|
|
9
|
+
|
|
10
|
+
import { Chess } from '../types';
|
|
11
|
+
import { Create } from './definitions';
|
|
12
|
+
|
|
13
|
+
const handler: Operation.WithHandler<typeof Create> = Create.pipe(
|
|
14
|
+
Operation.withHandler(
|
|
15
|
+
Effect.fn(function* ({ name, pgn, fen }) {
|
|
16
|
+
return yield* Database.add(Chess.make({ name, pgn, fen }));
|
|
17
|
+
}),
|
|
18
|
+
),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export default handler;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { Operation } from '@dxos/compute';
|
|
8
|
+
import { Database, Ref } from '@dxos/echo';
|
|
9
|
+
|
|
10
|
+
import { Chess } from '../types';
|
|
11
|
+
|
|
12
|
+
export const Create = Operation.make({
|
|
13
|
+
meta: {
|
|
14
|
+
key: 'org.dxos.function.chess.create',
|
|
15
|
+
name: 'Create Chess',
|
|
16
|
+
description: 'Creates a new chess game.',
|
|
17
|
+
},
|
|
18
|
+
input: Schema.Struct({
|
|
19
|
+
name: Schema.optional(
|
|
20
|
+
Schema.String.annotations({
|
|
21
|
+
description: 'Name of the game.',
|
|
22
|
+
}),
|
|
23
|
+
),
|
|
24
|
+
pgn: Schema.optional(
|
|
25
|
+
Schema.String.annotations({
|
|
26
|
+
description: 'Portable Game Notation.',
|
|
27
|
+
}),
|
|
28
|
+
),
|
|
29
|
+
fen: Schema.optional(
|
|
30
|
+
Schema.String.annotations({
|
|
31
|
+
description: 'Forsyth-Edwards Notation.',
|
|
32
|
+
}),
|
|
33
|
+
),
|
|
34
|
+
}),
|
|
35
|
+
output: Chess.Game,
|
|
36
|
+
services: [Database.Service],
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export const Move = Operation.make({
|
|
40
|
+
meta: {
|
|
41
|
+
key: 'org.dxos.function.chess.move',
|
|
42
|
+
name: 'Move',
|
|
43
|
+
description: 'Makes a move in the given chess game.',
|
|
44
|
+
},
|
|
45
|
+
input: Schema.Struct({
|
|
46
|
+
game: Ref.Ref(Chess.Game).annotations({
|
|
47
|
+
description: 'The ID of the chess object.',
|
|
48
|
+
}),
|
|
49
|
+
move: Schema.String.annotations({
|
|
50
|
+
description: 'The move to make in the chess game.',
|
|
51
|
+
examples: ['e4', 'Bf3'],
|
|
52
|
+
}),
|
|
53
|
+
}),
|
|
54
|
+
output: Schema.Struct({
|
|
55
|
+
pgn: Schema.String.annotations({
|
|
56
|
+
description: 'The PGN of the game after the move was played.',
|
|
57
|
+
}),
|
|
58
|
+
}),
|
|
59
|
+
services: [Database.Service],
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export const Play = Operation.make({
|
|
63
|
+
meta: {
|
|
64
|
+
key: 'org.dxos.function.chess.play',
|
|
65
|
+
name: 'Play',
|
|
66
|
+
description: 'Uses the chess engine to play the next move.',
|
|
67
|
+
},
|
|
68
|
+
input: Schema.Struct({
|
|
69
|
+
game: Ref.Ref(Chess.Game).annotations({
|
|
70
|
+
description: 'The ID of the chess object.',
|
|
71
|
+
}),
|
|
72
|
+
side: Schema.optional(Schema.Literal('white', 'black', 'any')).annotations({
|
|
73
|
+
description: 'The side to play.',
|
|
74
|
+
defaultValue: 'any',
|
|
75
|
+
}),
|
|
76
|
+
}),
|
|
77
|
+
output: Schema.Struct({
|
|
78
|
+
pgn: Schema.String.annotations({
|
|
79
|
+
description: 'The PGN of the game after the move was played.',
|
|
80
|
+
}),
|
|
81
|
+
move: Schema.optional(Schema.String).annotations({
|
|
82
|
+
description: 'The move that was played.',
|
|
83
|
+
}),
|
|
84
|
+
}),
|
|
85
|
+
services: [Database.Service],
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
export const Print = Operation.make({
|
|
89
|
+
meta: {
|
|
90
|
+
key: 'org.dxos.function.chess.print',
|
|
91
|
+
name: 'Print game',
|
|
92
|
+
description: 'Prints the chess game to ASCII.',
|
|
93
|
+
},
|
|
94
|
+
input: Schema.Struct({
|
|
95
|
+
pgn: Schema.optional(
|
|
96
|
+
Schema.String.annotations({
|
|
97
|
+
description: 'Portable Game Notation.',
|
|
98
|
+
}),
|
|
99
|
+
),
|
|
100
|
+
fen: Schema.optional(
|
|
101
|
+
Schema.String.annotations({
|
|
102
|
+
description: 'Forsyth-Edwards Notation.',
|
|
103
|
+
}),
|
|
104
|
+
),
|
|
105
|
+
}),
|
|
106
|
+
output: Schema.Struct({
|
|
107
|
+
ascii: Schema.String,
|
|
108
|
+
}),
|
|
109
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { OperationHandlerSet } from '@dxos/compute';
|
|
6
|
+
|
|
7
|
+
const Handlers = OperationHandlerSet.lazy(
|
|
8
|
+
() => import('./create'),
|
|
9
|
+
() => import('./move'),
|
|
10
|
+
() => import('./play'),
|
|
11
|
+
() => import('./print'),
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export { Create, Move, Play, Print } from './definitions';
|
|
15
|
+
|
|
16
|
+
export const ChessHandlers = Handlers;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Chess as ChessJS } from 'chess.js';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
|
|
8
|
+
import { Operation } from '@dxos/compute';
|
|
9
|
+
import { Database, Obj } from '@dxos/echo';
|
|
10
|
+
|
|
11
|
+
import { type Chess } from '../types';
|
|
12
|
+
import { Move } from './definitions';
|
|
13
|
+
|
|
14
|
+
const handler: Operation.WithHandler<typeof Move> = Move.pipe(
|
|
15
|
+
Operation.withHandler(
|
|
16
|
+
Effect.fn(function* ({ game, move }) {
|
|
17
|
+
const obj = (yield* Database.load(game)) as Chess.Game;
|
|
18
|
+
const chess = new ChessJS();
|
|
19
|
+
if (obj.pgn) {
|
|
20
|
+
chess.loadPgn(obj.pgn);
|
|
21
|
+
} else if (obj.fen) {
|
|
22
|
+
chess.load(obj.fen);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
chess.move(move, { strict: false });
|
|
26
|
+
const pgn = chess.pgn();
|
|
27
|
+
Obj.update(obj, (obj) => {
|
|
28
|
+
const mutableGame = obj as Obj.Mutable<typeof obj>;
|
|
29
|
+
mutableGame.pgn = pgn;
|
|
30
|
+
});
|
|
31
|
+
return { pgn };
|
|
32
|
+
}),
|
|
33
|
+
),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
export default handler;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Chess as ChessJS } from 'chess.js';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
|
|
8
|
+
import { Operation } from '@dxos/compute';
|
|
9
|
+
import { Database, Obj } from '@dxos/echo';
|
|
10
|
+
|
|
11
|
+
import { type Chess } from '../types';
|
|
12
|
+
import { Play } from './definitions';
|
|
13
|
+
|
|
14
|
+
const handler: Operation.WithHandler<typeof Play> = Play.pipe(
|
|
15
|
+
Operation.withHandler(
|
|
16
|
+
Effect.fn(function* ({ game, side = 'any' }) {
|
|
17
|
+
const object = (yield* Database.load(game)) as Chess.Game;
|
|
18
|
+
const chess = new ChessJS();
|
|
19
|
+
if (object.pgn) {
|
|
20
|
+
chess.loadPgn(object.pgn);
|
|
21
|
+
} else if (object.fen) {
|
|
22
|
+
chess.load(object.fen);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (
|
|
26
|
+
!(side === 'any' || (chess.turn() === 'w' && side === 'white') || (chess.turn() === 'b' && side === 'black'))
|
|
27
|
+
) {
|
|
28
|
+
return { move: undefined, pgn: object.pgn! };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const moves = chess.moves();
|
|
32
|
+
const move = moves[Math.floor(Math.random() * moves.length)];
|
|
33
|
+
|
|
34
|
+
chess.move(move, { strict: false });
|
|
35
|
+
const pgn = chess.pgn();
|
|
36
|
+
Obj.update(object, (object) => {
|
|
37
|
+
const mutableGame = object as Obj.Mutable<typeof object>;
|
|
38
|
+
mutableGame.pgn = pgn;
|
|
39
|
+
});
|
|
40
|
+
return { move, pgn };
|
|
41
|
+
}),
|
|
42
|
+
),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
export default handler;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Chess as ChessJS } from 'chess.js';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
|
|
8
|
+
import { Operation } from '@dxos/compute';
|
|
9
|
+
|
|
10
|
+
import { Print } from './definitions';
|
|
11
|
+
|
|
12
|
+
const handler: Operation.WithHandler<typeof Print> = Print.pipe(
|
|
13
|
+
Operation.withHandler(
|
|
14
|
+
Effect.fn(function* ({ pgn, fen }) {
|
|
15
|
+
try {
|
|
16
|
+
const chess = new ChessJS(fen);
|
|
17
|
+
if (pgn) {
|
|
18
|
+
chess.loadPgn(pgn);
|
|
19
|
+
}
|
|
20
|
+
return { ascii: chess.ascii() };
|
|
21
|
+
} catch {
|
|
22
|
+
return { ascii: '' };
|
|
23
|
+
}
|
|
24
|
+
}),
|
|
25
|
+
),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export default handler;
|
package/src/translations.ts
CHANGED
|
@@ -4,30 +4,34 @@
|
|
|
4
4
|
|
|
5
5
|
import { type Resource } from '@dxos/react-ui';
|
|
6
6
|
|
|
7
|
-
import { meta } from '
|
|
8
|
-
import { Chess } from '
|
|
7
|
+
import { meta } from '#meta';
|
|
8
|
+
import { Chess } from '#types';
|
|
9
9
|
|
|
10
10
|
export const translations = [
|
|
11
11
|
{
|
|
12
12
|
'en-US': {
|
|
13
13
|
[Chess.Game.typename]: {
|
|
14
|
-
'typename
|
|
15
|
-
'typename
|
|
16
|
-
'typename
|
|
17
|
-
'typename
|
|
18
|
-
'object
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
'
|
|
22
|
-
'
|
|
14
|
+
'typename.label': 'Game',
|
|
15
|
+
'typename.label_zero': 'Games',
|
|
16
|
+
'typename.label_one': 'Game',
|
|
17
|
+
'typename.label_other': 'Games',
|
|
18
|
+
'object-name.placeholder': 'New game',
|
|
19
|
+
'add-object.label': 'Add game',
|
|
20
|
+
'rename-object.label': 'Rename game',
|
|
21
|
+
'delete-object.label': 'Delete game',
|
|
22
|
+
'object-deleted.label': 'Game deleted',
|
|
23
23
|
},
|
|
24
24
|
[meta.id]: {
|
|
25
|
-
'plugin
|
|
26
|
-
'delete
|
|
27
|
-
'game.checkmate': 'Checkmate',
|
|
28
|
-
'game.stalemate': 'Stalemate',
|
|
29
|
-
'game.draw': 'Draw',
|
|
30
|
-
'game.check': 'Check',
|
|
25
|
+
'plugin.name': 'Chess',
|
|
26
|
+
'delete-game.label': 'Delete',
|
|
27
|
+
'game.checkmate.label': 'Checkmate',
|
|
28
|
+
'game.stalemate.label': 'Stalemate',
|
|
29
|
+
'game.draw.label': 'Draw',
|
|
30
|
+
'game.check.label': 'Check',
|
|
31
|
+
'select-player.button': 'Select player',
|
|
32
|
+
'toggle-info.button': 'Toggle info',
|
|
33
|
+
'close-info.button': 'Close info',
|
|
34
|
+
'flip-board.button': 'Flip board',
|
|
31
35
|
},
|
|
32
36
|
},
|
|
33
37
|
},
|
package/src/types/Chess.ts
CHANGED
|
@@ -3,42 +3,47 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { Chess as ChessJS } from 'chess.js';
|
|
6
|
-
import
|
|
6
|
+
import * as Schema from 'effect/Schema';
|
|
7
7
|
|
|
8
|
-
import { Obj, Type } from '@dxos/echo';
|
|
9
|
-
import { LabelAnnotation } from '@dxos/echo
|
|
8
|
+
import { Annotation, Obj, Type } from '@dxos/echo';
|
|
9
|
+
import { FormInputAnnotation, LabelAnnotation } from '@dxos/echo/internal';
|
|
10
10
|
import { log } from '@dxos/log';
|
|
11
11
|
|
|
12
12
|
export const Game = Schema.Struct({
|
|
13
13
|
name: Schema.optional(Schema.String),
|
|
14
|
-
players: Schema.
|
|
15
|
-
Schema.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}).pipe(Schema.mutable),
|
|
27
|
-
),
|
|
14
|
+
players: Schema.Struct({
|
|
15
|
+
white: Schema.optional(
|
|
16
|
+
Schema.String.annotations({
|
|
17
|
+
description: 'DID of white player',
|
|
18
|
+
}),
|
|
19
|
+
),
|
|
20
|
+
black: Schema.optional(
|
|
21
|
+
Schema.String.annotations({
|
|
22
|
+
description: 'DID of black player',
|
|
23
|
+
}),
|
|
24
|
+
),
|
|
25
|
+
}).pipe(FormInputAnnotation.set(false), Schema.optional),
|
|
28
26
|
pgn: Schema.String.annotations({
|
|
29
27
|
description: 'Portable Game Notation.',
|
|
30
|
-
}),
|
|
28
|
+
}).pipe(FormInputAnnotation.set(false), Schema.optional),
|
|
29
|
+
fen: Schema.String.annotations({
|
|
30
|
+
description: 'Forsyth-Edwards Notation.',
|
|
31
|
+
}).pipe(FormInputAnnotation.set(false), Schema.optional),
|
|
31
32
|
}).pipe(
|
|
32
|
-
Type.
|
|
33
|
-
typename: 'dxos.
|
|
34
|
-
version: '0.
|
|
33
|
+
Type.object({
|
|
34
|
+
typename: 'org.dxos.type.chess',
|
|
35
|
+
version: '0.1.0',
|
|
35
36
|
}),
|
|
36
37
|
LabelAnnotation.set(['name']),
|
|
38
|
+
Annotation.IconAnnotation.set({
|
|
39
|
+
icon: 'ph--shield-chevron--regular',
|
|
40
|
+
hue: 'amber',
|
|
41
|
+
}),
|
|
37
42
|
);
|
|
38
43
|
|
|
39
44
|
export interface Game extends Schema.Schema.Type<typeof Game> {}
|
|
40
45
|
|
|
41
|
-
export const
|
|
46
|
+
export const make = ({ name, pgn, fen }: { name?: string; pgn?: string; fen?: string } = {}) => {
|
|
42
47
|
const chess = new ChessJS();
|
|
43
48
|
if (pgn) {
|
|
44
49
|
try {
|
|
@@ -50,7 +55,8 @@ export const makeGame = ({ name, pgn }: { name?: string; pgn?: string } = {}) =>
|
|
|
50
55
|
|
|
51
56
|
return Obj.make(Game, {
|
|
52
57
|
name,
|
|
58
|
+
pgn,
|
|
59
|
+
fen,
|
|
53
60
|
players: {},
|
|
54
|
-
pgn: chess.pgn(),
|
|
55
61
|
});
|
|
56
62
|
};
|
package/src/types/index.ts
CHANGED