@dxos/plugin-chess 0.8.4-main.70d3990 → 0.8.4-main.74a063c4e0

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.
Files changed (223) hide show
  1. package/dist/lib/browser/blueprints/index.mjs +14 -0
  2. package/dist/lib/browser/{chunk-CCF24VRU.mjs → chunk-2TJN26DN.mjs} +18 -34
  3. package/dist/lib/browser/chunk-2TJN26DN.mjs.map +7 -0
  4. package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
  5. package/dist/lib/browser/chunk-MC7L6JNC.mjs +36 -0
  6. package/dist/lib/browser/chunk-MC7L6JNC.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-SBRUTOHG.mjs +28 -0
  8. package/dist/lib/browser/chunk-SBRUTOHG.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-XAJZK6Z2.mjs +110 -0
  10. package/dist/lib/browser/chunk-XAJZK6Z2.mjs.map +7 -0
  11. package/dist/lib/browser/cli/index.mjs +34 -0
  12. package/dist/lib/browser/cli/index.mjs.map +7 -0
  13. package/dist/lib/browser/create-AJHN4QT4.mjs +24 -0
  14. package/dist/lib/browser/create-AJHN4QT4.mjs.map +7 -0
  15. package/dist/lib/browser/index.mjs +364 -99
  16. package/dist/lib/browser/index.mjs.map +4 -4
  17. package/dist/lib/browser/meta.json +1 -1
  18. package/dist/lib/browser/move-CN7BGBOR.mjs +36 -0
  19. package/dist/lib/browser/move-CN7BGBOR.mjs.map +7 -0
  20. package/dist/lib/browser/operations/index.mjs +19 -0
  21. package/dist/lib/browser/operations/index.mjs.map +7 -0
  22. package/dist/lib/browser/play-YRKSZF5U.mjs +45 -0
  23. package/dist/lib/browser/play-YRKSZF5U.mjs.map +7 -0
  24. package/dist/lib/browser/print-EW7LPW4D.mjs +30 -0
  25. package/dist/lib/browser/print-EW7LPW4D.mjs.map +7 -0
  26. package/dist/lib/browser/types/index.mjs +3 -5
  27. package/dist/lib/node-esm/blueprints/index.mjs +15 -0
  28. package/dist/lib/node-esm/blueprints/index.mjs.map +7 -0
  29. package/dist/lib/node-esm/chunk-4HZWCKMR.mjs +38 -0
  30. package/dist/lib/node-esm/chunk-4HZWCKMR.mjs.map +7 -0
  31. package/dist/lib/node-esm/chunk-7W2LXAM5.mjs +29 -0
  32. package/dist/lib/node-esm/chunk-7W2LXAM5.mjs.map +7 -0
  33. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  34. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
  35. package/dist/lib/node-esm/chunk-NYU5JVXP.mjs +111 -0
  36. package/dist/lib/node-esm/chunk-NYU5JVXP.mjs.map +7 -0
  37. package/dist/lib/node-esm/{chunk-QKXLEJNZ.mjs → chunk-OIRJVY2R.mjs} +18 -34
  38. package/dist/lib/node-esm/chunk-OIRJVY2R.mjs.map +7 -0
  39. package/dist/lib/node-esm/cli/index.mjs +35 -0
  40. package/dist/lib/node-esm/cli/index.mjs.map +7 -0
  41. package/dist/lib/node-esm/create-QSETDT4N.mjs +25 -0
  42. package/dist/lib/node-esm/create-QSETDT4N.mjs.map +7 -0
  43. package/dist/lib/node-esm/index.mjs +364 -99
  44. package/dist/lib/node-esm/index.mjs.map +4 -4
  45. package/dist/lib/node-esm/meta.json +1 -1
  46. package/dist/lib/node-esm/move-OTEYBHVI.mjs +37 -0
  47. package/dist/lib/node-esm/move-OTEYBHVI.mjs.map +7 -0
  48. package/dist/lib/node-esm/operations/index.mjs +20 -0
  49. package/dist/lib/node-esm/operations/index.mjs.map +7 -0
  50. package/dist/lib/node-esm/play-ZLDAXADK.mjs +46 -0
  51. package/dist/lib/node-esm/play-ZLDAXADK.mjs.map +7 -0
  52. package/dist/lib/node-esm/print-UJHXAXMS.mjs +31 -0
  53. package/dist/lib/node-esm/print-UJHXAXMS.mjs.map +7 -0
  54. package/dist/lib/node-esm/types/index.mjs +3 -5
  55. package/dist/types/src/ChessPlugin.d.ts +2 -1
  56. package/dist/types/src/ChessPlugin.d.ts.map +1 -1
  57. package/dist/types/src/blueprints/chess-blueprint.d.ts +4 -0
  58. package/dist/types/src/blueprints/chess-blueprint.d.ts.map +1 -0
  59. package/dist/types/src/blueprints/index.d.ts +3 -0
  60. package/dist/types/src/blueprints/index.d.ts.map +1 -0
  61. package/dist/types/src/capabilities/artifact-definition.d.ts +3 -2
  62. package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -1
  63. package/dist/types/src/capabilities/blueprint-definition.d.ts +5 -5
  64. package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -1
  65. package/dist/types/src/capabilities/index.d.ts +5 -4
  66. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  67. package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
  68. package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
  69. package/dist/types/src/capabilities/react-surface.d.ts +3 -2
  70. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  71. package/dist/types/src/cli/index.d.ts +2 -0
  72. package/dist/types/src/cli/index.d.ts.map +1 -0
  73. package/dist/types/src/cli/plugin.d.ts +3 -0
  74. package/dist/types/src/cli/plugin.d.ts.map +1 -0
  75. package/dist/types/src/components/{Chessboard.d.ts → Chessboard/Chessboard.d.ts} +4 -8
  76. package/dist/types/src/components/Chessboard/Chessboard.d.ts.map +1 -0
  77. package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts +48 -0
  78. package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts.map +1 -0
  79. package/dist/types/src/components/{Info.d.ts → Chessboard/Info.d.ts} +1 -1
  80. package/dist/types/src/components/Chessboard/Info.d.ts.map +1 -0
  81. package/dist/types/src/components/Chessboard/index.d.ts +2 -0
  82. package/dist/types/src/components/Chessboard/index.d.ts.map +1 -0
  83. package/dist/types/src/components/Chessboard/types.d.ts +8 -0
  84. package/dist/types/src/components/Chessboard/types.d.ts.map +1 -0
  85. package/dist/types/src/components/index.d.ts +0 -1
  86. package/dist/types/src/components/index.d.ts.map +1 -1
  87. package/dist/types/src/containers/ChessArticle/ChessArticle.d.ts +6 -0
  88. package/dist/types/src/containers/ChessArticle/ChessArticle.d.ts.map +1 -0
  89. package/dist/types/src/containers/ChessArticle/ChessArticle.stories.d.ts +47 -0
  90. package/dist/types/src/containers/ChessArticle/ChessArticle.stories.d.ts.map +1 -0
  91. package/dist/types/src/containers/ChessArticle/index.d.ts +2 -0
  92. package/dist/types/src/containers/ChessArticle/index.d.ts.map +1 -0
  93. package/dist/types/src/containers/ChessCard/ChessCard.d.ts +6 -0
  94. package/dist/types/src/containers/ChessCard/ChessCard.d.ts.map +1 -0
  95. package/dist/types/src/{components/Card.stories.d.ts → containers/ChessCard/ChessCard.stories.d.ts} +2 -9
  96. package/dist/types/src/containers/ChessCard/ChessCard.stories.d.ts.map +1 -0
  97. package/dist/types/src/containers/ChessCard/index.d.ts +2 -0
  98. package/dist/types/src/containers/ChessCard/index.d.ts.map +1 -0
  99. package/dist/types/src/containers/index.d.ts +4 -0
  100. package/dist/types/src/containers/index.d.ts.map +1 -0
  101. package/dist/types/src/index.d.ts +2 -3
  102. package/dist/types/src/index.d.ts.map +1 -1
  103. package/dist/types/src/meta.d.ts +2 -2
  104. package/dist/types/src/meta.d.ts.map +1 -1
  105. package/dist/types/src/operations/create.d.ts +5 -0
  106. package/dist/types/src/operations/create.d.ts.map +1 -0
  107. package/dist/types/src/operations/definitions.d.ts +51 -0
  108. package/dist/types/src/operations/definitions.d.ts.map +1 -0
  109. package/dist/types/src/operations/index.d.ts +4 -0
  110. package/dist/types/src/operations/index.d.ts.map +1 -0
  111. package/dist/types/src/operations/move.d.ts +5 -0
  112. package/dist/types/src/operations/move.d.ts.map +1 -0
  113. package/dist/types/src/operations/play.d.ts +5 -0
  114. package/dist/types/src/operations/play.d.ts.map +1 -0
  115. package/dist/types/src/operations/print.d.ts +5 -0
  116. package/dist/types/src/operations/print.d.ts.map +1 -0
  117. package/dist/types/src/translations.d.ts +21 -20
  118. package/dist/types/src/translations.d.ts.map +1 -1
  119. package/dist/types/src/types/Chess.d.ts +17 -17
  120. package/dist/types/src/types/Chess.d.ts.map +1 -1
  121. package/dist/types/src/types/index.d.ts +0 -1
  122. package/dist/types/src/types/index.d.ts.map +1 -1
  123. package/dist/types/tsconfig.tsbuildinfo +1 -1
  124. package/package.json +74 -43
  125. package/src/ChessPlugin.tsx +41 -47
  126. package/src/blueprints/chess-blueprint.ts +35 -0
  127. package/src/blueprints/index.ts +6 -0
  128. package/src/capabilities/artifact-definition.ts +98 -92
  129. package/src/capabilities/blueprint-definition.ts +9 -28
  130. package/src/capabilities/index.ts +8 -6
  131. package/src/capabilities/operation-handler.ts +14 -0
  132. package/src/capabilities/react-surface.tsx +27 -15
  133. package/src/cli/index.ts +5 -0
  134. package/src/cli/plugin.ts +37 -0
  135. package/src/components/Chessboard/Chessboard.stories.tsx +94 -0
  136. package/src/components/{Chessboard.tsx → Chessboard/Chessboard.tsx} +32 -29
  137. package/src/components/{Info.tsx → Chessboard/Info.tsx} +41 -24
  138. package/src/components/Chessboard/index.ts +5 -0
  139. package/src/components/Chessboard/types.ts +18 -0
  140. package/src/components/index.ts +1 -5
  141. package/src/containers/ChessArticle/ChessArticle.stories.tsx +53 -0
  142. package/src/containers/ChessArticle/ChessArticle.tsx +73 -0
  143. package/src/containers/ChessArticle/index.ts +5 -0
  144. package/src/containers/ChessCard/ChessCard.stories.tsx +42 -0
  145. package/src/containers/ChessCard/ChessCard.tsx +22 -0
  146. package/src/containers/ChessCard/index.ts +5 -0
  147. package/src/containers/index.ts +8 -0
  148. package/src/index.ts +2 -3
  149. package/src/meta.ts +3 -3
  150. package/src/operations/create.ts +21 -0
  151. package/src/operations/definitions.ts +109 -0
  152. package/src/operations/index.ts +16 -0
  153. package/src/operations/move.ts +36 -0
  154. package/src/operations/play.ts +45 -0
  155. package/src/operations/print.ts +28 -0
  156. package/src/translations.ts +21 -20
  157. package/src/types/Chess.ts +11 -7
  158. package/src/types/index.ts +0 -1
  159. package/dist/lib/browser/ChessboardContainer-5YXEM4VR.mjs +0 -96
  160. package/dist/lib/browser/ChessboardContainer-5YXEM4VR.mjs.map +0 -7
  161. package/dist/lib/browser/blueprint-definition-Y5Y4YGNL.mjs +0 -11
  162. package/dist/lib/browser/chunk-3LPE2B5J.mjs +0 -169
  163. package/dist/lib/browser/chunk-3LPE2B5J.mjs.map +0 -7
  164. package/dist/lib/browser/chunk-5DOZV3PW.mjs +0 -294
  165. package/dist/lib/browser/chunk-5DOZV3PW.mjs.map +0 -7
  166. package/dist/lib/browser/chunk-CCF24VRU.mjs.map +0 -7
  167. package/dist/lib/browser/chunk-DUO4WTAM.mjs +0 -28
  168. package/dist/lib/browser/chunk-DUO4WTAM.mjs.map +0 -7
  169. package/dist/lib/browser/chunk-Q5TZCIH7.mjs +0 -8
  170. package/dist/lib/browser/chunk-Q5TZCIH7.mjs.map +0 -7
  171. package/dist/lib/browser/intent-resolver-KPGHK5JU.mjs +0 -25
  172. package/dist/lib/browser/intent-resolver-KPGHK5JU.mjs.map +0 -7
  173. package/dist/lib/browser/react-surface-3YST34QI.mjs +0 -38
  174. package/dist/lib/browser/react-surface-3YST34QI.mjs.map +0 -7
  175. package/dist/lib/node-esm/ChessboardContainer-7OQ6TOKB.mjs +0 -97
  176. package/dist/lib/node-esm/ChessboardContainer-7OQ6TOKB.mjs.map +0 -7
  177. package/dist/lib/node-esm/blueprint-definition-GR6OLMB6.mjs +0 -12
  178. package/dist/lib/node-esm/chunk-F3HFLDV5.mjs +0 -170
  179. package/dist/lib/node-esm/chunk-F3HFLDV5.mjs.map +0 -7
  180. package/dist/lib/node-esm/chunk-F4C2HVZL.mjs +0 -295
  181. package/dist/lib/node-esm/chunk-F4C2HVZL.mjs.map +0 -7
  182. package/dist/lib/node-esm/chunk-KNOOJFIR.mjs +0 -29
  183. package/dist/lib/node-esm/chunk-KNOOJFIR.mjs.map +0 -7
  184. package/dist/lib/node-esm/chunk-QKXLEJNZ.mjs.map +0 -7
  185. package/dist/lib/node-esm/chunk-VVXTAVIS.mjs +0 -10
  186. package/dist/lib/node-esm/chunk-VVXTAVIS.mjs.map +0 -7
  187. package/dist/lib/node-esm/intent-resolver-ZAELGF7I.mjs +0 -26
  188. package/dist/lib/node-esm/intent-resolver-ZAELGF7I.mjs.map +0 -7
  189. package/dist/lib/node-esm/react-surface-KV2KBSIU.mjs +0 -39
  190. package/dist/lib/node-esm/react-surface-KV2KBSIU.mjs.map +0 -7
  191. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  192. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  193. package/dist/types/src/components/Card.stories.d.ts.map +0 -1
  194. package/dist/types/src/components/Chessboard.d.ts.map +0 -1
  195. package/dist/types/src/components/Chessboard.stories.d.ts +0 -46
  196. package/dist/types/src/components/Chessboard.stories.d.ts.map +0 -1
  197. package/dist/types/src/components/ChessboardArticle.d.ts +0 -7
  198. package/dist/types/src/components/ChessboardArticle.d.ts.map +0 -1
  199. package/dist/types/src/components/ChessboardContainer.d.ts +0 -9
  200. package/dist/types/src/components/ChessboardContainer.d.ts.map +0 -1
  201. package/dist/types/src/components/Info.d.ts.map +0 -1
  202. package/dist/types/src/functions/create.d.ts +0 -14
  203. package/dist/types/src/functions/create.d.ts.map +0 -1
  204. package/dist/types/src/functions/index.d.ts +0 -4
  205. package/dist/types/src/functions/index.d.ts.map +0 -1
  206. package/dist/types/src/functions/move.d.ts +0 -8
  207. package/dist/types/src/functions/move.d.ts.map +0 -1
  208. package/dist/types/src/functions/play.d.ts +0 -9
  209. package/dist/types/src/functions/play.d.ts.map +0 -1
  210. package/dist/types/src/types/ChessAction.d.ts +0 -24
  211. package/dist/types/src/types/ChessAction.d.ts.map +0 -1
  212. package/src/capabilities/intent-resolver.ts +0 -22
  213. package/src/components/Card.stories.tsx +0 -66
  214. package/src/components/Chessboard.stories.tsx +0 -49
  215. package/src/components/ChessboardArticle.tsx +0 -68
  216. package/src/components/ChessboardContainer.tsx +0 -44
  217. package/src/functions/create.ts +0 -32
  218. package/src/functions/index.ts +0 -7
  219. package/src/functions/move.ts +0 -45
  220. package/src/functions/play.ts +0 -55
  221. package/src/types/ChessAction.ts +0 -19
  222. /package/dist/lib/browser/{blueprint-definition-Y5Y4YGNL.mjs.map → blueprints/index.mjs.map} +0 -0
  223. /package/dist/lib/{node-esm/blueprint-definition-GR6OLMB6.mjs.map → browser/chunk-J5LGTIGS.mjs.map} +0 -0
