@dxos/plugin-chess 0.8.4-main.67995b8 → 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.
Files changed (221) hide show
  1. package/dist/lib/browser/ChessArticle-UDSL3OJ4.mjs +59 -0
  2. package/dist/lib/browser/ChessArticle-UDSL3OJ4.mjs.map +7 -0
  3. package/dist/lib/browser/ChessCard-OIRFQMOJ.mjs +21 -0
  4. package/dist/lib/browser/ChessCard-OIRFQMOJ.mjs.map +7 -0
  5. package/dist/lib/browser/blueprint-definition-LWRZPLQL.mjs +18 -0
  6. package/dist/lib/browser/blueprint-definition-LWRZPLQL.mjs.map +7 -0
  7. package/dist/lib/browser/blueprints/index.mjs +11 -0
  8. package/dist/lib/browser/blueprints/index.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
  10. package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
  11. package/dist/lib/browser/chunk-JP6G6VR6.mjs +276 -0
  12. package/dist/lib/browser/chunk-JP6G6VR6.mjs.map +7 -0
  13. package/dist/lib/browser/chunk-RGHZ5CDO.mjs +21 -0
  14. package/dist/lib/browser/chunk-RGHZ5CDO.mjs.map +7 -0
  15. package/dist/lib/browser/chunk-VK2W2UDJ.mjs +231 -0
  16. package/dist/lib/browser/chunk-VK2W2UDJ.mjs.map +7 -0
  17. package/dist/lib/browser/chunk-WYUTI2K4.mjs +1 -0
  18. package/dist/lib/browser/chunk-WYUTI2K4.mjs.map +7 -0
  19. package/dist/lib/browser/chunk-YJ2NLHEY.mjs +64 -0
  20. package/dist/lib/browser/chunk-YJ2NLHEY.mjs.map +7 -0
  21. package/dist/lib/browser/cli/index.mjs +28 -0
  22. package/dist/lib/browser/cli/index.mjs.map +7 -0
  23. package/dist/lib/browser/index.mjs +62 -66
  24. package/dist/lib/browser/index.mjs.map +4 -4
  25. package/dist/lib/browser/meta.json +1 -1
  26. package/dist/lib/browser/react-surface-M7QMAFTB.mjs +50 -0
  27. package/dist/lib/browser/react-surface-M7QMAFTB.mjs.map +7 -0
  28. package/dist/lib/browser/types/index.mjs +4 -7
  29. package/dist/lib/node-esm/ChessArticle-76MOXLJM.mjs +60 -0
  30. package/dist/lib/node-esm/ChessArticle-76MOXLJM.mjs.map +7 -0
  31. package/dist/lib/node-esm/ChessCard-TKNQP6IO.mjs +22 -0
  32. package/dist/lib/node-esm/ChessCard-TKNQP6IO.mjs.map +7 -0
  33. package/dist/lib/node-esm/blueprint-definition-CJZXRDEQ.mjs +19 -0
  34. package/dist/lib/node-esm/blueprint-definition-CJZXRDEQ.mjs.map +7 -0
  35. package/dist/lib/node-esm/blueprints/index.mjs +12 -0
  36. package/dist/lib/node-esm/blueprints/index.mjs.map +7 -0
  37. package/dist/lib/node-esm/chunk-7XDEO6IJ.mjs +2 -0
  38. package/dist/lib/node-esm/chunk-7XDEO6IJ.mjs.map +7 -0
  39. package/dist/lib/node-esm/chunk-FK7NVSOG.mjs +277 -0
  40. package/dist/lib/node-esm/chunk-FK7NVSOG.mjs.map +7 -0
  41. package/dist/lib/node-esm/chunk-FYPVCMP4.mjs +23 -0
  42. package/dist/lib/node-esm/chunk-FYPVCMP4.mjs.map +7 -0
  43. package/dist/lib/node-esm/chunk-G3QQRYZC.mjs +232 -0
  44. package/dist/lib/node-esm/chunk-G3QQRYZC.mjs.map +7 -0
  45. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  46. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
  47. package/dist/lib/node-esm/chunk-J6AJLY2O.mjs +65 -0
  48. package/dist/lib/node-esm/chunk-J6AJLY2O.mjs.map +7 -0
  49. package/dist/lib/node-esm/cli/index.mjs +29 -0
  50. package/dist/lib/node-esm/cli/index.mjs.map +7 -0
  51. package/dist/lib/node-esm/index.mjs +62 -66
  52. package/dist/lib/node-esm/index.mjs.map +4 -4
  53. package/dist/lib/node-esm/meta.json +1 -1
  54. package/dist/lib/node-esm/react-surface-DKM6ICBU.mjs +51 -0
  55. package/dist/lib/node-esm/react-surface-DKM6ICBU.mjs.map +7 -0
  56. package/dist/lib/node-esm/types/index.mjs +4 -7
  57. package/dist/types/src/ChessPlugin.d.ts +2 -1
  58. package/dist/types/src/ChessPlugin.d.ts.map +1 -1
  59. package/dist/types/src/blueprints/chess-blueprint.d.ts +4 -0
  60. package/dist/types/src/blueprints/chess-blueprint.d.ts.map +1 -0
  61. package/dist/types/src/blueprints/functions/create.d.ts +15 -0
  62. package/dist/types/src/blueprints/functions/create.d.ts.map +1 -0
  63. package/dist/types/src/blueprints/functions/index.d.ts +56 -0
  64. package/dist/types/src/blueprints/functions/index.d.ts.map +1 -0
  65. package/dist/types/src/blueprints/functions/move.d.ts +16 -0
  66. package/dist/types/src/blueprints/functions/move.d.ts.map +1 -0
  67. package/dist/types/src/blueprints/functions/play.d.ts +17 -0
  68. package/dist/types/src/blueprints/functions/play.d.ts.map +1 -0
  69. package/dist/types/src/blueprints/functions/print.d.ts +8 -0
  70. package/dist/types/src/blueprints/functions/print.d.ts.map +1 -0
  71. package/dist/types/src/blueprints/index.d.ts +3 -0
  72. package/dist/types/src/blueprints/index.d.ts.map +1 -0
  73. package/dist/types/src/capabilities/artifact-definition/artifact-definition.d.ts +12 -0
  74. package/dist/types/src/capabilities/artifact-definition/artifact-definition.d.ts.map +1 -0
  75. package/dist/types/src/capabilities/artifact-definition/index.d.ts +3 -0
  76. package/dist/types/src/capabilities/artifact-definition/index.d.ts.map +1 -0
  77. package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts +6 -0
  78. package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts.map +1 -0
  79. package/dist/types/src/capabilities/blueprint-definition/index.d.ts +3 -0
  80. package/dist/types/src/capabilities/blueprint-definition/index.d.ts.map +1 -0
  81. package/dist/types/src/capabilities/index.d.ts +2 -3
  82. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  83. package/dist/types/src/capabilities/react-surface/index.d.ts +3 -0
  84. package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -0
  85. package/dist/types/src/capabilities/react-surface/react-surface.d.ts +5 -0
  86. package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -0
  87. package/dist/types/src/cli/index.d.ts +2 -0
  88. package/dist/types/src/cli/index.d.ts.map +1 -0
  89. package/dist/types/src/cli/plugin.d.ts +3 -0
  90. package/dist/types/src/cli/plugin.d.ts.map +1 -0
  91. package/dist/types/src/components/Chessboard/Chessboard.d.ts +34 -0
  92. package/dist/types/src/components/Chessboard/Chessboard.d.ts.map +1 -0
  93. package/dist/types/src/components/Chessboard/Info.d.ts +21 -0
  94. package/dist/types/src/components/Chessboard/Info.d.ts.map +1 -0
  95. package/dist/types/src/components/Chessboard/index.d.ts +2 -0
  96. package/dist/types/src/components/Chessboard/index.d.ts.map +1 -0
  97. package/dist/types/src/components/Chessboard/types.d.ts +8 -0
  98. package/dist/types/src/components/Chessboard/types.d.ts.map +1 -0
  99. package/dist/types/src/components/index.d.ts +1 -5
  100. package/dist/types/src/components/index.d.ts.map +1 -1
  101. package/dist/types/src/containers/ChessArticle/ChessArticle.d.ts +6 -0
  102. package/dist/types/src/containers/ChessArticle/ChessArticle.d.ts.map +1 -0
  103. package/dist/types/src/containers/ChessArticle/ChessArticle.stories.d.ts +47 -0
  104. package/dist/types/src/containers/ChessArticle/ChessArticle.stories.d.ts.map +1 -0
  105. package/dist/types/src/containers/ChessArticle/index.d.ts +3 -0
  106. package/dist/types/src/containers/ChessArticle/index.d.ts.map +1 -0
  107. package/dist/types/src/containers/ChessCard/ChessCard.d.ts +6 -0
  108. package/dist/types/src/containers/ChessCard/ChessCard.d.ts.map +1 -0
  109. package/dist/types/src/containers/ChessCard/ChessCard.stories.d.ts +15 -0
  110. package/dist/types/src/containers/ChessCard/ChessCard.stories.d.ts.map +1 -0
  111. package/dist/types/src/containers/ChessCard/index.d.ts +3 -0
  112. package/dist/types/src/containers/ChessCard/index.d.ts.map +1 -0
  113. package/dist/types/src/containers/index.d.ts +4 -0
  114. package/dist/types/src/containers/index.d.ts.map +1 -0
  115. package/dist/types/src/index.d.ts +3 -1
  116. package/dist/types/src/index.d.ts.map +1 -1
  117. package/dist/types/src/meta.d.ts +2 -3
  118. package/dist/types/src/meta.d.ts.map +1 -1
  119. package/dist/types/src/translations.d.ts +12 -2
  120. package/dist/types/src/translations.d.ts.map +1 -1
  121. package/dist/types/src/types/Chess.d.ts +27 -0
  122. package/dist/types/src/types/Chess.d.ts.map +1 -0
  123. package/dist/types/src/types/index.d.ts +1 -2
  124. package/dist/types/src/types/index.d.ts.map +1 -1
  125. package/dist/types/tsconfig.tsbuildinfo +1 -1
  126. package/package.json +63 -38
  127. package/src/ChessPlugin.tsx +26 -52
  128. package/src/blueprints/chess-blueprint.ts +36 -0
  129. package/src/blueprints/functions/create.ts +38 -0
  130. package/src/blueprints/functions/index.ts +17 -0
  131. package/src/blueprints/functions/move.ts +48 -0
  132. package/src/blueprints/functions/play.ts +58 -0
  133. package/src/blueprints/functions/print.ts +42 -0
  134. package/src/blueprints/index.ts +6 -0
  135. package/src/capabilities/artifact-definition/artifact-definition.ts +135 -0
  136. package/src/capabilities/artifact-definition/index.ts +7 -0
  137. package/src/capabilities/blueprint-definition/blueprint-definition.ts +17 -0
  138. package/src/capabilities/blueprint-definition/index.ts +7 -0
  139. package/src/capabilities/index.ts +2 -5
  140. package/src/capabilities/react-surface/index.ts +7 -0
  141. package/src/capabilities/react-surface/react-surface.tsx +33 -0
  142. package/src/cli/index.ts +5 -0
  143. package/src/cli/plugin.ts +26 -0
  144. package/src/components/Chessboard/Chessboard.tsx +186 -0
  145. package/src/components/Chessboard/Info.tsx +246 -0
  146. package/src/components/Chessboard/index.ts +5 -0
  147. package/src/components/Chessboard/types.ts +18 -0
  148. package/src/components/index.ts +2 -6
  149. package/src/containers/ChessArticle/ChessArticle.stories.tsx +53 -0
  150. package/src/containers/ChessArticle/ChessArticle.tsx +72 -0
  151. package/src/containers/ChessArticle/index.ts +7 -0
  152. package/src/containers/ChessCard/ChessCard.stories.tsx +42 -0
  153. package/src/containers/ChessCard/ChessCard.tsx +22 -0
  154. package/src/containers/ChessCard/index.ts +7 -0
  155. package/src/containers/index.ts +8 -0
  156. package/src/index.ts +3 -1
  157. package/src/meta.ts +9 -7
  158. package/src/translations.ts +12 -2
  159. package/src/types/Chess.ts +58 -0
  160. package/src/types/index.ts +1 -2
  161. package/dist/lib/browser/ChessContainer-SC4ZV6XZ.mjs +0 -129
  162. package/dist/lib/browser/ChessContainer-SC4ZV6XZ.mjs.map +0 -7
  163. package/dist/lib/browser/artifact-definition-A2FSM255.mjs +0 -182
  164. package/dist/lib/browser/artifact-definition-A2FSM255.mjs.map +0 -7
  165. package/dist/lib/browser/chunk-A3WEUKPK.mjs +0 -61
  166. package/dist/lib/browser/chunk-A3WEUKPK.mjs.map +0 -7
  167. package/dist/lib/browser/chunk-KDADGLPC.mjs +0 -8
  168. package/dist/lib/browser/chunk-KDADGLPC.mjs.map +0 -7
  169. package/dist/lib/browser/chunk-ZXH3N4NA.mjs +0 -66
  170. package/dist/lib/browser/chunk-ZXH3N4NA.mjs.map +0 -7
  171. package/dist/lib/browser/intent-resolver-KQYYX44R.mjs +0 -28
  172. package/dist/lib/browser/intent-resolver-KQYYX44R.mjs.map +0 -7
  173. package/dist/lib/browser/react-surface-PLUCWIYP.mjs +0 -36
  174. package/dist/lib/browser/react-surface-PLUCWIYP.mjs.map +0 -7
  175. package/dist/lib/node-esm/ChessContainer-7GLY5KLY.mjs +0 -130
  176. package/dist/lib/node-esm/ChessContainer-7GLY5KLY.mjs.map +0 -7
  177. package/dist/lib/node-esm/artifact-definition-2H7OUBZO.mjs +0 -183
  178. package/dist/lib/node-esm/artifact-definition-2H7OUBZO.mjs.map +0 -7
  179. package/dist/lib/node-esm/chunk-27D3JA3K.mjs +0 -68
  180. package/dist/lib/node-esm/chunk-27D3JA3K.mjs.map +0 -7
  181. package/dist/lib/node-esm/chunk-IS3Y25PL.mjs +0 -63
  182. package/dist/lib/node-esm/chunk-IS3Y25PL.mjs.map +0 -7
  183. package/dist/lib/node-esm/chunk-QFINI7CC.mjs +0 -10
  184. package/dist/lib/node-esm/chunk-QFINI7CC.mjs.map +0 -7
  185. package/dist/lib/node-esm/intent-resolver-GXK2JROQ.mjs +0 -29
  186. package/dist/lib/node-esm/intent-resolver-GXK2JROQ.mjs.map +0 -7
  187. package/dist/lib/node-esm/react-surface-NGLNIWN3.mjs +0 -37
  188. package/dist/lib/node-esm/react-surface-NGLNIWN3.mjs.map +0 -7
  189. package/dist/types/src/capabilities/artifact-definition.d.ts +0 -11
  190. package/dist/types/src/capabilities/artifact-definition.d.ts.map +0 -1
  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/capabilities/react-surface.d.ts +0 -4
  194. package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
  195. package/dist/types/src/components/Chess.d.ts +0 -14
  196. package/dist/types/src/components/Chess.d.ts.map +0 -1
  197. package/dist/types/src/components/ChessContainer.d.ts +0 -8
  198. package/dist/types/src/components/ChessContainer.d.ts.map +0 -1
  199. package/dist/types/src/components/ChessContainer.stories.d.ts +0 -23
  200. package/dist/types/src/components/ChessContainer.stories.d.ts.map +0 -1
  201. package/dist/types/src/components/ChessPanel.d.ts +0 -11
  202. package/dist/types/src/components/ChessPanel.d.ts.map +0 -1
  203. package/dist/types/src/components/Chessboard.stories.d.ts +0 -8
  204. package/dist/types/src/components/Chessboard.stories.d.ts.map +0 -1
  205. package/dist/types/src/components/PlayerSelector.d.ts +0 -8
  206. package/dist/types/src/components/PlayerSelector.d.ts.map +0 -1
  207. package/dist/types/src/types/schema.d.ts +0 -29
  208. package/dist/types/src/types/schema.d.ts.map +0 -1
  209. package/dist/types/src/types/types.d.ts +0 -32
  210. package/dist/types/src/types/types.d.ts.map +0 -1
  211. package/src/capabilities/artifact-definition.ts +0 -124
  212. package/src/capabilities/intent-resolver.ts +0 -26
  213. package/src/capabilities/react-surface.tsx +0 -23
  214. package/src/components/Chess.tsx +0 -60
  215. package/src/components/ChessContainer.stories.tsx +0 -110
  216. package/src/components/ChessContainer.tsx +0 -71
  217. package/src/components/ChessPanel.tsx +0 -67
  218. package/src/components/Chessboard.stories.tsx +0 -41
  219. package/src/components/PlayerSelector.tsx +0 -82
  220. package/src/types/schema.ts +0 -34
  221. package/src/types/types.ts +0 -20
