@dxos/plugin-chess 0.8.4-main.69d29f4 → 0.8.4-main.6fa680abb7
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/ChessArticle-UDSL3OJ4.mjs +59 -0
- package/dist/lib/browser/ChessArticle-UDSL3OJ4.mjs.map +7 -0
- package/dist/lib/browser/ChessCard-OIRFQMOJ.mjs +21 -0
- package/dist/lib/browser/ChessCard-OIRFQMOJ.mjs.map +7 -0
- package/dist/lib/browser/blueprint-definition-LWRZPLQL.mjs +18 -0
- package/dist/lib/browser/blueprint-definition-LWRZPLQL.mjs.map +7 -0
- package/dist/lib/browser/blueprints/index.mjs +4 -4
- package/dist/lib/browser/{chunk-73BDP7UV.mjs → chunk-JP6G6VR6.mjs} +30 -29
- package/dist/lib/browser/chunk-JP6G6VR6.mjs.map +7 -0
- package/dist/lib/browser/{chunk-H3NUMCQ6.mjs → chunk-RGHZ5CDO.mjs} +2 -2
- package/dist/lib/browser/{chunk-H3NUMCQ6.mjs.map → chunk-RGHZ5CDO.mjs.map} +1 -1
- package/dist/lib/browser/{chunk-FO4ZNFN6.mjs → chunk-VK2W2UDJ.mjs} +44 -42
- package/dist/lib/browser/chunk-VK2W2UDJ.mjs.map +7 -0
- package/dist/lib/browser/chunk-WYUTI2K4.mjs +1 -0
- package/dist/lib/browser/chunk-WYUTI2K4.mjs.map +7 -0
- package/dist/lib/browser/{chunk-66H3V2YV.mjs → chunk-YJ2NLHEY.mjs} +3 -3
- package/dist/lib/browser/{chunk-66H3V2YV.mjs.map → chunk-YJ2NLHEY.mjs.map} +1 -1
- package/dist/lib/browser/cli/index.mjs +10 -10
- package/dist/lib/browser/cli/index.mjs.map +3 -3
- package/dist/lib/browser/index.mjs +21 -26
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/react-surface-M7QMAFTB.mjs +50 -0
- package/dist/lib/browser/react-surface-M7QMAFTB.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +1 -1
- package/dist/lib/node-esm/ChessArticle-76MOXLJM.mjs +60 -0
- package/dist/lib/node-esm/ChessArticle-76MOXLJM.mjs.map +7 -0
- package/dist/lib/node-esm/ChessCard-TKNQP6IO.mjs +22 -0
- package/dist/lib/node-esm/ChessCard-TKNQP6IO.mjs.map +7 -0
- package/dist/lib/node-esm/{blueprint-definition-SL4LBVV5.mjs → blueprint-definition-CJZXRDEQ.mjs} +7 -7
- package/dist/lib/node-esm/blueprint-definition-CJZXRDEQ.mjs.map +7 -0
- package/dist/lib/node-esm/blueprints/index.mjs +4 -4
- package/dist/lib/node-esm/chunk-7XDEO6IJ.mjs +2 -0
- package/dist/lib/node-esm/chunk-7XDEO6IJ.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-WXEPWOHT.mjs → chunk-FK7NVSOG.mjs} +30 -29
- package/dist/lib/node-esm/chunk-FK7NVSOG.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-F5OMIM4F.mjs → chunk-FYPVCMP4.mjs} +2 -2
- package/dist/lib/node-esm/{chunk-F5OMIM4F.mjs.map → chunk-FYPVCMP4.mjs.map} +1 -1
- package/dist/lib/node-esm/{chunk-C7IWIXCJ.mjs → chunk-G3QQRYZC.mjs} +44 -42
- package/dist/lib/node-esm/chunk-G3QQRYZC.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-OUNGNJFP.mjs → chunk-J6AJLY2O.mjs} +3 -3
- package/dist/lib/node-esm/{chunk-OUNGNJFP.mjs.map → chunk-J6AJLY2O.mjs.map} +1 -1
- package/dist/lib/node-esm/cli/index.mjs +10 -10
- package/dist/lib/node-esm/cli/index.mjs.map +3 -3
- package/dist/lib/node-esm/index.mjs +21 -26
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/react-surface-DKM6ICBU.mjs +51 -0
- package/dist/lib/node-esm/react-surface-DKM6ICBU.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/functions/create.d.ts +1 -1
- package/dist/types/src/blueprints/functions/index.d.ts +55 -4
- package/dist/types/src/blueprints/functions/index.d.ts.map +1 -1
- package/dist/types/src/blueprints/functions/move.d.ts +9 -1
- package/dist/types/src/blueprints/functions/move.d.ts.map +1 -1
- package/dist/types/src/blueprints/functions/play.d.ts +9 -1
- package/dist/types/src/blueprints/functions/play.d.ts.map +1 -1
- package/dist/types/src/blueprints/index.d.ts +1 -1
- package/dist/types/src/blueprints/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/artifact-definition/artifact-definition.d.ts +1 -1
- package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts +3 -6
- package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts.map +1 -1
- package/dist/types/src/capabilities/blueprint-definition/index.d.ts +1 -1
- package/dist/types/src/capabilities/blueprint-definition/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface/index.d.ts +1 -1
- package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts +2 -2
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -1
- package/dist/types/src/cli/plugin.d.ts.map +1 -1
- package/dist/types/src/components/{Chessboard.d.ts → Chessboard/Chessboard.d.ts} +3 -8
- package/dist/types/src/components/Chessboard/Chessboard.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/{components/Chessboard.stories.d.ts → containers/ChessArticle/ChessArticle.stories.d.ts} +3 -2
- package/dist/types/src/containers/ChessArticle/ChessArticle.stories.d.ts.map +1 -0
- package/dist/types/src/containers/ChessArticle/index.d.ts +3 -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 +3 -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 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +1 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Chess.d.ts +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +45 -44
- package/src/ChessPlugin.tsx +8 -8
- package/src/blueprints/chess-blueprint.ts +14 -6
- package/src/blueprints/functions/create.ts +2 -2
- package/src/blueprints/functions/index.ts +13 -4
- package/src/blueprints/functions/move.ts +11 -12
- package/src/blueprints/functions/play.ts +5 -6
- package/src/blueprints/functions/print.ts +1 -1
- package/src/blueprints/index.ts +1 -1
- package/src/capabilities/blueprint-definition/blueprint-definition.ts +6 -12
- package/src/capabilities/react-surface/react-surface.tsx +13 -7
- package/src/cli/plugin.ts +4 -4
- package/src/components/{Chessboard.tsx → Chessboard/Chessboard.tsx} +24 -26
- package/src/components/{Info.tsx → Chessboard/Info.tsx} +12 -10
- 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} +7 -7
- package/src/containers/ChessArticle/ChessArticle.tsx +72 -0
- package/src/containers/ChessArticle/index.ts +7 -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 +7 -0
- package/src/containers/index.ts +8 -0
- package/src/index.ts +1 -1
- package/src/meta.ts +1 -1
- package/src/translations.ts +1 -0
- package/src/types/Chess.ts +2 -2
- package/dist/lib/browser/ChessboardContainer-JZ4ANG4O.mjs +0 -81
- package/dist/lib/browser/ChessboardContainer-JZ4ANG4O.mjs.map +0 -7
- package/dist/lib/browser/blueprint-definition-P7TYXWMF.mjs +0 -18
- package/dist/lib/browser/blueprint-definition-P7TYXWMF.mjs.map +0 -7
- package/dist/lib/browser/chunk-73BDP7UV.mjs.map +0 -7
- package/dist/lib/browser/chunk-FO4ZNFN6.mjs.map +0 -7
- package/dist/lib/browser/chunk-OW6S2SRG.mjs +0 -8
- package/dist/lib/browser/chunk-OW6S2SRG.mjs.map +0 -7
- package/dist/lib/browser/react-surface-VNOWFKC6.mjs +0 -37
- package/dist/lib/browser/react-surface-VNOWFKC6.mjs.map +0 -7
- package/dist/lib/node-esm/ChessboardContainer-7ONFYN7L.mjs +0 -82
- package/dist/lib/node-esm/ChessboardContainer-7ONFYN7L.mjs.map +0 -7
- package/dist/lib/node-esm/blueprint-definition-SL4LBVV5.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-24GJHLHM.mjs +0 -10
- package/dist/lib/node-esm/chunk-24GJHLHM.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-C7IWIXCJ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-WXEPWOHT.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-HSHCIOAS.mjs +0 -38
- package/dist/lib/node-esm/react-surface-HSHCIOAS.mjs.map +0 -7
- 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.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/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
|
>
|
|
@@ -89,7 +91,7 @@ export const Info = ({ classNames, orientation = 'white', onOrientationChange, o
|
|
|
89
91
|
);
|
|
90
92
|
};
|
|
91
93
|
|
|
92
|
-
Info.displayName =
|
|
94
|
+
Info.displayName = INFO_NAME;
|
|
93
95
|
|
|
94
96
|
//
|
|
95
97
|
// History
|
|
@@ -154,12 +156,12 @@ const History = ({ classNames, model, min, max, onSelect }: HistoryProps) => {
|
|
|
154
156
|
}}
|
|
155
157
|
>
|
|
156
158
|
{moves.map(([a, b], index) => (
|
|
157
|
-
<div key={index} className='grid grid-cols-[3rem_1fr_1fr_1rem] gap-2
|
|
159
|
+
<div key={index} className='grid grid-cols-[3rem_1fr_1fr_1rem] gap-2 ps-4 leading-1'>
|
|
158
160
|
<div className='content-center text-xs text-subdued'>{index + 1}</div>
|
|
159
161
|
{a && (
|
|
160
162
|
<div
|
|
161
163
|
data-index={a.index}
|
|
162
|
-
className={mx('
|
|
164
|
+
className={mx('ps-2 cursor-pointer', a.index === moveIndex - 1 && 'bg-primary-500')}
|
|
163
165
|
onClick={() => onSelect?.(a.index + 1)}
|
|
164
166
|
>
|
|
165
167
|
{a.move}
|
|
@@ -168,7 +170,7 @@ const History = ({ classNames, model, min, max, onSelect }: HistoryProps) => {
|
|
|
168
170
|
{b && (
|
|
169
171
|
<div
|
|
170
172
|
data-index={b.index}
|
|
171
|
-
className={mx('
|
|
173
|
+
className={mx('ps-2 cursor-pointer', b.index === moveIndex - 1 && 'bg-primary-500')}
|
|
172
174
|
onClick={() => onSelect?.(b.index + 1)}
|
|
173
175
|
>
|
|
174
176
|
{b.move}
|
|
@@ -194,12 +196,12 @@ type PlayerIndicatorProps = PropsWithChildren<{
|
|
|
194
196
|
const PlayerIndicator = ({ children, model, player, icon }: PlayerIndicatorProps) => {
|
|
195
197
|
const turn = player === (model.game.turn() === 'w' ? 'white' : 'black');
|
|
196
198
|
return (
|
|
197
|
-
<div className='grid grid-cols-[2rem_1fr_2rem] gap-2
|
|
199
|
+
<div className='grid grid-cols-[2rem_1fr_2rem] gap-2 h-(--dx-rail-size) px-1 flex items-center overflow-hidden'>
|
|
198
200
|
<div className='place-items-center'>
|
|
199
201
|
<Icon
|
|
200
202
|
icon={turn ? 'ph--circle--fill' : 'ph--circle--thin'}
|
|
201
203
|
size={6}
|
|
202
|
-
classNames={mx(turn && (model.game.isCheckmate() ? 'text-
|
|
204
|
+
classNames={mx(turn && (model.game.isCheckmate() ? 'text-error-500' : 'text-success-text'))}
|
|
203
205
|
/>
|
|
204
206
|
</div>
|
|
205
207
|
<div className='truncate overflow-hidden items-center'>{children}</div>
|
|
@@ -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,12 +6,12 @@ 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 { translations } from '
|
|
12
|
-
import { Chess } from '
|
|
11
|
+
import { translations } from '../../translations';
|
|
12
|
+
import { Chess } from '../../types';
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import { ChessArticle } from './ChessArticle';
|
|
15
15
|
|
|
16
16
|
type StoryProps = {
|
|
17
17
|
pgn?: string;
|
|
@@ -19,13 +19,13 @@ type StoryProps = {
|
|
|
19
19
|
|
|
20
20
|
const DefaultStory = ({ pgn }: StoryProps) => {
|
|
21
21
|
const game = useMemo(() => Chess.make(pgn ? { pgn } : undefined), [pgn]);
|
|
22
|
-
return <
|
|
22
|
+
return <ChessArticle subject={game} />;
|
|
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,72 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { useCallback, useRef, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { type SurfaceComponentProps } 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 = SurfaceComponentProps<Chess.Game>;
|
|
17
|
+
|
|
18
|
+
export const ChessArticle = ({ role, subject: game }: ChessArticleProps) => {
|
|
19
|
+
const { t } = useTranslation(meta.id);
|
|
20
|
+
const [orientation, setOrientation] = useState<Player>('white');
|
|
21
|
+
const [open, setOpen] = 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={open}
|
|
38
|
+
classNames={mx('invisible @3xl:visible')}
|
|
39
|
+
onClick={() => setOpen((open) => !open)}
|
|
40
|
+
/>
|
|
41
|
+
</Toolbar.Root>
|
|
42
|
+
</Panel.Toolbar>
|
|
43
|
+
<Panel.Content>
|
|
44
|
+
<div
|
|
45
|
+
className={mx(
|
|
46
|
+
'grid h-full w-full gap-2',
|
|
47
|
+
open && '@3xl:grid-cols-[1fr_320px]',
|
|
48
|
+
role === 'section' && 'aspect-square',
|
|
49
|
+
role === 'section' && open && '@3xl:aspect-auto',
|
|
50
|
+
)}
|
|
51
|
+
>
|
|
52
|
+
<Chessboard.Content>
|
|
53
|
+
<Chessboard.Board classNames='m-4 rounded-xs overflow-hidden' orientation={orientation} />
|
|
54
|
+
</Chessboard.Content>
|
|
55
|
+
{open && (
|
|
56
|
+
<div className='hidden @3xl:flex flex-col p-8 justify-center items-center overflow-hidden'>
|
|
57
|
+
<Chessboard.Info
|
|
58
|
+
orientation={orientation}
|
|
59
|
+
min={8}
|
|
60
|
+
max={8}
|
|
61
|
+
onOrientationChange={setOrientation}
|
|
62
|
+
onClose={() => setOpen(false)}
|
|
63
|
+
onSelect={handleSelect}
|
|
64
|
+
/>
|
|
65
|
+
</div>
|
|
66
|
+
)}
|
|
67
|
+
</div>
|
|
68
|
+
</Panel.Content>
|
|
69
|
+
</Panel.Root>
|
|
70
|
+
</Chessboard.Root>
|
|
71
|
+
);
|
|
72
|
+
};
|
|
@@ -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';
|
|
8
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
9
9
|
import { CardContainer } from '@dxos/react-ui-mosaic/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} />
|
|
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 SurfaceComponentProps } from '@dxos/app-toolkit/ui';
|
|
8
|
+
|
|
9
|
+
import { Chessboard } from '../../components';
|
|
10
|
+
import { type Chess } from '../../types';
|
|
11
|
+
|
|
12
|
+
export type ChessCardProps = SurfaceComponentProps<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.
|
package/src/translations.ts
CHANGED
|
@@ -16,6 +16,7 @@ export const translations = [
|
|
|
16
16
|
'typename label_one': 'Game',
|
|
17
17
|
'typename label_other': 'Games',
|
|
18
18
|
'object name placeholder': 'New game',
|
|
19
|
+
'add object label': 'Add game',
|
|
19
20
|
'rename object label': 'Rename game',
|
|
20
21
|
'delete object label': 'Delete game',
|
|
21
22
|
'object deleted label': 'Game deleted',
|
package/src/types/Chess.ts
CHANGED
|
@@ -31,8 +31,8 @@ export const Game = Schema.Struct({
|
|
|
31
31
|
}).pipe(FormInputAnnotation.set(false), Schema.optional),
|
|
32
32
|
}).pipe(
|
|
33
33
|
Type.object({
|
|
34
|
-
typename: 'dxos.
|
|
35
|
-
version: '0.
|
|
34
|
+
typename: 'org.dxos.type.chess',
|
|
35
|
+
version: '0.1.0',
|
|
36
36
|
}),
|
|
37
37
|
LabelAnnotation.set(['name']),
|
|
38
38
|
);
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Chessboard
|
|
3
|
-
} from "./chunk-73BDP7UV.mjs";
|
|
4
|
-
import {
|
|
5
|
-
meta
|
|
6
|
-
} from "./chunk-H3NUMCQ6.mjs";
|
|
7
|
-
import "./chunk-J5LGTIGS.mjs";
|
|
8
|
-
|
|
9
|
-
// src/components/ChessboardContainer.tsx
|
|
10
|
-
import React2 from "react";
|
|
11
|
-
import { Obj } from "@dxos/echo";
|
|
12
|
-
|
|
13
|
-
// src/components/ChessboardArticle.tsx
|
|
14
|
-
import React, { useCallback, useRef, useState } from "react";
|
|
15
|
-
import { Toolbar, useTranslation } from "@dxos/react-ui";
|
|
16
|
-
import { Layout } from "@dxos/react-ui-mosaic";
|
|
17
|
-
import { mx } from "@dxos/ui-theme";
|
|
18
|
-
var ChessboardArticle = ({ role, subject: game }) => {
|
|
19
|
-
const { t } = useTranslation(meta.id);
|
|
20
|
-
const [orientation, setOrientation] = useState("white");
|
|
21
|
-
const [open, setOpen] = useState(true);
|
|
22
|
-
const controller = useRef(null);
|
|
23
|
-
const handleSelect = useCallback((index) => {
|
|
24
|
-
controller.current?.setMoveNumber(index);
|
|
25
|
-
}, []);
|
|
26
|
-
return /* @__PURE__ */ React.createElement(Layout.Main, {
|
|
27
|
-
toolbar: true,
|
|
28
|
-
classNames: "@container"
|
|
29
|
-
}, /* @__PURE__ */ React.createElement(Chessboard.Root, {
|
|
30
|
-
game,
|
|
31
|
-
ref: controller
|
|
32
|
-
}, /* @__PURE__ */ React.createElement(Toolbar.Root, null, /* @__PURE__ */ React.createElement(Toolbar.IconButton, {
|
|
33
|
-
icon: "ph--info--regular",
|
|
34
|
-
iconOnly: true,
|
|
35
|
-
label: t("toggle info button"),
|
|
36
|
-
disabled: open,
|
|
37
|
-
classNames: mx("invisible @3xl:visible"),
|
|
38
|
-
onClick: () => setOpen((open2) => !open2)
|
|
39
|
-
})), /* @__PURE__ */ React.createElement("div", {
|
|
40
|
-
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")
|
|
41
|
-
}, /* @__PURE__ */ React.createElement(Chessboard.Content, null, /* @__PURE__ */ React.createElement(Chessboard.Board, {
|
|
42
|
-
classNames: "m-4 rounded-sm overflow-hidden",
|
|
43
|
-
orientation
|
|
44
|
-
})), open && /* @__PURE__ */ React.createElement("div", {
|
|
45
|
-
className: "hidden @3xl:flex flex-col p-8 justify-center items-center overflow-hidden"
|
|
46
|
-
}, /* @__PURE__ */ React.createElement(Chessboard.Info, {
|
|
47
|
-
orientation,
|
|
48
|
-
min: 8,
|
|
49
|
-
max: 8,
|
|
50
|
-
onOrientationChange: setOrientation,
|
|
51
|
-
onClose: () => setOpen(false),
|
|
52
|
-
onSelect: handleSelect
|
|
53
|
-
})))));
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// src/components/ChessboardContainer.tsx
|
|
57
|
-
var ChessboardContainer = ({ role, subject: game }) => {
|
|
58
|
-
const db = Obj.getDatabase(game);
|
|
59
|
-
if (!db) {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
switch (role) {
|
|
63
|
-
case "card--content": {
|
|
64
|
-
return /* @__PURE__ */ React2.createElement(Chessboard.Root, {
|
|
65
|
-
game
|
|
66
|
-
}, /* @__PURE__ */ React2.createElement(Chessboard.Content, null, /* @__PURE__ */ React2.createElement(Chessboard.Board, null)));
|
|
67
|
-
}
|
|
68
|
-
default: {
|
|
69
|
-
return /* @__PURE__ */ React2.createElement(ChessboardArticle, {
|
|
70
|
-
role,
|
|
71
|
-
subject: game
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
var ChessboardContainer_default = ChessboardContainer;
|
|
77
|
-
export {
|
|
78
|
-
ChessboardContainer,
|
|
79
|
-
ChessboardContainer_default as default
|
|
80
|
-
};
|
|
81
|
-
//# sourceMappingURL=ChessboardContainer-JZ4ANG4O.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 { type SurfaceComponentProps } from '@dxos/app-framework/react';\nimport { Obj } from '@dxos/echo';\n\nimport { type Chess } from '../types';\n\nimport { Chessboard } from './Chessboard';\nimport { ChessboardArticle } from './ChessboardArticle';\n\nexport type ChessboardContainerProps = SurfaceComponentProps<Chess.Game>;\n\nexport const ChessboardContainer = ({ role, subject: game }: ChessboardContainerProps) => {\n const db = Obj.getDatabase(game);\n if (!db) {\n return null;\n }\n\n switch (role) {\n case 'card--content': {\n return (\n <Chessboard.Root game={game}>\n <Chessboard.Content>\n <Chessboard.Board />\n </Chessboard.Content>\n </Chessboard.Root>\n );\n }\n\n default: {\n return <ChessboardArticle role={role} subject={game} />;\n }\n }\n};\n\nexport default ChessboardContainer;\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { useCallback, useRef, useState } from 'react';\n\nimport { type SurfaceComponentProps } from '@dxos/app-framework/react';\nimport { Toolbar, useTranslation } from '@dxos/react-ui';\nimport { type Player } from '@dxos/react-ui-gameboard';\nimport { Layout } from '@dxos/react-ui-mosaic';\nimport { mx } from '@dxos/ui-theme';\n\nimport { meta } from '../meta';\nimport { type Chess } from '../types';\n\nimport { Chessboard, type ChessboardController, type ChessboardInfoProps } from './Chessboard';\n\nexport type ChessboardArticleProps = SurfaceComponentProps<Chess.Game>;\n\nexport const ChessboardArticle = ({ role, subject: game }: ChessboardArticleProps) => {\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 <Layout.Main 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 </Layout.Main>\n );\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;AAIA,OAAOA,YAAW;AAGlB,SAASC,WAAW;;;ACHpB,OAAOC,SAASC,aAAaC,QAAQC,gBAAgB;AAGrD,SAASC,SAASC,sBAAsB;AAExC,SAASC,cAAc;AACvB,SAASC,UAAU;AASZ,IAAMC,oBAAoB,CAAC,EAAEC,MAAMC,SAASC,KAAI,MAA0B;AAC/E,QAAM,EAAEC,EAAC,IAAKC,eAAeC,KAAKC,EAAE;AACpC,QAAM,CAACC,aAAaC,cAAAA,IAAkBC,SAAiB,OAAA;AACvD,QAAM,CAACC,MAAMC,OAAAA,IAAWF,SAAS,IAAA;AACjC,QAAMG,aAAaC,OAA6B,IAAA;AAGhD,QAAMC,eAAeC,YAA0D,CAACC,UAAAA;AAC9EJ,eAAWK,SAASC,cAAcF,KAAAA;EACpC,GAAG,CAAA,CAAE;AAEL,SACE,sBAAA,cAACG,OAAOC,MAAI;IAACC,SAAAA;IAAQC,YAAW;KAC9B,sBAAA,cAACC,WAAWC,MAAI;IAACtB;IAAYuB,KAAKb;KAChC,sBAAA,cAACc,QAAQF,MAAI,MACX,sBAAA,cAACE,QAAQC,YAAU;IACjBC,MAAK;IACLC,UAAAA;IACAC,OAAO3B,EAAE,oBAAA;IACT4B,UAAUrB;IACVY,YAAYU,GAAG,wBAAA;IACfC,SAAS,MAAMtB,QAAQ,CAACD,UAAS,CAACA,KAAAA;OAGtC,sBAAA,cAACwB,OAAAA;IACCC,WAAWH,GACT,8BACAtB,QAAQ,8BACRV,SAAS,aAAa,iBACtBA,SAAS,aAAaU,QAAQ,kBAAA;KAGhC,sBAAA,cAACa,WAAWa,SAAO,MACjB,sBAAA,cAACb,WAAWc,OAAK;IAACf,YAAW;IAAiCf;OAE/DG,QACC,sBAAA,cAACwB,OAAAA;IAAIC,WAAU;KACb,sBAAA,cAACZ,WAAWe,MAAI;IACd/B;IACAgC,KAAK;IACLC,KAAK;IACLC,qBAAqBjC;IACrBkC,SAAS,MAAM/B,QAAQ,KAAA;IACvBgC,UAAU7B;;AAQ1B;;;ADtDO,IAAM8B,sBAAsB,CAAC,EAAEC,MAAMC,SAASC,KAAI,MAA4B;AACnF,QAAMC,KAAKC,IAAIC,YAAYH,IAAAA;AAC3B,MAAI,CAACC,IAAI;AACP,WAAO;EACT;AAEA,UAAQH,MAAAA;IACN,KAAK,iBAAiB;AACpB,aACE,gBAAAM,OAAA,cAACC,WAAWC,MAAI;QAACN;SACf,gBAAAI,OAAA,cAACC,WAAWE,SAAO,MACjB,gBAAAH,OAAA,cAACC,WAAWG,OAAK,IAAA,CAAA,CAAA;IAIzB;IAEA,SAAS;AACP,aAAO,gBAAAJ,OAAA,cAACK,mBAAAA;QAAkBX;QAAYC,SAASC;;IACjD;EACF;AACF;AAEA,IAAA,8BAAeH;",
|
|
6
|
-
"names": ["React", "Obj", "React", "useCallback", "useRef", "useState", "Toolbar", "useTranslation", "Layout", "mx", "ChessboardArticle", "role", "subject", "game", "t", "useTranslation", "meta", "id", "orientation", "setOrientation", "useState", "open", "setOpen", "controller", "useRef", "handleSelect", "useCallback", "index", "current", "setMoveNumber", "Layout", "Main", "toolbar", "classNames", "Chessboard", "Root", "ref", "Toolbar", "IconButton", "icon", "iconOnly", "label", "disabled", "mx", "onClick", "div", "className", "Content", "Board", "Info", "min", "max", "onOrientationChange", "onClose", "onSelect", "ChessboardContainer", "role", "subject", "game", "db", "Obj", "getDatabase", "React", "Chessboard", "Root", "Content", "Board", "ChessboardArticle"]
|
|
7
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
chess_blueprint_exports
|
|
3
|
-
} from "./chunk-FO4ZNFN6.mjs";
|
|
4
|
-
import "./chunk-66H3V2YV.mjs";
|
|
5
|
-
import "./chunk-J5LGTIGS.mjs";
|
|
6
|
-
|
|
7
|
-
// src/capabilities/blueprint-definition/blueprint-definition.ts
|
|
8
|
-
import * as Effect from "effect/Effect";
|
|
9
|
-
import { Capability, Common } from "@dxos/app-framework";
|
|
10
|
-
var blueprintDefinition = Capability.makeModule(() => Effect.succeed([
|
|
11
|
-
Capability.contributes(Common.Capability.Functions, chess_blueprint_exports.functions),
|
|
12
|
-
Capability.contributes(Common.Capability.BlueprintDefinition, chess_blueprint_exports.make())
|
|
13
|
-
]));
|
|
14
|
-
var blueprint_definition_default = blueprintDefinition;
|
|
15
|
-
export {
|
|
16
|
-
blueprint_definition_default as default
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=blueprint-definition-P7TYXWMF.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/capabilities/blueprint-definition/blueprint-definition.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\n\nimport { Capability, Common } from '@dxos/app-framework';\n\nimport { ChessBlueprint } from '../../blueprints';\n\nexport type BlueprintCapabilities = [\n Capability.Capability<typeof Common.Capability.Functions>,\n Capability.Capability<typeof Common.Capability.BlueprintDefinition>,\n];\n\nconst blueprintDefinition = Capability.makeModule<[], BlueprintCapabilities>(() =>\n Effect.succeed([\n Capability.contributes(Common.Capability.Functions, ChessBlueprint.functions),\n Capability.contributes(Common.Capability.BlueprintDefinition, ChessBlueprint.make()),\n ]),\n);\n\nexport default blueprintDefinition;\n"],
|
|
5
|
-
"mappings": ";;;;;;;AAIA,YAAYA,YAAY;AAExB,SAASC,YAAYC,cAAc;AASnC,IAAMC,sBAAsBC,WAAWC,WAAsC,MACpEC,eAAQ;EACbF,WAAWG,YAAYC,OAAOJ,WAAWK,WAAWC,wBAAeC,SAAS;EAC5EP,WAAWG,YAAYC,OAAOJ,WAAWQ,qBAAqBF,wBAAeG,KAAI,CAAA;CAClF,CAAA;AAGH,IAAA,+BAAeV;",
|
|
6
|
-
"names": ["Effect", "Capability", "Common", "blueprintDefinition", "Capability", "makeModule", "succeed", "contributes", "Common", "Functions", "ChessBlueprint", "functions", "BlueprintDefinition", "make"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/Chessboard.tsx", "../../../src/components/Info.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Registry, RegistryContext } from '@effect-atom/atom-react';\nimport React, {\n type PropsWithChildren,\n forwardRef,\n useCallback,\n useContext,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n} from 'react';\n\nimport { addEventListener } from '@dxos/async';\nimport { Obj } from '@dxos/echo';\nimport { type ThemedClassName } from '@dxos/react-ui';\nimport {\n ChessModel,\n Gameboard,\n type GameboardRootProps,\n Chessboard as NaturalChessboard,\n type ChessboardProps as NaturalChessboardProps,\n getRawPgn,\n useGameboardContext,\n} from '@dxos/react-ui-gameboard';\nimport { useSoundEffect } from '@dxos/react-ui-sfx';\nimport { mx } from '@dxos/ui-theme';\n\nimport { type Chess } from '../types';\n\nimport { Info, type InfoProps } from './Info';\n\nexport interface ChessboardController {\n setMoveNumber(index: number): void;\n}\n\nexport class ExtendedChessModel extends ChessModel {\n constructor(\n registry: Registry.Registry,\n readonly object: Chess.Game,\n ) {\n super(registry);\n }\n}\n\n//\n// Root\n//\n\ntype RootProps = PropsWithChildren<{\n game: Chess.Game;\n}>;\n\nconst Root = forwardRef<ChessboardController, RootProps>(({ game, children }, forwardedRef) => {\n const registry = useContext(RegistryContext);\n const model = useMemo(() => new ExtendedChessModel(registry, game), [registry]);\n const click = useSoundEffect('Click');\n\n // Controller.\n useImperativeHandle(forwardedRef, () => {\n return {\n setMoveNumber: (index) => model.setMoveIndex(index),\n };\n }, [model]);\n\n // External change.\n // NOTE: Warning if user has not interacted with the board.\n useEffect(() => {\n if (model.pgn !== getRawPgn(game.pgn ?? '')) {\n const silent = model.pgn === '*';\n model.update(game.pgn);\n if (!silent) {\n void click.play();\n }\n }\n }, [game.pgn]);\n\n // Move.\n const handleDrop = useCallback<NonNullable<GameboardRootProps<ChessModel>['onDrop']>>(\n (move) => {\n if (!model.makeMove(move)) {\n return false;\n }\n\n void click.play();\n Obj.change(game, (g) => {\n g.pgn = model.pgn;\n });\n return true;\n },\n [model],\n );\n\n return (\n <Gameboard.Root model={model} onDrop={handleDrop}>\n {children}\n </Gameboard.Root>\n );\n});\n\n//\n// Content\n//\n\ntype Role = 'card--popover' | 'card--intrinsic' | 'card--extrinsic';\n\ntype ContentProps = ThemedClassName<PropsWithChildren<{ role?: Role }>>;\n\nconst Content = ({ classNames, children, role }: ContentProps) => {\n return (\n <Gameboard.Content\n classNames={mx(classNames, role === 'card--popover' && 'size-container popover-square')}\n grow={!role || role === 'card--extrinsic'}\n contain={!role || role === 'card--extrinsic' || role === 'card--popover'}\n >\n {children}\n </Gameboard.Content>\n );\n};\n\n//\n// Board\n//\n\ntype BoardProps = NaturalChessboardProps;\n\nconst Board = (props: BoardProps) => {\n const registry = useContext(RegistryContext);\n const { model } = useGameboardContext<ChessModel>(Board.displayName);\n\n // Keyboard navigation.\n const ref = useRef<HTMLDivElement>(null);\n useEffect(() => {\n if (!ref.current) {\n return;\n }\n\n // Participate in keyboard navigation (set tabIndex={0})\n ref.current.setAttribute('data-arrow-keys', 'all');\n\n return addEventListener(ref.current, 'keydown', (ev) => {\n const moveIndex = registry.get(model.moveIndex);\n switch (ev.key) {\n case 'ArrowUp':\n model.setMoveIndex(0);\n break;\n case 'ArrowDown':\n model.setMoveIndex(model.game.history().length);\n break;\n case 'ArrowLeft':\n if (moveIndex > 0) {\n model.setMoveIndex(moveIndex - 1);\n }\n break;\n case 'ArrowRight':\n if (moveIndex < model.game.history().length) {\n model.setMoveIndex(moveIndex + 1);\n }\n break;\n }\n });\n }, [registry, model]);\n\n return <NaturalChessboard ref={ref} {...props} />;\n};\n\nBoard.displayName = 'Chessboard.Board';\n\n//\n// Chessboard\n//\n\nexport const Chessboard = {\n Root: Root,\n Content: Content,\n Board: Board,\n Info: Info,\n};\n\nexport type {\n RootProps as ChessboardRootProps,\n ContentProps as ChessboardContentProps,\n BoardProps as ChessboardBoardProps,\n InfoProps as ChessboardInfoProps,\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { useAtomValue } from '@effect-atom/atom-react';\nimport React, { type JSX, type PropsWithChildren, useEffect, useMemo, useRef } from 'react';\n\nimport { generateName } from '@dxos/display-name';\nimport { Obj } from '@dxos/echo';\nimport { type SpaceMember, useMembers } from '@dxos/react-client/echo';\nimport { Icon, IconButton, Select, type ThemedClassName, useTranslation } from '@dxos/react-ui';\nimport { type Player, useGameboardContext } from '@dxos/react-ui-gameboard';\nimport { mx } from '@dxos/ui-theme';\n\nimport { meta } from '../meta';\n\nimport { type ExtendedChessModel } from './Chessboard';\n\nexport type InfoProps = ThemedClassName<\n {\n orientation?: Player;\n onOrientationChange?: (orientation: Player) => void;\n onClose?: () => void;\n } & Pick<HistoryProps, 'min' | 'max' | 'onSelect'>\n>;\n\nexport const Info = ({ classNames, orientation = 'white', onOrientationChange, onClose, ...props }: InfoProps) => {\n const { t } = useTranslation(meta.id);\n const { model } = useGameboardContext<ExtendedChessModel>(Info.displayName);\n const db = Obj.getDatabase(model.object);\n const members = useMembers(db?.spaceId);\n\n return (\n <div\n className={mx(\n 'grid grid-rows-[min-content_1fr_min-content] is-full min-is-[18rem] p-2 overflow-hidden bg-groupSurface rounded-sm',\n classNames,\n )}\n >\n <PlayerIndicator\n model={model}\n player={orientation === 'white' ? 'black' : 'white'}\n icon={\n onClose && (\n <IconButton icon='ph--x--regular' iconOnly label={t('close info button')} size={4} onClick={onClose} />\n )\n }\n >\n <PlayerSelector\n value={model.object.players?.[orientation === 'white' ? 'black' : 'white']}\n onValueChange={(value) => {\n Obj.change(model.object, (obj) => {\n obj.players![orientation === 'white' ? 'black' : 'white'] = value;\n });\n }}\n members={members}\n />\n </PlayerIndicator>\n\n <History model={model} {...props} />\n\n <PlayerIndicator\n model={model}\n player={orientation}\n icon={\n onOrientationChange && (\n <IconButton\n classNames={mx('transition duration-200 ease-linear', orientation === 'white' && 'rotate-180')}\n icon='ph--arrows-clockwise--regular'\n iconOnly\n label={t('flip board button')}\n size={4}\n onClick={() => onOrientationChange(orientation === 'white' ? 'black' : 'white')}\n />\n )\n }\n >\n <PlayerSelector\n value={model.object.players?.[orientation]}\n onValueChange={(value) => {\n Obj.change(model.object, (obj) => {\n obj.players![orientation] = value;\n });\n }}\n members={members}\n />\n </PlayerIndicator>\n </div>\n );\n};\n\nInfo.displayName = 'Chessboard.Info';\n\n//\n// History\n//\n\ntype HistoryProps = ThemedClassName<{\n model: ExtendedChessModel;\n min?: number;\n max?: number;\n onSelect?: (index: number) => void;\n}>;\n\nconst History = ({ classNames, model, min, max, onSelect }: HistoryProps) => {\n const { t } = useTranslation(meta.id);\n const moveIndex = useAtomValue(model.moveIndex);\n const label = model.game.isGameOver()\n ? model.game.isCheckmate()\n ? t('game.checkmate label')\n : model.game.isStalemate()\n ? t('game.stalemate label')\n : t('game.draw label')\n : model.game.isCheck()\n ? t('game.check label')\n : undefined;\n\n const history = model.game.history();\n const moves = useMemo(\n () =>\n history.reduce(\n (acc, move, index) => {\n if (index % 2 === 0) {\n acc.push([{ index, move }]);\n } else {\n acc[acc.length - 1].push({ index, move });\n }\n return acc;\n },\n [] as { index: number; move: string }[][],\n ),\n [history.length],\n );\n\n const scrollerRef = useRef<HTMLDivElement>(null);\n useEffect(() => {\n scrollerRef.current?.scrollTo({ top: scrollerRef.current.scrollHeight });\n }, [history.length]);\n\n useEffect(() => {\n const div = scrollerRef.current?.querySelector(`[data-index=\"${moveIndex - 1}\"]`);\n scrollerRef.current?.classList.add('scrollbar-none');\n div?.scrollIntoView({ behavior: 'smooth' });\n scrollerRef.current?.classList.remove('scrollbar-none');\n }, [moveIndex]);\n\n return (\n <div\n ref={scrollerRef}\n className={mx('overflow-y-auto', classNames)}\n style={{\n minHeight: min === undefined ? 'auto' : `${min * 24}px`,\n maxHeight: max === undefined ? 'auto' : `${max * 24}px`,\n }}\n >\n {moves.map(([a, b], index) => (\n <div key={index} className='grid grid-cols-[3rem_1fr_1fr_1rem] gap-2 pis-4 leading-1'>\n <div className='content-center text-xs text-subdued'>{index + 1}</div>\n {a && (\n <div\n data-index={a.index}\n className={mx('pis-2 cursor-pointer', a.index === moveIndex - 1 && 'bg-primary-500')}\n onClick={() => onSelect?.(a.index + 1)}\n >\n {a.move}\n </div>\n )}\n {b && (\n <div\n data-index={b.index}\n className={mx('pis-2 cursor-pointer', b.index === moveIndex - 1 && 'bg-primary-500')}\n onClick={() => onSelect?.(b.index + 1)}\n >\n {b.move}\n </div>\n )}\n </div>\n ))}\n {label && <div className='text-center'>{label}</div>}\n </div>\n );\n};\n\n//\n// PlayerIndicator\n//\n\ntype PlayerIndicatorProps = PropsWithChildren<{\n model: ExtendedChessModel;\n player: Player;\n icon?: JSX.Element;\n}>;\n\nconst PlayerIndicator = ({ children, model, player, icon }: PlayerIndicatorProps) => {\n const turn = player === (model.game.turn() === 'w' ? 'white' : 'black');\n return (\n <div className='grid grid-cols-[2rem_1fr_2rem] gap-2 bs-[--rail-size] pli-1 flex items-center overflow-hidden'>\n <div className='place-items-center'>\n <Icon\n icon={turn ? 'ph--circle--fill' : 'ph--circle--thin'}\n size={6}\n classNames={mx(turn && (model.game.isCheckmate() ? 'text-red-500' : 'text-green-500'))}\n />\n </div>\n <div className='truncate overflow-hidden items-center'>{children}</div>\n {icon}\n </div>\n );\n};\n\n//\n// PlayerSelector\n//\n\ntype PlayerSelectorProps = {\n value?: string;\n onValueChange: (player: string) => void;\n members: SpaceMember[];\n};\n\nconst PlayerSelector = ({ value, onValueChange, members }: PlayerSelectorProps) => {\n const { t } = useTranslation(meta.id);\n return (\n <Select.Root value={value} onValueChange={onValueChange}>\n <Select.TriggerButton placeholder={t('select player button')} />\n <Select.Portal>\n <Select.Content>\n <Select.Viewport>\n {members.map((member) => {\n const memberKey = member.identity.identityKey.toHex();\n const displayName = member.identity?.profile?.displayName || generateName(memberKey);\n return (\n <Select.Option key={memberKey} value={memberKey}>\n {displayName}\n </Select.Option>\n );\n })}\n </Select.Viewport>\n <Select.Arrow />\n </Select.Content>\n </Select.Portal>\n </Select.Root>\n );\n};\n"],
|
|
5
|
-
"mappings": ";;;;;AAIA,SAAwBA,uBAAuB;AAC/C,OAAOC,UAELC,YACAC,aACAC,YACAC,aAAAA,YACAC,qBACAC,WAAAA,UACAC,UAAAA,eACK;AAEP,SAASC,wBAAwB;AACjC,SAASC,OAAAA,YAAW;AAEpB,SACEC,YACAC,WAEAC,cAAcC,mBAEdC,WACAC,uBAAAA,4BACK;AACP,SAASC,sBAAsB;AAC/B,SAASC,MAAAA,WAAU;;;ACzBnB,SAASC,oBAAoB;AAC7B,OAAOC,SAA2CC,WAAWC,SAASC,cAAc;AAEpF,SAASC,oBAAoB;AAC7B,SAASC,WAAW;AACpB,SAA2BC,kBAAkB;AAC7C,SAASC,MAAMC,YAAYC,QAA8BC,sBAAsB;AAC/E,SAAsBC,2BAA2B;AACjD,SAASC,UAAU;AAcZ,IAAMC,OAAO,CAAC,EAAEC,YAAYC,cAAc,SAASC,qBAAqBC,SAAS,GAAGC,MAAAA,MAAkB;AAC3G,QAAM,EAAEC,EAAC,IAAKC,eAAeC,KAAKC,EAAE;AACpC,QAAM,EAAEC,MAAK,IAAKC,oBAAwCX,KAAKY,WAAW;AAC1E,QAAMC,KAAKC,IAAIC,YAAYL,MAAMM,MAAM;AACvC,QAAMC,UAAUC,WAAWL,IAAIM,OAAAA;AAE/B,SACE,sBAA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,KAAK;AACH,cAAIA,YAAYxC,MAAML,KAAKgD,QAAO,EAAGC,QAAQ;AAC3C5C,kBAAMO,aAAaiC,YAAY,CAAA;UACjC;AACA;MACJ;IACF,CAAA;EACF,GAAG;IAACjD;IAAUS;GAAM;AAEpB,SAAO,gBAAAqB,OAAA,cAACwB,mBAAAA;IAAkBX;IAAW,GAAGH;;AAC1C;AAEAD,MAAMG,cAAc;AAMb,IAAMa,aAAa;EACxBrD;EACA+B;EACAM;EACAiB;AACF;",
|
|
6
|
-
"names": ["RegistryContext", "React", "forwardRef", "useCallback", "useContext", "useEffect", "useImperativeHandle", "useMemo", "useRef", "addEventListener", "Obj", "ChessModel", "Gameboard", "Chessboard", "NaturalChessboard", "getRawPgn", "useGameboardContext", "useSoundEffect", "mx", "useAtomValue", "React", "useEffect", "useMemo", "useRef", "generateName", "Obj", "useMembers", "Icon", "IconButton", "Select", "useTranslation", "useGameboardContext", "mx", "Info", "classNames", "orientation", "onOrientationChange", "onClose", "props", "t", "useTranslation", "meta", "id", "model", "useGameboardContext", "displayName", "db", "Obj", "getDatabase", "object", "members", "useMembers", "spaceId", "div", "className", "mx", "PlayerIndicator", "player", "icon", "IconButton", "iconOnly", "label", "size", "onClick", "PlayerSelector", "value", "players", "onValueChange", "change", "obj", "History", "min", "max", "onSelect", "moveIndex", "useAtomValue", "game", "isGameOver", "isCheckmate", "isStalemate", "isCheck", "undefined", "history", "moves", "useMemo", "reduce", "acc", "move", "index", "push", "length", "scrollerRef", "useRef", "useEffect", "current", "scrollTo", "top", "scrollHeight", "querySelector", "classList", "add", "scrollIntoView", "behavior", "remove", "ref", "style", "minHeight", "maxHeight", "map", "a", "b", "key", "data-index", "children", "turn", "Icon", "Select", "Root", "TriggerButton", "placeholder", "Portal", "Content", "Viewport", "member", "memberKey", "identity", "identityKey", "toHex", "profile", "generateName", "Option", "Arrow", "ExtendedChessModel", "ChessModel", "registry", "object", "Root", "forwardRef", "game", "children", "forwardedRef", "useContext", "RegistryContext", "model", "useMemo", "click", "useSoundEffect", "useImperativeHandle", "setMoveNumber", "index", "setMoveIndex", "useEffect", "pgn", "getRawPgn", "silent", "update", "play", "handleDrop", "useCallback", "move", "makeMove", "Obj", "change", "g", "React", "Gameboard", "onDrop", "Content", "classNames", "role", "mx", "grow", "contain", "Board", "props", "useGameboardContext", "displayName", "ref", "useRef", "current", "setAttribute", "addEventListener", "ev", "moveIndex", "get", "key", "history", "length", "NaturalChessboard", "Chessboard", "Info"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/blueprints/chess-blueprint.ts", "../../../src/blueprints/functions/index.ts", "../../../src/blueprints/functions/create.ts", "../../../src/blueprints/functions/move.ts", "../../../src/blueprints/functions/play.ts", "../../../src/blueprints/functions/print.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Blueprint, Template } from '@dxos/blueprints';\nimport { type FunctionDefinition } from '@dxos/functions';\nimport { trim } from '@dxos/util';\n\nimport { create, move, play, print } from './functions';\n\nexport const Key = 'dxos.org/blueprint/chess';\n\nexport const functions: FunctionDefinition[] = [create, move, play, print];\n\nexport const make = () =>\n Blueprint.make({\n key: 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// Copyright 2024 DXOS.org\n//\n\nexport { default as create } from './create';\nexport { default as move } from './move';\nexport { default as play } from './play';\nexport { default as print } from './print';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\nimport * as Schema from 'effect/Schema';\n\nimport { Database } from '@dxos/echo';\nimport { 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 name: Schema.optional(\n Schema.String.annotations({\n description: 'Name of the game.',\n }),\n ),\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: { name, pgn, fen } }) {\n return yield* Database.Service.add(Chess.make({ name, 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 { Database, Obj } from '@dxos/echo';\nimport { 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* Database.Service.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 const pgn = chess.pgn();\n Obj.change(object, (o) => {\n o.pgn = pgn;\n });\n return { 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 { Database, Obj } from '@dxos/echo';\nimport { 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* Database.Service.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 const pgn = chess.pgn();\n Obj.change(object, (o) => {\n o.pgn = pgn;\n });\n return { move, 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 { defineFunction } from '@dxos/functions';\n\nexport default defineFunction({\n key: 'dxos.org/function/chess/print',\n name: 'Print game',\n description: 'Prints the chess game to ASCII.',\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: Schema.Struct({\n ascii: Schema.String,\n }),\n handler: Effect.fn(function* ({ data: { pgn, fen } }) {\n try {\n const chess = new ChessJS(fen);\n if (pgn) {\n chess.loadPgn(pgn);\n }\n return { ascii: chess.ascii() };\n } catch {\n // TODO(burdon): Error handling?\n return { ascii: '' };\n }\n }),\n});\n"],
|
|
5
|
-
"mappings": ";;;;;;;;AAAA;;;;;;AAIA,SAASA,WAAWC,gBAAgB;AAEpC,SAASC,YAAY;;;ACNrB;;;;;;;;;ACIA,YAAYC,YAAY;AACxB,YAAYC,YAAY;AAExB,SAASC,gBAAgB;AACzB,SAASC,sBAAsB;AAI/B,IAAA,iBAAeC,eAAe;EAC5BC,KAAK;EACLC,MAAM;EACNC,aAAa;EACbC,aAAoBC,cAAO;IACzBH,MAAaI,gBACJC,cAAOC,YAAY;MACxBL,aAAa;IACf,CAAA,CAAA;IAEFM,KAAYH,gBACHC,cAAOC,YAAY;MACxBL,aAAa;IACf,CAAA,CAAA;IAEFO,KAAYJ,gBACHC,cAAOC,YAAY;MACxBL,aAAa;IACf,CAAA,CAAA;EAEJ,CAAA;EACAQ,cAAcC,cAAMC;EACpBC,SAAgBC,UAAG,WAAW,EAAEC,MAAM,EAAEd,MAAMO,KAAKC,IAAG,EAAE,GAAE;AACxD,WAAO,OAAOO,SAASC,QAAQC,IAAIP,cAAMQ,KAAK;MAAElB;MAAMO;MAAKC;IAAI,CAAA,CAAA;EACjE,CAAA;AACF,CAAA;;;ACjCA,SAASW,SAASC,eAAe;AACjC,YAAYC,aAAY;AACxB,YAAYC,aAAY;AAExB,SAASC,kBAAkB;AAC3B,SAASC,YAAAA,WAAUC,WAAW;AAC9B,SAASC,kBAAAA,uBAAsB;AAI/B,IAAA,eAAeC,gBAAe;EAC5BC,KAAK;EACLC,MAAM;EACNC,aAAa;EACbC,aAAoBC,eAAO;IACzBC,IAAIC,WAAWC,YAAY;MACzBL,aAAa;IACf,CAAA;IACAM,MAAaC,eAAOF,YAAY;MAC9BL,aAAa;MACbQ,UAAU;QAAC;QAAM;;IACnB,CAAA;EACF,CAAA;EACAC,cAAqBP,eAAO;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,EAAET,KAAKI,IAAG,EAAE,GAAE;AAClD,QAAI;AACF,YAAMM,QAAQ,IAAIC,SAAQP,GAAAA;AAC1B,UAAIJ,KAAK;AACPU,cAAME,QAAQZ,GAAAA;MAChB;AACA,aAAO;QAAEM,OAAOI,MAAMJ,MAAK;MAAG;IAChC,QAAQ;AAEN,aAAO;QAAEA,OAAO;MAAG;IACrB;EACF,CAAA;AACF,CAAA;;;AL/BO,IAAMO,MAAM;AAEZ,IAAMC,YAAkC;EAACC;EAAQC;EAAMC;EAAMC;;AAE7D,IAAMC,OAAO,MAClBC,UAAUD,KAAK;EACbE,KAAKR;EACLS,MAAM;EACNC,OAAOH,UAAUI,gBAAgB;IAAEV;EAAU,CAAA;EAC7CW,cAAcC,SAASP,KAAK;IAC1BQ,QAAQC;;;;;;EAMV,CAAA;AACF,CAAA;",
|
|
6
|
-
"names": ["Blueprint", "Template", "trim", "Effect", "Schema", "Database", "defineFunction", "defineFunction", "key", "name", "description", "inputSchema", "Struct", "optional", "String", "annotations", "pgn", "fen", "outputSchema", "Chess", "Game", "handler", "fn", "data", "Database", "Service", "add", "make", "Chess", "ChessJS", "Effect", "Schema", "ArtifactId", "Database", "Obj", "defineFunction", "defineFunction", "key", "name", "description", "inputSchema", "Struct", "id", "ArtifactId", "annotations", "move", "String", "examples", "outputSchema", "pgn", "handler", "fn", "data", "object", "Database", "Service", "resolve", "toDXN", "Chess", "Game", "chess", "ChessJS", "loadPgn", "fen", "load", "strict", "Obj", "change", "o", "Chess", "ChessJS", "Effect", "Schema", "ArtifactId", "Database", "Obj", "defineFunction", "defineFunction", "key", "name", "description", "inputSchema", "Struct", "id", "ArtifactId", "annotations", "side", "optional", "Literal", "defaultValue", "outputSchema", "pgn", "String", "move", "handler", "fn", "data", "object", "Database", "Service", "resolve", "toDXN", "Chess", "Game", "chess", "ChessJS", "loadPgn", "fen", "load", "turn", "undefined", "moves", "Math", "floor", "random", "length", "strict", "Obj", "change", "o", "Chess", "ChessJS", "Effect", "Schema", "defineFunction", "defineFunction", "key", "name", "description", "inputSchema", "Struct", "pgn", "optional", "String", "annotations", "fen", "outputSchema", "ascii", "handler", "fn", "data", "chess", "ChessJS", "loadPgn", "Key", "functions", "create", "move", "play", "print", "make", "Blueprint", "key", "name", "tools", "toolDefinitions", "instructions", "Template", "source", "trim"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/index.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { lazy } from 'react';\n\nexport * from './Chessboard';\n\nexport const ChessboardContainer = lazy(() => import('./ChessboardContainer'));\n"],
|
|
5
|
-
"mappings": ";AAIA,SAASA,YAAY;AAId,IAAMC,sBAAsBC,KAAK,MAAM,OAAO,oCAAA,CAAA;",
|
|
6
|
-
"names": ["lazy", "ChessboardContainer", "lazy"]
|
|
7
|
-
}
|