@@ -0,0 +1,42 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
6
+ import React, { useMemo } from 'react';
7
+
8
+ import { CardContainer } from '@dxos/react-ui-mosaic/testing';
9
+ import { withLayout, withTheme } from '@dxos/react-ui/testing';
10
+
11
+ import { meta as pluginMeta } from '#meta';
12
+ import { Chess } from '#types';
13
+
14
+ import { ChessCard } from './ChessCard';
15
+
16
+ const SAMPLE_PGN =
17
+ '1. e4 e5 2. Nf3 Nc6 3. Bc4 Bc5 4. c3 Nf6 5. d4 exd4 6. cxd4 Bb4+ 7. Nc3 d5 8. exd5 Nxd5 9. O-O Be6 10. Qb3 Na5 11. Qa4+ c6 12. Bxd5 Bxc3 13. Bxe6 fxe6 14. d5 Qg5 15. dxe6 Qg4 16. e7 Kf7 17. bxc3 Kg6 *';
18
+
19
+ const CardStory = () => {
20
+ const game = useMemo(() => Chess.make({ pgn: SAMPLE_PGN }), []);
21
+ return (
22
+ <CardContainer role='popover' icon={pluginMeta.icon}>
23
+ <ChessCard subject={game} role='card--content' />
24
+ </CardContainer>
25
+ );
26
+ };
27
+
28
+ const meta = {
29
+ title: 'plugins/plugin-chess/containers/ChessCard',
30
+ render: () => <CardStory />,
31
+ decorators: [withTheme(), withLayout({ layout: 'column' })],
32
+ parameters: {
33
+ layout: 'fullscreen',
34
+ },
35
+ tags: ['cards'],
36
+ } satisfies Meta;
37
+
38
+ export default meta;
39
+
40
+ type Story = StoryObj<typeof meta>;
41
+
42
+ export const Popover: Story = {};
@@ -0,0 +1,22 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import React from 'react';
6
+
7
+ import { type AppSurface } from '@dxos/app-toolkit/ui';
8
+
9
+ import { Chessboard } from '#components';
10
+ import { type Chess } from '#types';
11
+
12
+ export type ChessCardProps = AppSurface.ObjectCardProps<Chess.Game>;
13
+
14
+ export const ChessCard = ({ subject: game }: ChessCardProps) => {
15
+ return (
16
+ <Chessboard.Root game={game}>
17
+ <Chessboard.Content>
18
+ <Chessboard.Board />
19
+ </Chessboard.Content>
20
+ </Chessboard.Root>
21
+ );
22
+ };
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ export { ChessCard as default } from './ChessCard';
@@ -0,0 +1,8 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { type ComponentType, lazy } from 'react';
6
+
7
+ export const ChessArticle: ComponentType<any> = lazy(() => import('./ChessArticle'));
8
+ export const ChessCard: ComponentType<any> = lazy(() => import('./ChessCard'));
package/src/index.ts CHANGED
@@ -2,9 +2,8 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- export * from './capabilities';
6
- export * from './components';
7
- export * from './functions';
5
+ export * from './blueprints';
6
+ export * from './components/Chessboard';
8
7
  export * from './meta';