@@ -0,0 +1,33 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Effect from 'effect/Effect';
6
+ import React from 'react';
7
+
8
+ import { Capabilities, Capability } from '@dxos/app-framework';
9
+ import { Surface } from '@dxos/app-framework/ui';
10
+ import { Obj } from '@dxos/echo';
11
+
12
+ import { ChessArticle, ChessCard } from '../../containers';
13
+ import { meta } from '../../meta';
14
+ import { Chess } from '../../types';
15
+
16
+ export default Capability.makeModule(() =>
17
+ Effect.succeed(
18
+ Capability.contributes(Capabilities.ReactSurface, [
19
+ Surface.create({
20
+ id: meta.id,
21
+ role: ['article', 'section'],
22
+ filter: (data): data is { subject: Chess.Game } => Obj.instanceOf(Chess.Game, data.subject),
23
+ component: ({ data, role }) => <ChessArticle role={role} subject={data.subject} />,
24
+ }),
25
+ Surface.create({
26
+ id: meta.id,
27
+ role: ['card--content'],
28
+ filter: (data): data is { subject: Chess.Game } => Obj.instanceOf(Chess.Game, data.subject),
29
+ component: ({ data, role }) => <ChessCard role={role} subject={data.subject} />,
30
+ }),
31
+ ]),
32
+ ),
33
+ );
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * from './plugin';
@@ -0,0 +1,26 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Effect from 'effect/Effect';
6
+
7
+ import { Plugin } from '@dxos/app-framework';
8
+ import { AppPlugin } from '@dxos/app-toolkit';
9
+ import { type CreateObject } from '@dxos/plugin-space/types';
10
+
11
+ import { meta } from '../meta';
12
+ import { Chess } from '../types';
13
+
14
+ // TODO(wittjosiah): Factor out shared modules.
15
+ export const ChessPlugin = Plugin.define(meta).pipe(
16
+ AppPlugin.addMetadataModule({
17
+ metadata: {
18
+ id: Chess.Game.typename,
19
+ metadata: {
20
+ createObject: ((props) => Effect.sync(() => Chess.make(props))) satisfies CreateObject,
21
+ },
22
+ },
23
+ }),
24
+ AppPlugin.addSchemaModule({ schema: [Chess.Game] }),
25
+ Plugin.make,
26
+ );
@@ -0,0 +1,186 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { RegistryContext } from '@effect-atom/atom-react';
6
+ import React, {
7
+ type PropsWithChildren,
8
+ forwardRef,
9
+ useCallback,
10
+ useContext,
11
+ useEffect,
12
+ useImperativeHandle,
13
+ useMemo,
14
+ useRef,
15
+ } from 'react';
16
+
17
+ import { addEventListener } from '@dxos/async';
18
+ import { useObject } from '@dxos/echo-react';
19
+ import { type ThemedClassName } from '@dxos/react-ui';
20
+ import {
21
+ type ChessModel,
22
+ Gameboard,
23
+ type GameboardRootProps,
24
+ Chessboard as NaturalChessboard,
25
+ type ChessboardProps as NaturalChessboardProps,
26
+ getRawPgn,
27
+ useGameboardContext,
28
+ } from '@dxos/react-ui-gameboard';
29
+ import { useSoundEffect } from '@dxos/react-ui-sfx';
30
+ import { mx } from '@dxos/ui-theme';
31
+
32
+ import { type Chess } from '../../types';
33
+
34
+ import { Info, type InfoProps } from './Info';
35
+ import { ExtendedChessModel } from './types';
36
+
37
+ export interface ChessboardController {
38
+ setMoveNumber(index: number): void;
39
+ }
40
+
41
+ //
42
+ // Root
43
+ //
44
+
45
+ type RootProps = PropsWithChildren<{
46
+ game: Chess.Game;
47
+ }>;
48
+
49
+ const Root = forwardRef<ChessboardController, RootProps>(({ game, children }, forwardedRef) => {
50
+ const registry = useContext(RegistryContext);
51
+ const model = useMemo(() => new ExtendedChessModel(registry, game), [registry]);
52
+ const click = useSoundEffect('Click');
53
+ const [pgn, updatePgn] = useObject(game, 'pgn');
54
+
55
+ // Controller.
56
+ useImperativeHandle(forwardedRef, () => {
57
+ return {
58
+ setMoveNumber: (index) => model.setMoveIndex(index),
59
+ };
60
+ }, [model]);
61
+
62
+ // TODO(wittjosiah): Rather than useEffect to sync ECHO object to model, create an alternative model implementation.
63
+ // This model would take the ECHO object and derive game state directly from that.
64
+ // Mutation methods would mutate the ECHO object and other state would be derived from that.
65
+
66
+ // External change.
67
+ // NOTE: Warning if user has not interacted with the board.
68
+ useEffect(() => {
69
+ if (model.pgn !== getRawPgn(pgn ?? '')) {
70
+ const silent = model.pgn === '*';
71
+ model.update(pgn);
72
+ if (!silent) {
73
+ void click.play();
74
+ }
75
+ }
76
+ }, [pgn]);
77
+
78
+ // Move.
79
+ const handleDrop = useCallback<NonNullable<GameboardRootProps<ChessModel>['onDrop']>>(
80
+ (move) => {
81
+ if (!model.makeMove(move)) {
82
+ return false;
83
+ }
84
+
85
+ void click.play();
86
+ updatePgn(() => model.pgn);
87
+ return true;
88
+ },
89
+ [model],
90
+ );
91
+
92
+ return (
93
+ <Gameboard.Root model={model} onDrop={handleDrop}>
94
+ {children}
95
+ </Gameboard.Root>
96
+ );
97
+ });
98
+
99
+ //
100
+ // Content
101
+ //
102
+
103
+ type Role = 'card--content';
104
+
105
+ type ContentProps = ThemedClassName<PropsWithChildren<{ role?: Role }>>;
106
+
107
+ const Content = ({ classNames, children, role }: ContentProps) => {
108
+ return (
109
+ <Gameboard.Content
110
+ classNames={mx(
111
+ classNames,
112
+ role === 'card--content' ? 'dx-size-container dx-card-square' : 'flex flex-col justify-center',
113
+ )}
114
+ >
115
+ {children}
116
+ </Gameboard.Content>
117
+ );
118
+ };
119
+
120
+ //
121
+ // Board
122
+ //
123
+
124
+ const BOARD_NAME = 'Chessboard.Board';
125
+
126
+ type BoardProps = NaturalChessboardProps;
127
+
128
+ const Board = (props: BoardProps) => {
129
+ const registry = useContext(RegistryContext);
130
+ const { model } = useGameboardContext<ChessModel>(BOARD_NAME);
131
+
132
+ // Keyboard navigation.
133
+ const ref = useRef<HTMLDivElement>(null);
134
+ useEffect(() => {
135
+ if (!ref.current) {
136
+ return;
137
+ }
138
+
139
+ // Participate in keyboard navigation (set tabIndex={0})
140
+ ref.current.setAttribute('data-arrow-keys', 'all');
141
+
142
+ return addEventListener(ref.current, 'keydown', (ev) => {
143
+ const moveIndex = registry.get(model.moveIndex);
144
+ switch (ev.key) {
145
+ case 'ArrowUp':
146
+ model.setMoveIndex(0);
147
+ break;
148
+ case 'ArrowDown':
149
+ model.setMoveIndex(model.game.history().length);
150
+ break;
151
+ case 'ArrowLeft':
152
+ if (moveIndex > 0) {
153
+ model.setMoveIndex(moveIndex - 1);
154
+ }
155
+ break;
156
+ case 'ArrowRight':
157
+ if (moveIndex < model.game.history().length) {
158
+ model.setMoveIndex(moveIndex + 1);
159
+ }
160
+ break;
161
+ }
162
+ });
163
+ }, [registry, model]);
164
+
165
+ return <NaturalChessboard {...props} ref={ref} />;
166
+ };
167
+
168
+ Board.displayName = BOARD_NAME;
169
+
170
+ //
171
+ // Chessboard
172
+ //
173
+
174
+ export const Chessboard = {
175
+ Root: Root,
176
+ Content: Content,
177
+ Board: Board,
178
+ Info: Info,
179
+ };
180
+
181
+ export type {
182
+ RootProps as ChessboardRootProps,
183
+ ContentProps as ChessboardContentProps,
184
+ BoardProps as ChessboardBoardProps,
185
+ InfoProps as ChessboardInfoProps,
186
+ };
@@ -0,0 +1,246 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { useAtomValue } from '@effect-atom/atom-react';
6
+ import React, { type JSX, type PropsWithChildren, useEffect, useMemo, useRef } from 'react';
7
+
8
+ import { generateName } from '@dxos/display-name';
9
+ import { Obj } from '@dxos/echo';
10
+ import { type SpaceMember, useMembers } from '@dxos/react-client/echo';
11
+ import { Icon, IconButton, Select, type ThemedClassName, useTranslation } from '@dxos/react-ui';
12
+ import { type Player, useGameboardContext } from '@dxos/react-ui-gameboard';
13
+ import { mx } from '@dxos/ui-theme';
14
+
15
+ import { meta } from '../../meta';
16
+
17
+ import { type ExtendedChessModel } from './types';
18
+
19
+ const INFO_NAME = 'Chessboard.Info';
20
+
21
+ export type InfoProps = ThemedClassName<
22
+ {
23
+ orientation?: Player;
24
+ onOrientationChange?: (orientation: Player) => void;
25
+ onClose?: () => void;
26
+ } & Pick<HistoryProps, 'min' | 'max' | 'onSelect'>
27
+ >;
28
+
29
+ export const Info = ({ classNames, orientation = 'white', onOrientationChange, onClose, ...props }: InfoProps) => {
30
+ const { t } = useTranslation(meta.id);
31
+ const { model } = useGameboardContext<ExtendedChessModel>(INFO_NAME);
32
+ const db = Obj.getDatabase(model.object);
33
+ const members = useMembers(db?.spaceId);
34
+
35
+ return (
36
+ <div
37
+ className={mx(
38
+ 'grid grid-rows-[min-content_1fr_min-content] w-full min-w-[18rem] p-2 overflow-hidden bg-group-surface rounded-xs',
39
+ classNames,
40
+ )}
41
+ >
42
+ <PlayerIndicator
43
+ model={model}
44
+ player={orientation === 'white' ? 'black' : 'white'}
45
+ icon={
46
+ onClose && (
47
+ <IconButton icon='ph--x--regular' iconOnly label={t('close info button')} size={4} onClick={onClose} />
48
+ )
49
+ }
50
+ >
51
+ <PlayerSelector
52
+ value={model.object.players?.[orientation === 'white' ? 'black' : 'white']}
53
+ onValueChange={(value) => {
54
+ Obj.change(model.object, (obj) => {
55
+ obj.players![orientation === 'white' ? 'black' : 'white'] = value;
56
+ });
57
+ }}
58
+ members={members}
59
+ />
60
+ </PlayerIndicator>
61
+
62
+ <History model={model} {...props} />
63
+
64
+ <PlayerIndicator
65
+ model={model}
66
+ player={orientation}
67
+ icon={
68
+ onOrientationChange && (
69
+ <IconButton
70
+ classNames={mx('transition duration-200 ease-linear', orientation === 'white' && 'rotate-180')}
71
+ icon='ph--arrows-clockwise--regular'
72
+ iconOnly
73
+ label={t('flip board button')}
74
+ size={4}
75
+ onClick={() => onOrientationChange(orientation === 'white' ? 'black' : 'white')}
76
+ />
77
+ )
78
+ }
79
+ >
80
+ <PlayerSelector
81
+ value={model.object.players?.[orientation]}
82
+ onValueChange={(value) => {
83
+ Obj.change(model.object, (obj) => {
84
+ obj.players![orientation] = value;
85
+ });
86
+ }}
87
+ members={members}
88
+ />
89
+ </PlayerIndicator>
90
+ </div>
91
+ );
92
+ };
93
+
94
+ Info.displayName = INFO_NAME;
95
+
96
+ //
97
+ // History
98
+ //
99
+
100
+ type HistoryProps = ThemedClassName<{
101
+ model: ExtendedChessModel;
102
+ min?: number;
103
+ max?: number;
104
+ onSelect?: (index: number) => void;
105
+ }>;
106
+
107
+ const History = ({ classNames, model, min, max, onSelect }: HistoryProps) => {
108
+ const { t } = useTranslation(meta.id);
109
+ const moveIndex = useAtomValue(model.moveIndex);
110
+ const label = model.game.isGameOver()
111
+ ? model.game.isCheckmate()
112
+ ? t('game.checkmate label')
113
+ : model.game.isStalemate()
114
+ ? t('game.stalemate label')
115
+ : t('game.draw label')
116
+ : model.game.isCheck()
117
+ ? t('game.check label')
118
+ : undefined;
119
+
120
+ const history = model.game.history();
121
+ const moves = useMemo(
122
+ () =>
123
+ history.reduce(
124
+ (acc, move, index) => {
125
+ if (index % 2 === 0) {
126
+ acc.push([{ index, move }]);
127
+ } else {
128
+ acc[acc.length - 1].push({ index, move });
129
+ }
130
+ return acc;
131
+ },
132
+ [] as { index: number; move: string }[][],
133
+ ),
134
+ [history.length],
135
+ );
136
+
137
+ const scrollerRef = useRef<HTMLDivElement>(null);
138
+ useEffect(() => {
139
+ scrollerRef.current?.scrollTo({ top: scrollerRef.current.scrollHeight });
140
+ }, [history.length]);
141
+
142
+ useEffect(() => {
143
+ const div = scrollerRef.current?.querySelector(`[data-index="${moveIndex - 1}"]`);
144
+ scrollerRef.current?.classList.add('scrollbar-none');
145
+ div?.scrollIntoView({ behavior: 'smooth' });
146
+ scrollerRef.current?.classList.remove('scrollbar-none');
147
+ }, [moveIndex]);
148
+
149
+ return (
150
+ <div
151
+ ref={scrollerRef}
152
+ className={mx('overflow-y-auto', classNames)}
153
+ style={{
154
+ minHeight: min === undefined ? 'auto' : `${min * 24}px`,
155
+ maxHeight: max === undefined ? 'auto' : `${max * 24}px`,
156
+ }}
157
+ >
158
+ {moves.map(([a, b], index) => (
159
+ <div key={index} className='grid grid-cols-[3rem_1fr_1fr_1rem] gap-2 ps-4 leading-1'>
160
+ <div className='content-center text-xs text-subdued'>{index + 1}</div>
161
+ {a && (
162
+ <div
163
+ data-index={a.index}
164
+ className={mx('ps-2 cursor-pointer', a.index === moveIndex - 1 && 'bg-primary-500')}
165
+ onClick={() => onSelect?.(a.index + 1)}
166
+ >
167
+ {a.move}
168
+ </div>
169
+ )}
170
+ {b && (
171
+ <div
172
+ data-index={b.index}
173
+ className={mx('ps-2 cursor-pointer', b.index === moveIndex - 1 && 'bg-primary-500')}
174
+ onClick={() => onSelect?.(b.index + 1)}
175
+ >
176
+ {b.move}
177
+ </div>
178
+ )}
179
+ </div>
180
+ ))}
181
+ {label && <div className='text-center'>{label}</div>}
182
+ </div>
183
+ );
184
+ };
185
+
186
+ //
187
+ // PlayerIndicator
188
+ //
189
+
190
+ type PlayerIndicatorProps = PropsWithChildren<{
191
+ model: ExtendedChessModel;
192
+ player: Player;
193
+ icon?: JSX.Element;
194
+ }>;
195
+
196
+ const PlayerIndicator = ({ children, model, player, icon }: PlayerIndicatorProps) => {
197
+ const turn = player === (model.game.turn() === 'w' ? 'white' : 'black');
198
+ return (
199
+ <div className='grid grid-cols-[2rem_1fr_2rem] gap-2 h-(--dx-rail-size) px-1 flex items-center overflow-hidden'>
200
+ <div className='place-items-center'>
201
+ <Icon
202
+ icon={turn ? 'ph--circle--fill' : 'ph--circle--thin'}
203
+ size={6}
204
+ classNames={mx(turn && (model.game.isCheckmate() ? 'text-error-500' : 'text-success-text'))}
205
+ />
206
+ </div>
207
+ <div className='truncate overflow-hidden items-center'>{children}</div>
208
+ {icon}
209
+ </div>
210
+ );
211
+ };
212
+
213
+ //
214
+ // PlayerSelector
215
+ //
216
+
217
+ type PlayerSelectorProps = {
218
+ value?: string;
219
+ onValueChange: (player: string) => void;
220
+ members: SpaceMember[];
221
+ };
222
+
223
+ const PlayerSelector = ({ value, onValueChange, members }: PlayerSelectorProps) => {
224
+ const { t } = useTranslation(meta.id);
225
+ return (
226
+ <Select.Root value={value} onValueChange={onValueChange}>
227
+ <Select.TriggerButton placeholder={t('select player button')} />
228
+ <Select.Portal>
229
+ <Select.Content>
230
+ <Select.Viewport>
231
+ {members.map((member) => {
232
+ const memberKey = member.identity.identityKey.toHex();
233
+ const displayName = member.identity?.profile?.displayName || generateName(memberKey);
234
+ return (
235
+ <Select.Option key={memberKey} value={memberKey}>
236
+ {displayName}
237
+ </Select.Option>
238
+ );
239
+ })}
240
+ </Select.Viewport>
241
+ <Select.Arrow />
242
+ </Select.Content>
243
+ </Select.Portal>
244
+ </Select.Root>
245
+ );
246
+ };
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ export * from './Chessboard';
@@ -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
+ }
@@ -1,9 +1,5 @@
1
1
  //
