@dxos/plugin-chess 0.8.4-main.937b3ca → 0.8.4-main.9be5663bfe
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 +9 -6
- package/dist/lib/browser/{chunk-7OZ7J7LF.mjs → chunk-2TJN26DN.mjs} +10 -7
- package/dist/lib/browser/chunk-2TJN26DN.mjs.map +7 -0
- package/dist/lib/browser/chunk-JZMN24DY.mjs +28 -0
- package/dist/lib/browser/chunk-JZMN24DY.mjs.map +7 -0
- package/dist/lib/browser/chunk-MC7L6JNC.mjs +36 -0
- package/dist/lib/browser/chunk-MC7L6JNC.mjs.map +7 -0
- package/dist/lib/browser/chunk-XAJZK6Z2.mjs +110 -0
- package/dist/lib/browser/chunk-XAJZK6Z2.mjs.map +7 -0
- package/dist/lib/browser/cli/index.mjs +21 -15
- package/dist/lib/browser/cli/index.mjs.map +3 -3
- package/dist/lib/browser/create-AJHN4QT4.mjs +24 -0
- package/dist/lib/browser/create-AJHN4QT4.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +351 -61
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/move-T2NLRBR4.mjs +36 -0
- package/dist/lib/browser/move-T2NLRBR4.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-7VTMD3SJ.mjs +45 -0
- package/dist/lib/browser/play-7VTMD3SJ.mjs.map +7 -0
- package/dist/lib/browser/print-EW7LPW4D.mjs +30 -0
- package/dist/lib/browser/print-EW7LPW4D.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +1 -1
- package/dist/lib/node-esm/blueprints/index.mjs +9 -6
- package/dist/lib/node-esm/chunk-4HZWCKMR.mjs +38 -0
- package/dist/lib/node-esm/chunk-4HZWCKMR.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-LQEDIKCV.mjs +29 -0
- package/dist/lib/node-esm/chunk-LQEDIKCV.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-NYU5JVXP.mjs +111 -0
- package/dist/lib/node-esm/chunk-NYU5JVXP.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-NAYRVJR4.mjs → chunk-OIRJVY2R.mjs} +10 -7
- package/dist/lib/node-esm/chunk-OIRJVY2R.mjs.map +7 -0
- package/dist/lib/node-esm/cli/index.mjs +21 -15
- package/dist/lib/node-esm/cli/index.mjs.map +3 -3
- package/dist/lib/node-esm/create-QSETDT4N.mjs +25 -0
- package/dist/lib/node-esm/create-QSETDT4N.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +351 -61
- 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-5F2ANDTE.mjs +37 -0
- package/dist/lib/node-esm/move-5F2ANDTE.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-W4DQCQRX.mjs +46 -0
- package/dist/lib/node-esm/play-W4DQCQRX.mjs.map +7 -0
- package/dist/lib/node-esm/print-UJHXAXMS.mjs +31 -0
- package/dist/lib/node-esm/print-UJHXAXMS.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +1 -1
- package/dist/types/src/ChessPlugin.d.ts.map +1 -1
- package/dist/types/src/blueprints/chess-blueprint.d.ts +3 -20
- package/dist/types/src/blueprints/chess-blueprint.d.ts.map +1 -1
- package/dist/types/src/blueprints/index.d.ts +2 -2
- package/dist/types/src/blueprints/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/{artifact-definition/artifact-definition.d.ts → artifact-definition.d.ts} +1 -1
- package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -0
- package/dist/types/src/capabilities/blueprint-definition.d.ts +6 -0
- package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +5 -2
- 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 +5 -0
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
- package/dist/types/src/cli/plugin.d.ts.map +1 -1
- package/dist/types/src/components/{Chessboard.d.ts → Chessboard/Chessboard.d.ts} +4 -9
- package/dist/types/src/components/Chessboard/Chessboard.d.ts.map +1 -0
- package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts +48 -0
- package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts.map +1 -0
- package/dist/types/src/components/{Info.d.ts → Chessboard/Info.d.ts} +1 -1
- 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 +47 -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/{components/Card.stories.d.ts → containers/ChessCard/ChessCard.stories.d.ts} +1 -1
- 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 -2
- package/dist/types/src/index.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 +21 -20
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Chess.d.ts +5 -5
- package/dist/types/src/types/Chess.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +60 -44
- package/src/ChessPlugin.tsx +30 -15
- package/src/blueprints/chess-blueprint.ts +14 -7
- package/src/blueprints/index.ts +2 -2
- package/src/capabilities/{artifact-definition/artifact-definition.ts → artifact-definition.ts} +5 -5
- package/src/capabilities/blueprint-definition.ts +17 -0
- package/src/capabilities/index.ts +9 -2
- package/src/capabilities/operation-handler.ts +14 -0
- package/src/capabilities/react-surface.tsx +35 -0
- package/src/cli/plugin.ts +18 -7
- package/src/components/Chessboard/Chessboard.stories.tsx +94 -0
- package/src/components/{Chessboard.tsx → Chessboard/Chessboard.tsx} +22 -30
- package/src/components/{Info.tsx → Chessboard/Info.tsx} +32 -19
- 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/{components/Chessboard.stories.tsx → containers/ChessArticle/ChessArticle.stories.tsx} +9 -9
- package/src/containers/ChessArticle/ChessArticle.tsx +73 -0
- package/src/containers/ChessArticle/index.ts +5 -0
- package/src/{components/Card.stories.tsx → containers/ChessCard/ChessCard.stories.tsx} +9 -14
- 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 -2
- package/src/meta.ts +1 -1
- 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 -20
- package/src/types/Chess.ts +8 -4
- package/dist/lib/browser/ChessboardContainer-IS4PXWJD.mjs +0 -81
- package/dist/lib/browser/ChessboardContainer-IS4PXWJD.mjs.map +0 -7
- package/dist/lib/browser/blueprint-definition-5RUGJ64Z.mjs +0 -18
- package/dist/lib/browser/blueprint-definition-5RUGJ64Z.mjs.map +0 -7
- package/dist/lib/browser/chunk-7OZ7J7LF.mjs.map +0 -7
- package/dist/lib/browser/chunk-DH4WQRZH.mjs +0 -229
- package/dist/lib/browser/chunk-DH4WQRZH.mjs.map +0 -7
- package/dist/lib/browser/chunk-H3NUMCQ6.mjs +0 -21
- package/dist/lib/browser/chunk-H3NUMCQ6.mjs.map +0 -7
- package/dist/lib/browser/chunk-MV2GQK7M.mjs +0 -8
- package/dist/lib/browser/chunk-MV2GQK7M.mjs.map +0 -7
- package/dist/lib/browser/chunk-UUMPZ2FM.mjs +0 -271
- package/dist/lib/browser/chunk-UUMPZ2FM.mjs.map +0 -7
- package/dist/lib/browser/react-surface-GQE7XMWH.mjs +0 -37
- package/dist/lib/browser/react-surface-GQE7XMWH.mjs.map +0 -7
- package/dist/lib/node-esm/ChessboardContainer-S3T6OE7P.mjs +0 -82
- package/dist/lib/node-esm/ChessboardContainer-S3T6OE7P.mjs.map +0 -7
- package/dist/lib/node-esm/blueprint-definition-RYKASBIJ.mjs +0 -19
- package/dist/lib/node-esm/blueprint-definition-RYKASBIJ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-DOBR6ILE.mjs +0 -10
- package/dist/lib/node-esm/chunk-DOBR6ILE.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-F5OMIM4F.mjs +0 -23
- package/dist/lib/node-esm/chunk-F5OMIM4F.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-LKJ5GDAB.mjs +0 -272
- package/dist/lib/node-esm/chunk-LKJ5GDAB.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NAYRVJR4.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NFDJU7XQ.mjs +0 -230
- package/dist/lib/node-esm/chunk-NFDJU7XQ.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-7UZLIVN6.mjs +0 -38
- package/dist/lib/node-esm/react-surface-7UZLIVN6.mjs.map +0 -7
- package/dist/types/src/blueprints/functions/create.d.ts +0 -15
- package/dist/types/src/blueprints/functions/create.d.ts.map +0 -1
- package/dist/types/src/blueprints/functions/index.d.ts +0 -5
- package/dist/types/src/blueprints/functions/index.d.ts.map +0 -1
- package/dist/types/src/blueprints/functions/move.d.ts +0 -8
- package/dist/types/src/blueprints/functions/move.d.ts.map +0 -1
- package/dist/types/src/blueprints/functions/play.d.ts +0 -9
- package/dist/types/src/blueprints/functions/play.d.ts.map +0 -1
- package/dist/types/src/blueprints/functions/print.d.ts +0 -8
- package/dist/types/src/blueprints/functions/print.d.ts.map +0 -1
- package/dist/types/src/capabilities/artifact-definition/artifact-definition.d.ts.map +0 -1
- package/dist/types/src/capabilities/artifact-definition/index.d.ts +0 -3
- package/dist/types/src/capabilities/artifact-definition/index.d.ts.map +0 -1
- package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts +0 -9
- package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts.map +0 -1
- package/dist/types/src/capabilities/blueprint-definition/index.d.ts +0 -3
- package/dist/types/src/capabilities/blueprint-definition/index.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-surface/index.d.ts +0 -3
- package/dist/types/src/capabilities/react-surface/index.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts +0 -5
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +0 -1
- package/dist/types/src/components/Card.stories.d.ts.map +0 -1
- package/dist/types/src/components/Chessboard.d.ts.map +0 -1
- package/dist/types/src/components/Chessboard.stories.d.ts +0 -46
- 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 -7
- package/dist/types/src/components/ChessboardContainer.d.ts.map +0 -1
- package/dist/types/src/components/Info.d.ts.map +0 -1
- package/src/blueprints/functions/create.ts +0 -38
- package/src/blueprints/functions/index.ts +0 -8
- package/src/blueprints/functions/move.ts +0 -49
- package/src/blueprints/functions/play.ts +0 -59
- package/src/blueprints/functions/print.ts +0 -42
- package/src/capabilities/artifact-definition/index.ts +0 -7
- package/src/capabilities/blueprint-definition/blueprint-definition.ts +0 -23
- package/src/capabilities/blueprint-definition/index.ts +0 -7
- package/src/capabilities/react-surface/index.ts +0 -7
- package/src/capabilities/react-surface/react-surface.tsx +0 -27
- package/src/components/ChessboardArticle.tsx +0 -71
- package/src/components/ChessboardContainer.tsx +0 -40
|
@@ -12,9 +12,11 @@ import { Icon, IconButton, Select, type ThemedClassName, useTranslation } from '
|
|
|
12
12
|
import { type Player, useGameboardContext } from '@dxos/react-ui-gameboard';
|
|
13
13
|
import { mx } from '@dxos/ui-theme';
|
|
14
14
|
|
|
15
|
-
import { meta } from '
|
|
15
|
+
import { meta } from '#meta';
|
|
16
16
|
|
|
17
|
-
import { type ExtendedChessModel } from './
|
|
17
|
+
import { type ExtendedChessModel } from './types';
|
|
18
|
+
|
|
19
|
+
const INFO_NAME = 'Chessboard.Info';
|
|
18
20
|
|
|
19
21
|
export type InfoProps = ThemedClassName<
|
|
20
22
|
{
|
|
@@ -26,14 +28,14 @@ export type InfoProps = ThemedClassName<
|
|
|
26
28
|
|
|
27
29
|
export const Info = ({ classNames, orientation = 'white', onOrientationChange, onClose, ...props }: InfoProps) => {
|
|
28
30
|
const { t } = useTranslation(meta.id);
|
|
29
|
-
const { model } = useGameboardContext<ExtendedChessModel>(
|
|
31
|
+
const { model } = useGameboardContext<ExtendedChessModel>(INFO_NAME);
|
|
30
32
|
const db = Obj.getDatabase(model.object);
|
|
31
33
|
const members = useMembers(db?.spaceId);
|
|
32
34
|
|
|
33
35
|
return (
|
|
34
36
|
<div
|
|
35
37
|
className={mx(
|
|
36
|
-
'grid grid-rows-[min-content_1fr_min-content]
|
|
38
|
+
'grid grid-rows-[min-content_1fr_min-content] w-full min-w-[18rem] p-2 overflow-hidden bg-group-surface rounded-xs',
|
|
37
39
|
classNames,
|
|
38
40
|
)}
|
|
39
41
|
>
|
|
@@ -42,14 +44,23 @@ export const Info = ({ classNames, orientation = 'white', onOrientationChange, o
|
|
|
42
44
|
player={orientation === 'white' ? 'black' : 'white'}
|
|
43
45
|
icon={
|
|
44
46
|
onClose && (
|
|
45
|
-
<IconButton
|
|
47
|
+
<IconButton
|
|
48
|
+
variant='ghost'
|
|
49
|
+
icon='ph--x--regular'
|
|
50
|
+
iconOnly
|
|
51
|
+
label={t('close-info.button')}
|
|
52
|
+
size={4}
|
|
53
|
+
onClick={onClose}
|
|
54
|
+
/>
|
|
46
55
|
)
|
|
47
56
|
}
|
|
48
57
|
>
|
|
49
58
|
<PlayerSelector
|
|
50
59
|
value={model.object.players?.[orientation === 'white' ? 'black' : 'white']}
|
|
51
60
|
onValueChange={(value) => {
|
|
52
|
-
model.object
|
|
61
|
+
Obj.change(model.object, (obj) => {
|
|
62
|
+
obj.players![orientation === 'white' ? 'black' : 'white'] = value;
|
|
63
|
+
});
|
|
53
64
|
}}
|
|
54
65
|
members={members}
|
|
55
66
|
/>
|
|
@@ -66,7 +77,7 @@ export const Info = ({ classNames, orientation = 'white', onOrientationChange, o
|
|
|
66
77
|
classNames={mx('transition duration-200 ease-linear', orientation === 'white' && 'rotate-180')}
|
|
67
78
|
icon='ph--arrows-clockwise--regular'
|
|
68
79
|
iconOnly
|
|
69
|
-
label={t('flip
|
|
80
|
+
label={t('flip-board.button')}
|
|
70
81
|
size={4}
|
|
71
82
|
onClick={() => onOrientationChange(orientation === 'white' ? 'black' : 'white')}
|
|
72
83
|
/>
|
|
@@ -76,7 +87,9 @@ export const Info = ({ classNames, orientation = 'white', onOrientationChange, o
|
|
|
76
87
|
<PlayerSelector
|
|
77
88
|
value={model.object.players?.[orientation]}
|
|
78
89
|
onValueChange={(value) => {
|
|
79
|
-
model.object
|
|
90
|
+
Obj.change(model.object, (obj) => {
|
|
91
|
+
obj.players![orientation] = value;
|
|
92
|
+
});
|
|
80
93
|
}}
|
|
81
94
|
members={members}
|
|
82
95
|
/>
|
|
@@ -85,7 +98,7 @@ export const Info = ({ classNames, orientation = 'white', onOrientationChange, o
|
|
|
85
98
|
);
|
|
86
99
|
};
|
|
87
100
|
|
|
88
|
-
Info.displayName =
|
|
101
|
+
Info.displayName = INFO_NAME;
|
|
89
102
|
|
|
90
103
|
//
|
|
91
104
|
// History
|
|
@@ -103,12 +116,12 @@ const History = ({ classNames, model, min, max, onSelect }: HistoryProps) => {
|
|
|
103
116
|
const moveIndex = useAtomValue(model.moveIndex);
|
|
104
117
|
const label = model.game.isGameOver()
|
|
105
118
|
? model.game.isCheckmate()
|
|
106
|
-
? t('game.checkmate
|
|
119
|
+
? t('game.checkmate.label')
|
|
107
120
|
: model.game.isStalemate()
|
|
108
|
-
? t('game.stalemate
|
|
109
|
-
: t('game.draw
|
|
121
|
+
? t('game.stalemate.label')
|
|
122
|
+
: t('game.draw.label')
|
|
110
123
|
: model.game.isCheck()
|
|
111
|
-
? t('game.check
|
|
124
|
+
? t('game.check.label')
|
|
112
125
|
: undefined;
|
|
113
126
|
|
|
114
127
|
const history = model.game.history();
|
|
@@ -150,12 +163,12 @@ const History = ({ classNames, model, min, max, onSelect }: HistoryProps) => {
|
|
|
150
163
|
}}
|
|
151
164
|
>
|
|
152
165
|
{moves.map(([a, b], index) => (
|
|
153
|
-
<div key={index} className='grid grid-cols-[3rem_1fr_1fr_1rem] gap-2
|
|
166
|
+
<div key={index} className='grid grid-cols-[3rem_1fr_1fr_1rem] gap-2 ps-4'>
|
|
154
167
|
<div className='content-center text-xs text-subdued'>{index + 1}</div>
|
|
155
168
|
{a && (
|
|
156
169
|
<div
|
|
157
170
|
data-index={a.index}
|
|
158
|
-
className={mx('
|
|
171
|
+
className={mx('ps-2 text-sm cursor-pointer', a.index === moveIndex - 1 && 'bg-primary-500')}
|
|
159
172
|
onClick={() => onSelect?.(a.index + 1)}
|
|
160
173
|
>
|
|
161
174
|
{a.move}
|
|
@@ -164,7 +177,7 @@ const History = ({ classNames, model, min, max, onSelect }: HistoryProps) => {
|
|
|
164
177
|
{b && (
|
|
165
178
|
<div
|
|
166
179
|
data-index={b.index}
|
|
167
|
-
className={mx('
|
|
180
|
+
className={mx('ps-2 text-sm cursor-pointer', b.index === moveIndex - 1 && 'bg-primary-500')}
|
|
168
181
|
onClick={() => onSelect?.(b.index + 1)}
|
|
169
182
|
>
|
|
170
183
|
{b.move}
|
|
@@ -190,12 +203,12 @@ type PlayerIndicatorProps = PropsWithChildren<{
|
|
|
190
203
|
const PlayerIndicator = ({ children, model, player, icon }: PlayerIndicatorProps) => {
|
|
191
204
|
const turn = player === (model.game.turn() === 'w' ? 'white' : 'black');
|
|
192
205
|
return (
|
|
193
|
-
<div className='grid grid-cols-[2rem_1fr_2rem] gap-2
|
|
206
|
+
<div className='grid grid-cols-[2rem_1fr_2rem] gap-2 h-(--dx-rail-size) px-1 flex items-center overflow-hidden'>
|
|
194
207
|
<div className='place-items-center'>
|
|
195
208
|
<Icon
|
|
196
209
|
icon={turn ? 'ph--circle--fill' : 'ph--circle--thin'}
|
|
197
210
|
size={6}
|
|
198
|
-
classNames={mx(turn && (model.game.isCheckmate() ? 'text-
|
|
211
|
+
classNames={mx(turn && (model.game.isCheckmate() ? 'text-error-500' : 'text-success-text'))}
|
|
199
212
|
/>
|
|
200
213
|
</div>
|
|
201
214
|
<div className='truncate overflow-hidden items-center'>{children}</div>
|
|
@@ -218,7 +231,7 @@ const PlayerSelector = ({ value, onValueChange, members }: PlayerSelectorProps)
|
|
|
218
231
|
const { t } = useTranslation(meta.id);
|
|
219
232
|
return (
|
|
220
233
|
<Select.Root value={value} onValueChange={onValueChange}>
|
|
221
|
-
<Select.TriggerButton placeholder={t('select
|
|
234
|
+
<Select.TriggerButton placeholder={t('select-player.button')} />
|
|
222
235
|
<Select.Portal>
|
|
223
236
|
<Select.Content>
|
|
224
237
|
<Select.Viewport>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Registry } from '@effect-atom/atom-react';
|
|
6
|
+
|
|
7
|
+
import { ChessModel } from '@dxos/react-ui-gameboard';
|
|
8
|
+
|
|
9
|
+
import { type Chess } from '#types';
|
|
10
|
+
|
|
11
|
+
export class ExtendedChessModel extends ChessModel {
|
|
12
|
+
constructor(
|
|
13
|
+
registry: Registry.Registry,
|
|
14
|
+
readonly object: Chess.Game,
|
|
15
|
+
) {
|
|
16
|
+
super(registry);
|
|
17
|
+
}
|
|
18
|
+
}
|
package/src/components/index.ts
CHANGED
package/src/{components/Chessboard.stories.tsx → containers/ChessArticle/ChessArticle.stories.tsx}
RENAMED
|
@@ -6,26 +6,26 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
|
6
6
|
import React, { useMemo } from 'react';
|
|
7
7
|
|
|
8
8
|
import { withClientProvider } from '@dxos/react-client/testing';
|
|
9
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
9
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
10
10
|
|
|
11
|
-
import {
|
|
12
|
-
import { Chess } from '../types';
|
|
11
|
+
import { Chess } from '#types';
|
|
13
12
|
|
|
14
|
-
import {
|
|
13
|
+
import { translations } from '../../translations';
|
|
14
|
+
import { ChessArticle } from './ChessArticle';
|
|
15
15
|
|
|
16
|
-
type
|
|
16
|
+
type DefaultStoryProps = {
|
|
17
17
|
pgn?: string;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
const DefaultStory = ({ pgn }:
|
|
20
|
+
const DefaultStory = ({ pgn }: DefaultStoryProps) => {
|
|
21
21
|
const game = useMemo(() => Chess.make(pgn ? { pgn } : undefined), [pgn]);
|
|
22
|
-
return <
|
|
22
|
+
return <ChessArticle role='article' subject={game} attendableId='story' />;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
const meta = {
|
|
26
|
-
title: 'plugins/plugin-chess/
|
|
26
|
+
title: 'plugins/plugin-chess/containers/ChessArticle',
|
|
27
27
|
component: DefaultStory,
|
|
28
|
-
decorators: [withTheme, withClientProvider({ createIdentity: true })],
|
|
28
|
+
decorators: [withTheme(), withLayout({ layout: 'fullscreen' }), withClientProvider({ createIdentity: true })],
|
|
29
29
|
parameters: {
|
|
30
30
|
layout: 'fullscreen',
|
|
31
31
|
translations,
|
|
@@ -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
|
+
};
|
|
@@ -5,37 +5,32 @@
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
6
|
import React, { useMemo } from 'react';
|
|
7
7
|
|
|
8
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
9
8
|
import { CardContainer } from '@dxos/react-ui-mosaic/testing';
|
|
9
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
10
10
|
|
|
11
|
-
import { meta as pluginMeta } from '
|
|
12
|
-
import { Chess } from '
|
|
11
|
+
import { meta as pluginMeta } from '#meta';
|
|
12
|
+
import { Chess } from '#types';
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import { ChessCard } from './ChessCard';
|
|
15
15
|
|
|
16
16
|
const SAMPLE_PGN =
|
|
17
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
18
|
|
|
19
|
-
// TODO(wittjosiah): ECHO objects don't work when passed via Storybook args.
|
|
20
19
|
const CardStory = () => {
|
|
21
20
|
const game = useMemo(() => Chess.make({ pgn: SAMPLE_PGN }), []);
|
|
22
21
|
return (
|
|
23
|
-
<CardContainer icon={pluginMeta.icon}>
|
|
24
|
-
<
|
|
25
|
-
<Chessboard.Content>
|
|
26
|
-
<Chessboard.Board />
|
|
27
|
-
</Chessboard.Content>
|
|
28
|
-
</Chessboard.Root>
|
|
22
|
+
<CardContainer role='popover' icon={pluginMeta.icon}>
|
|
23
|
+
<ChessCard subject={game} role='card--content' />
|
|
29
24
|
</CardContainer>
|
|
30
25
|
);
|
|
31
26
|
};
|
|
32
27
|
|
|
33
28
|
const meta = {
|
|
34
|
-
title: 'plugins/plugin-chess/
|
|
29
|
+
title: 'plugins/plugin-chess/containers/ChessCard',
|
|
35
30
|
render: () => <CardStory />,
|
|
36
|
-
decorators: [withTheme],
|
|
31
|
+
decorators: [withTheme(), withLayout({ layout: 'column' })],
|
|
37
32
|
parameters: {
|
|
38
|
-
layout: '
|
|
33
|
+
layout: 'fullscreen',
|
|
39
34
|
},
|
|
40
35
|
tags: ['cards'],
|
|
41
36
|
} satisfies Meta;
|
|
@@ -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
package/src/meta.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { type Plugin } from '@dxos/app-framework';
|
|
|
6
6
|
import { trim } from '@dxos/util';
|
|
7
7
|
|
|
8
8
|
export const meta: Plugin.Meta = {
|
|
9
|
-
id: 'dxos.
|
|
9
|
+
id: 'org.dxos.plugin.chess',
|
|
10
10
|
name: 'Chess',
|
|
11
11
|
description: trim`
|
|
12
12
|
Full-featured chess game supporting multiplayer matches with friends or practice sessions against AI opponents.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import { Database } from '@dxos/echo';
|
|
8
|
+
import { Operation } from '@dxos/operation';
|
|
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 { Database, Ref } from '@dxos/echo';
|
|
8
|
+
import { Operation } from '@dxos/operation';
|
|
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/operation';
|
|
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 { Database, Obj } from '@dxos/echo';
|
|
9
|
+
import { Operation } from '@dxos/operation';
|
|
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.change(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 { Database, Obj } from '@dxos/echo';
|
|
9
|
+
import { Operation } from '@dxos/operation';
|
|
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.change(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/operation';
|
|
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;
|