9
8
  export * from './types';
10
9
 
package/src/meta.ts CHANGED
@@ -2,11 +2,11 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { type PluginMeta } from '@dxos/app-framework';
5
+ import { type Plugin } from '@dxos/app-framework';
6
6
  import { trim } from '@dxos/util';
7
7
 
8
- export const meta: PluginMeta = {
9
- id: 'dxos.org/plugin/chess',
8
+ export const meta: Plugin.Meta = {
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, (game) => {
28
+ const mutableGame = game as Obj.Mutable<typeof game>;
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, (game) => {
37
+ const mutableGame = game as Obj.Mutable<typeof game>;
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;
@@ -4,33 +4,34 @@
4
4
 
5
5
  import { type Resource } from '@dxos/react-ui';
6
6
 
7
- import { meta } from './meta';
8
- import { Chess } from './types';
7
+ import { meta } from '#meta';
8
+ import { Chess } from '#types';
9
9
 
10
10
  export const translations = [
11
11
  {
12
12
  'en-US': {
13
13
  [Chess.Game.typename]: {
14
- 'typename label': 'Game',
15
- 'typename label_zero': 'Games',
16
- 'typename label_one': 'Game',
17
- 'typename label_other': 'Games',
18
- 'object name placeholder': 'New game',
19
- 'rename object label': 'Rename game',
20
- 'delete object label': 'Delete game',
21
- 'object deleted label': 'Game deleted',
14
+ 'typename.label': 'Game',
15
+ 'typename.label_zero': 'Games',
16
+ 'typename.label_one': 'Game',
17
+ 'typename.label_other': 'Games',
18
+ 'object-name.placeholder': 'New game',
19
+ 'add-object.label': 'Add game',
20
+ 'rename-object.label': 'Rename game',
21
+ 'delete-object.label': 'Delete game',
22
+ 'object-deleted.label': 'Game deleted',
22
23
  },
23
24
  [meta.id]: {
24
- 'plugin name': 'Chess',
25
- 'delete game label': 'Delete',
26
- 'game.checkmate label': 'Checkmate',
27
- 'game.stalemate label': 'Stalemate',
28
- 'game.draw label': 'Draw',
29
- 'game.check label': 'Check',
30
- 'select player button': 'Select player',
31
- 'toggle info button': 'Toggle info',
32
- 'close info button': 'Close info',
33
- 'flip board button': 'Flip board',
25
+ 'plugin.name': 'Chess',
26
+ 'delete-game.label': 'Delete',
27
+ 'game.checkmate.label': 'Checkmate',
28
+ 'game.stalemate.label': 'Stalemate',
29
+ 'game.draw.label': 'Draw',
30
+ 'game.check.label': 'Check',
31
+ 'select-player.button': 'Select player',
32
+ 'toggle-info.button': 'Toggle info',
33
+ 'close-info.button': 'Close info',
34
+ 'flip-board.button': 'Flip board',
34
35
  },
35
36
  },
36
37
  },
@@ -5,7 +5,7 @@
5
5
  import { Chess as ChessJS } from 'chess.js';
6
6
  import * as Schema from 'effect/Schema';
7
7
 
8
- import { Obj, Type } from '@dxos/echo';
8
+ import { Annotation, Obj, Type } from '@dxos/echo';
9
9
  import { FormInputAnnotation, LabelAnnotation } from '@dxos/echo/internal';
10
10
  import { log } from '@dxos/log';
11
11
 
@@ -22,7 +22,7 @@ export const Game = Schema.Struct({
22
22
  description: 'DID of black player',
23
23
  }),
24
24
  ),
25
- }).pipe(Schema.mutable, FormInputAnnotation.set(false), Schema.optional),
25
+ }).pipe(FormInputAnnotation.set(false), Schema.optional),
26
26
  pgn: Schema.String.annotations({
27
27
  description: 'Portable Game Notation.',
28
28
  }).pipe(FormInputAnnotation.set(false), Schema.optional),