2
- // Copyright 2023 DXOS.org
2
+ // Copyright 2026 DXOS.org
3
3
  //
4
4
 
5
- import { lazy } from 'react';
6
-
7
- export * from './Chess';
8
-
9
- export const ChessContainer = lazy(() => import('./ChessContainer'));
5
+ export * from './Chessboard';
@@ -0,0 +1,53 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
6
+ import React, { useMemo } from 'react';
7
+
8
+ import { withClientProvider } from '@dxos/react-client/testing';
9
+ import { withLayout, withTheme } from '@dxos/react-ui/testing';
10
+
11
+ import { translations } from '../../translations';
12
+ import { Chess } from '../../types';
13
+
14
+ import { ChessArticle } from './ChessArticle';
15
+
16
+ type StoryProps = {
17
+ pgn?: string;
18
+ };
19
+
20
+ const DefaultStory = ({ pgn }: StoryProps) => {
21
+ const game = useMemo(() => Chess.make(pgn ? { pgn } : undefined), [pgn]);
22
+ return <ChessArticle subject={game} />;
23
+ };
24
+
25
+ const meta = {
26
+ title: 'plugins/plugin-chess/containers/ChessArticle',
27
+ component: DefaultStory,
28
+ decorators: [withTheme(), withLayout({ layout: 'fullscreen' }), withClientProvider({ createIdentity: true })],
29
+ parameters: {
30
+ layout: 'fullscreen',
31
+ translations,
32
+ },
33
+ } satisfies Meta<typeof DefaultStory>;
34
+
35
+ export default meta;
36
+
37
+ type Story = StoryObj<typeof meta>;
38
+
39
+ export const Default: Story = {
40
+ args: {},
41
+ };
42
+
43
+ export const EndGame: Story = {
44
+ args: {
45
+ pgn: '1. e4 e5 2. Nf3 Nc6 3. Bc4 Bc5 4. c3 Nf6 5. d4 exd4 6. cxd4 Bb4+ 7. Nc3 d5 8. exd5 Nxd5 9. O-O Be6 10. Qb3 Na5 11. Qa4+ c6 12. Bxd5 Bxc3 13. Bxe6 fxe6 *',
46
+ },
47
+ };
48
+
49
+ export const Promption: Story = {
50
+ args: {
51
+ pgn: '1. e4 e5 2. Nf3 Nc6 3. Bc4 Bc5 4. c3 Nf6 5. d4 exd4 6. cxd4 Bb4+ 7. Nc3 d5 8. exd5 Nxd5 9. O-O Be6 10. Qb3 Na5 11. Qa4+ c6 12. Bxd5 Bxc3 13. Bxe6 fxe6 14. d5 Qg5 15. dxe6 Qg4 16. e7 Kf7 17. bxc3 Kg6 *',
52
+ },
53
+ };
@@ -0,0 +1,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
+ };
@@ -0,0 +1,7 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import { ChessArticle } from './ChessArticle';
6
+
7
+ export default ChessArticle;