@@ -30,16 +30,20 @@ export const Game = Schema.Struct({
30
30
  description: 'Forsyth-Edwards Notation.',
31
31
  }).pipe(FormInputAnnotation.set(false), Schema.optional),
32
32
  }).pipe(
33
- Type.Obj({
34
- typename: 'dxos.org/type/Chess',
35
- version: '0.2.0',
33
+ Type.object({
34
+ typename: 'org.dxos.type.chess',
35
+ version: '0.1.0',
36
36
  }),
37
37
  LabelAnnotation.set(['name']),
38
+ Annotation.IconAnnotation.set({
39
+ icon: 'ph--shield-chevron--regular',
40
+ hue: 'amber',
41
+ }),
38
42
  );
39
43
 
40
44
  export interface Game extends Schema.Schema.Type<typeof Game> {}
41
45
 
42
- export const makeGame = ({ name, pgn, fen }: { name?: string; pgn?: string; fen?: string } = {}) => {
46
+ export const make = ({ name, pgn, fen }: { name?: string; pgn?: string; fen?: string } = {}) => {
43
47
  const chess = new ChessJS();
44
48
  if (pgn) {
45
49
  try {
@@ -51,8 +55,8 @@ export const makeGame = ({ name, pgn, fen }: { name?: string; pgn?: string; fen?
51
55
 
52
56
  return Obj.make(Game, {
53
57
  name,
54
- players: {},
55
58
  pgn,
56
59
  fen,
60
+ players: {},
57
61
  });
58
62
  };
@@ -3,4 +3,3 @@
3
3
  //
4
4
 
5
5
  export * as Chess from './Chess';
6
- export * as ChessAction from './ChessAction';
@@ -1,96 +0,0 @@
1
- import {
2
- Chessboard
3
- } from "./chunk-5DOZV3PW.mjs";
4
- import {
5
- meta
6
- } from "./chunk-DUO4WTAM.mjs";
7
-
8
- // src/components/ChessboardContainer.tsx
9
- import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
10
- import React2 from "react";
11
- import { getSpace } from "@dxos/react-client/echo";
12
-
13
- // src/components/ChessboardArticle.tsx
14
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
15
- import React, { useCallback, useRef, useState } from "react";
16
- import { Toolbar, useTranslation } from "@dxos/react-ui";
17
- import { StackItem } from "@dxos/react-ui-stack";
18
- import { mx } from "@dxos/react-ui-theme";
19
- var ChessboardArticle = ({ game, role }) => {
20
- var _effect = _useSignals();
21
- try {
22
- const { t } = useTranslation(meta.id);
23
- const [orientation, setOrientation] = useState("white");
24
- const [open, setOpen] = useState(true);
25
- const controller = useRef(null);
26
- const handleSelect = useCallback((index) => {
27
- controller.current?.setMoveNumber(index);
28
- }, []);
29
- return /* @__PURE__ */ React.createElement(StackItem.Content, {
30
- toolbar: true,
31
- classNames: "@container"
32
- }, /* @__PURE__ */ React.createElement(Chessboard.Root, {
33
- game,
34
- ref: controller
35
- }, /* @__PURE__ */ React.createElement(Toolbar.Root, null, /* @__PURE__ */ React.createElement(Toolbar.IconButton, {
36
- icon: "ph--info--regular",
37
- iconOnly: true,
38
- label: t("toggle info button"),
39
- disabled: open,
40
- classNames: mx("invisible @3xl:visible"),
41
- onClick: () => setOpen((open2) => !open2)
42
- })), /* @__PURE__ */ React.createElement("div", {
43
- className: mx("grid bs-full is-full gap-2", open && "@3xl:grid-cols-[1fr_320px]", role === "section" && "aspect-square", role === "section" && open && "@3xl:aspect-auto")
44
- }, /* @__PURE__ */ React.createElement(Chessboard.Content, null, /* @__PURE__ */ React.createElement(Chessboard.Board, {
45
- classNames: "m-4 rounded-sm overflow-hidden",
46
- orientation
47
- })), open && /* @__PURE__ */ React.createElement("div", {
48
- className: "hidden @3xl:flex flex-col p-8 justify-center items-center overflow-hidden"
49
- }, /* @__PURE__ */ React.createElement(Chessboard.Info, {
50
- orientation,
51
- min: 8,
52
- max: 8,
53
- onOrientationChange: setOrientation,
54
- onClose: () => setOpen(false),
55
- onSelect: handleSelect
56
- })))));
57
- } finally {
58
- _effect.f();
59
- }
60
- };
61
-
62
- // src/components/ChessboardContainer.tsx
63
- var ChessboardContainer = ({ game, role }) => {
64
- var _effect = _useSignals2();
65
- try {
66
- const space = getSpace(game);
67
- if (!space) {
68
- return null;
69
- }
70
- switch (role) {
71
- case "card--popover":
72
- case "card--intrinsic":
73
- case "card--extrinsic": {
74
- return /* @__PURE__ */ React2.createElement(Chessboard.Root, {
75
- game
76
- }, /* @__PURE__ */ React2.createElement(Chessboard.Content, {
77
- role
78
- }, /* @__PURE__ */ React2.createElement(Chessboard.Board, null)));
79
- }
80
- default: {
81
- return /* @__PURE__ */ React2.createElement(ChessboardArticle, {
82
- game,
83
- role
84
- });
85
- }
86
- }
87
- } finally {
88
- _effect.f();
89
- }
90
- };
91
- var ChessboardContainer_default = ChessboardContainer;
92
- export {
93
- ChessboardContainer,
94
- ChessboardContainer_default as default
95
- };
96
- //# sourceMappingURL=ChessboardContainer-5YXEM4VR.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/ChessboardContainer.tsx", "../../../src/components/ChessboardArticle.tsx"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport React from 'react';\n\nimport { getSpace } from '@dxos/react-client/echo';\n\nimport { type Chess } from '../types';\n\nimport { Chessboard } from './Chessboard';\nimport { ChessboardArticle } from './ChessboardArticle';\n\nexport type ChessboardContainerProps = {\n game: Chess.Game;\n role?: string;\n};\n\nexport const ChessboardContainer = ({ game, role }: ChessboardContainerProps) => {\n const space = getSpace(game);\n if (!space) {\n return null;\n }\n\n switch (role) {\n case 'card--popover':\n case 'card--intrinsic':\n case 'card--extrinsic': {\n return (\n <Chessboard.Root game={game}>\n <Chessboard.Content role={role}>\n <Chessboard.Board />\n </Chessboard.Content>\n </Chessboard.Root>\n );\n }\n\n default: {\n return <ChessboardArticle game={game} role={role} />;\n }\n }\n};\n\nexport default ChessboardContainer;\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { useCallback, useRef, useState } from 'react';\n\nimport { Toolbar, useTranslation } from '@dxos/react-ui';\nimport { type Player } from '@dxos/react-ui-gameboard';\nimport { StackItem } from '@dxos/react-ui-stack';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { meta } from '../meta';\nimport { type Chess } from '../types';\n\nimport { Chessboard, type ChessboardController, type ChessboardInfoProps } from './Chessboard';\n\nexport const ChessboardArticle = ({ game, role }: { game: Chess.Game; role?: string }) => {\n const { t } = useTranslation(meta.id);\n const [orientation, setOrientation] = useState<Player>('white');\n const [open, setOpen] = useState(true);\n const controller = useRef<ChessboardController>(null);\n\n // TODO(burdon): Keyboard handler.\n const handleSelect = useCallback<NonNullable<ChessboardInfoProps['onSelect']>>((index) => {\n controller.current?.setMoveNumber(index);\n }, []);\n\n return (\n <StackItem.Content toolbar classNames='@container'>\n <Chessboard.Root game={game} ref={controller}>\n <Toolbar.Root>\n <Toolbar.IconButton\n icon='ph--info--regular'\n iconOnly\n label={t('toggle info button')}\n disabled={open}\n classNames={mx('invisible @3xl:visible')}\n onClick={() => setOpen((open) => !open)}\n />\n </Toolbar.Root>\n <div\n className={mx(\n 'grid bs-full is-full gap-2',\n open && '@3xl:grid-cols-[1fr_320px]',\n role === 'section' && 'aspect-square',\n role === 'section' && open && '@3xl:aspect-auto',\n )}\n >\n <Chessboard.Content>\n <Chessboard.Board classNames='m-4 rounded-sm overflow-hidden' orientation={orientation} />\n </Chessboard.Content>\n {open && (\n <div className='hidden @3xl:flex flex-col p-8 justify-center items-center overflow-hidden'>\n <Chessboard.Info\n orientation={orientation}\n min={8}\n max={8}\n onOrientationChange={setOrientation}\n onClose={() => setOpen(false)}\n onSelect={handleSelect}\n />\n </div>\n )}\n </div>\n </Chessboard.Root>\n </StackItem.Content>\n );\n};\n"],
5
- "mappings": ";;;;;;;;;AAIA,OAAOA,YAAW;AAElB,SAASC,gBAAgB;;;;ACFzB,OAAOC,SAASC,aAAaC,QAAQC,gBAAgB;AAErD,SAASC,SAASC,sBAAsB;AAExC,SAASC,iBAAiB;AAC1B,SAASC,UAAU;AAOZ,IAAMC,oBAAoB,CAAC,EAAEC,MAAMC,KAAI,MAAuC;;;AACnF,UAAM,EAAEC,EAAC,IAAKC,eAAeC,KAAKC,EAAE;AACpC,UAAM,CAACC,aAAaC,cAAAA,IAAkBC,SAAiB,OAAA;AACvD,UAAM,CAACC,MAAMC,OAAAA,IAAWF,SAAS,IAAA;AACjC,UAAMG,aAAaC,OAA6B,IAAA;AAGhD,UAAMC,eAAeC,YAA0D,CAACC,UAAAA;AAC9EJ,iBAAWK,SAASC,cAAcF,KAAAA;IACpC,GAAG,CAAA,CAAE;AAEL,WACE,sBAAA,cAACG,UAAUC,SAAO;MAACC,SAAAA;MAAQC,YAAW;OACpC,sBAAA,cAACC,WAAWC,MAAI;MAACvB;MAAYwB,KAAKb;OAChC,sBAAA,cAACc,QAAQF,MAAI,MACX,sBAAA,cAACE,QAAQC,YAAU;MACjBC,MAAK;MACLC,UAAAA;MACAC,OAAO3B,EAAE,oBAAA;MACT4B,UAAUrB;MACVY,YAAYU,GAAG,wBAAA;MACfC,SAAS,MAAMtB,QAAQ,CAACD,UAAS,CAACA,KAAAA;SAGtC,sBAAA,cAACwB,OAAAA;MACCC,WAAWH,GACT,8BACAtB,QAAQ,8BACRR,SAAS,aAAa,iBACtBA,SAAS,aAAaQ,QAAQ,kBAAA;OAGhC,sBAAA,cAACa,WAAWH,SAAO,MACjB,sBAAA,cAACG,WAAWa,OAAK;MAACd,YAAW;MAAiCf;SAE/DG,QACC,sBAAA,cAACwB,OAAAA;MAAIC,WAAU;OACb,sBAAA,cAACZ,WAAWc,MAAI;MACd9B;MACA+B,KAAK;MACLC,KAAK;MACLC,qBAAqBhC;MACrBiC,SAAS,MAAM9B,QAAQ,KAAA;MACvB+B,UAAU5B;;;;;AAQ1B;;;ADjDO,IAAM6B,sBAAsB,CAAC,EAAEC,MAAMC,KAAI,MAA4B;;;AAC1E,UAAMC,QAAQC,SAASH,IAAAA;AACvB,QAAI,CAACE,OAAO;AACV,aAAO;IACT;AAEA,YAAQD,MAAAA;MACN,KAAK;MACL,KAAK;MACL,KAAK,mBAAmB;AACtB,eACE,gBAAAG,OAAA,cAACC,WAAWC,MAAI;UAACN;WACf,gBAAAI,OAAA,cAACC,WAAWE,SAAO;UAACN;WAClB,gBAAAG,OAAA,cAACC,WAAWG,OAAK,IAAA,CAAA,CAAA;MAIzB;MAEA,SAAS;AACP,eAAO,gBAAAJ,OAAA,cAACK,mBAAAA;UAAkBT;UAAYC;;MACxC;IACF;;;;AACF;AAEA,IAAA,8BAAeF;",
6
- "names": ["React", "getSpace", "React", "useCallback", "useRef", "useState", "Toolbar", "useTranslation", "StackItem", "mx", "ChessboardArticle", "game", "role", "t", "useTranslation", "meta", "id", "orientation", "setOrientation", "useState", "open", "setOpen", "controller", "useRef", "handleSelect", "useCallback", "index", "current", "setMoveNumber", "StackItem", "Content", "toolbar", "classNames", "Chessboard", "Root", "ref", "Toolbar", "IconButton", "icon", "iconOnly", "label", "disabled", "mx", "onClick", "div", "className", "Board", "Info", "min", "max", "onOrientationChange", "onClose", "onSelect", "ChessboardContainer", "game", "role", "space", "getSpace", "React", "Chessboard", "Root", "Content", "Board", "ChessboardArticle"]
7
- }
@@ -1,11 +0,0 @@
1
- import {
2
- CHESS_BLUEPRINT_KEY,
3
- blueprint_definition_default
4
- } from "./chunk-3LPE2B5J.mjs";
5
- import "./chunk-CCF24VRU.mjs";
6
- import "./chunk-DUO4WTAM.mjs";
7
- export {
8
- CHESS_BLUEPRINT_KEY,
9
- blueprint_definition_default as default
10
- };
11
- //# sourceMappingURL=blueprint-definition-Y5Y4YGNL.mjs.map