@dxos/plugin-chess 0.8.4-main.3c1ae3b → 0.8.4-main.3eb6e50203

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 (180) hide show
  1. package/dist/lib/browser/ChessboardContainer-GNSIZKY7.mjs +80 -0
  2. package/dist/lib/browser/ChessboardContainer-GNSIZKY7.mjs.map +7 -0
  3. package/dist/lib/browser/blueprint-definition-YUKJZPOL.mjs +19 -0
  4. package/dist/lib/browser/blueprint-definition-YUKJZPOL.mjs.map +7 -0
  5. package/dist/lib/browser/blueprints/index.mjs +11 -0
  6. package/dist/lib/browser/{chunk-CCF24VRU.mjs → chunk-66H3V2YV.mjs} +10 -29
  7. package/dist/lib/browser/chunk-66H3V2YV.mjs.map +7 -0
  8. package/dist/lib/browser/{chunk-DUO4WTAM.mjs → chunk-H3NUMCQ6.mjs} +1 -8
  9. package/dist/lib/browser/chunk-H3NUMCQ6.mjs.map +7 -0
  10. package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
  11. package/dist/lib/browser/chunk-MABHE5SS.mjs +277 -0
  12. package/dist/lib/browser/chunk-MABHE5SS.mjs.map +7 -0
  13. package/dist/lib/browser/{chunk-WYPR77TX.mjs → chunk-PBRN5Q4R.mjs} +105 -50
  14. package/dist/lib/browser/chunk-PBRN5Q4R.mjs.map +7 -0
  15. package/dist/lib/browser/{chunk-Q5TZCIH7.mjs → chunk-QGVMZ4PK.mjs} +2 -2
  16. package/dist/lib/browser/cli/index.mjs +29 -0
  17. package/dist/lib/browser/cli/index.mjs.map +7 -0
  18. package/dist/lib/browser/index.mjs +45 -69
  19. package/dist/lib/browser/index.mjs.map +4 -4
  20. package/dist/lib/browser/meta.json +1 -1
  21. package/dist/lib/browser/react-surface-C52R6BRL.mjs +38 -0
  22. package/dist/lib/browser/react-surface-C52R6BRL.mjs.map +7 -0
  23. package/dist/lib/browser/types/index.mjs +3 -5
  24. package/dist/lib/node-esm/ChessboardContainer-5OVYZMIW.mjs +81 -0
  25. package/dist/lib/node-esm/ChessboardContainer-5OVYZMIW.mjs.map +7 -0
  26. package/dist/lib/node-esm/blueprint-definition-4HZ2HWWC.mjs +20 -0
  27. package/dist/lib/node-esm/blueprint-definition-4HZ2HWWC.mjs.map +7 -0
  28. package/dist/lib/node-esm/blueprints/index.mjs +12 -0
  29. package/dist/lib/node-esm/blueprints/index.mjs.map +7 -0
  30. package/dist/lib/node-esm/{chunk-NU4GSP5Y.mjs → chunk-3MAU6WHB.mjs} +105 -50
  31. package/dist/lib/node-esm/chunk-3MAU6WHB.mjs.map +7 -0
  32. package/dist/lib/node-esm/{chunk-KNOOJFIR.mjs → chunk-F5OMIM4F.mjs} +1 -7
  33. package/dist/lib/node-esm/chunk-F5OMIM4F.mjs.map +7 -0
  34. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  35. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
  36. package/dist/lib/node-esm/{chunk-VVXTAVIS.mjs → chunk-IFK6UAKF.mjs} +2 -2
  37. package/dist/lib/node-esm/{chunk-QKXLEJNZ.mjs → chunk-OUNGNJFP.mjs} +10 -29
  38. package/dist/lib/node-esm/chunk-OUNGNJFP.mjs.map +7 -0
  39. package/dist/lib/node-esm/chunk-V6MKXXPO.mjs +278 -0
  40. package/dist/lib/node-esm/chunk-V6MKXXPO.mjs.map +7 -0
  41. package/dist/lib/node-esm/cli/index.mjs +30 -0
  42. package/dist/lib/node-esm/cli/index.mjs.map +7 -0
  43. package/dist/lib/node-esm/index.mjs +45 -69
  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/react-surface-NW33JZ6J.mjs +39 -0
  47. package/dist/lib/node-esm/react-surface-NW33JZ6J.mjs.map +7 -0
  48. package/dist/lib/node-esm/types/index.mjs +3 -5
  49. package/dist/types/src/ChessPlugin.d.ts +2 -1
  50. package/dist/types/src/ChessPlugin.d.ts.map +1 -1
  51. package/dist/types/src/blueprints/chess-blueprint.d.ts +21 -0
  52. package/dist/types/src/blueprints/chess-blueprint.d.ts.map +1 -0
  53. package/dist/types/src/{functions → blueprints/functions}/create.d.ts +7 -6
  54. package/dist/types/src/blueprints/functions/create.d.ts.map +1 -0
  55. package/dist/types/src/{functions → blueprints/functions}/index.d.ts +1 -0
  56. package/dist/types/src/blueprints/functions/index.d.ts.map +1 -0
  57. package/dist/types/src/blueprints/functions/move.d.ts +16 -0
  58. package/dist/types/src/blueprints/functions/move.d.ts.map +1 -0
  59. package/dist/types/src/blueprints/functions/play.d.ts +17 -0
  60. package/dist/types/src/blueprints/functions/play.d.ts.map +1 -0
  61. package/dist/types/src/{functions/move.d.ts → blueprints/functions/print.d.ts} +4 -4
  62. package/dist/types/src/blueprints/functions/print.d.ts.map +1 -0
  63. package/dist/types/src/blueprints/index.d.ts +3 -0
  64. package/dist/types/src/blueprints/index.d.ts.map +1 -0
  65. package/dist/types/src/capabilities/artifact-definition/artifact-definition.d.ts +12 -0
  66. package/dist/types/src/capabilities/artifact-definition/artifact-definition.d.ts.map +1 -0
  67. package/dist/types/src/capabilities/artifact-definition/index.d.ts +3 -0
  68. package/dist/types/src/capabilities/artifact-definition/index.d.ts.map +1 -0
  69. package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts +10 -0
  70. package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts.map +1 -0
  71. package/dist/types/src/capabilities/blueprint-definition/index.d.ts +3 -0
  72. package/dist/types/src/capabilities/blueprint-definition/index.d.ts.map +1 -0
  73. package/dist/types/src/capabilities/index.d.ts +1 -3
  74. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  75. package/dist/types/src/capabilities/react-surface/index.d.ts +3 -0
  76. package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -0
  77. package/dist/types/src/capabilities/react-surface/react-surface.d.ts +5 -0
  78. package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -0
  79. package/dist/types/src/cli/index.d.ts +2 -0
  80. package/dist/types/src/cli/index.d.ts.map +1 -0
  81. package/dist/types/src/cli/plugin.d.ts +3 -0
  82. package/dist/types/src/cli/plugin.d.ts.map +1 -0
  83. package/dist/types/src/components/Card.stories.d.ts +1 -8
  84. package/dist/types/src/components/Card.stories.d.ts.map +1 -1
  85. package/dist/types/src/components/Chessboard.d.ts +2 -1
  86. package/dist/types/src/components/Chessboard.d.ts.map +1 -1
  87. package/dist/types/src/components/Chessboard.stories.d.ts +6 -6
  88. package/dist/types/src/components/Chessboard.stories.d.ts.map +1 -1
  89. package/dist/types/src/components/ChessboardArticle.d.ts +3 -4
  90. package/dist/types/src/components/ChessboardArticle.d.ts.map +1 -1
  91. package/dist/types/src/components/ChessboardContainer.d.ts +3 -5
  92. package/dist/types/src/components/ChessboardContainer.d.ts.map +1 -1
  93. package/dist/types/src/components/Info.d.ts.map +1 -1
  94. package/dist/types/src/components/index.d.ts +1 -1
  95. package/dist/types/src/components/index.d.ts.map +1 -1
  96. package/dist/types/src/index.d.ts +1 -1
  97. package/dist/types/src/index.d.ts.map +1 -1
  98. package/dist/types/src/meta.d.ts +2 -2
  99. package/dist/types/src/meta.d.ts.map +1 -1
  100. package/dist/types/src/types/Chess.d.ts +16 -16
  101. package/dist/types/src/types/Chess.d.ts.map +1 -1
  102. package/dist/types/src/types/index.d.ts +0 -1
  103. package/dist/types/src/types/index.d.ts.map +1 -1
  104. package/dist/types/tsconfig.tsbuildinfo +1 -1
  105. package/package.json +58 -42
  106. package/src/ChessPlugin.tsx +26 -46
  107. package/src/blueprints/chess-blueprint.ts +28 -0
  108. package/src/{functions → blueprints/functions}/create.ts +8 -3
  109. package/src/{functions → blueprints/functions}/index.ts +1 -0
  110. package/src/{functions → blueprints/functions}/move.ts +10 -8
  111. package/src/{functions → blueprints/functions}/play.ts +10 -8
  112. package/src/blueprints/functions/print.ts +42 -0
  113. package/src/blueprints/index.ts +6 -0
  114. package/src/capabilities/artifact-definition/artifact-definition.ts +135 -0
  115. package/src/capabilities/artifact-definition/index.ts +7 -0
  116. package/src/capabilities/blueprint-definition/blueprint-definition.ts +24 -0
  117. package/src/capabilities/blueprint-definition/index.ts +7 -0
  118. package/src/capabilities/index.ts +1 -6
  119. package/src/capabilities/react-surface/index.ts +7 -0
  120. package/src/capabilities/react-surface/react-surface.tsx +28 -0
  121. package/src/cli/index.ts +5 -0
  122. package/src/cli/plugin.ts +27 -0
  123. package/src/components/Card.stories.tsx +19 -38
  124. package/src/components/Chessboard.stories.tsx +16 -12
  125. package/src/components/Chessboard.tsx +26 -13
  126. package/src/components/ChessboardArticle.tsx +8 -6
  127. package/src/components/ChessboardContainer.tsx +9 -13
  128. package/src/components/Info.tsx +21 -11
  129. package/src/index.ts +1 -1
  130. package/src/meta.ts +2 -2
  131. package/src/types/Chess.ts +4 -4
  132. package/src/types/index.ts +0 -1
  133. package/dist/lib/browser/ChessboardContainer-5YXEM4VR.mjs +0 -96
  134. package/dist/lib/browser/ChessboardContainer-5YXEM4VR.mjs.map +0 -7
  135. package/dist/lib/browser/blueprint-definition-EAL54B6V.mjs +0 -11
  136. package/dist/lib/browser/chunk-5DOZV3PW.mjs +0 -294
  137. package/dist/lib/browser/chunk-5DOZV3PW.mjs.map +0 -7
  138. package/dist/lib/browser/chunk-CCF24VRU.mjs.map +0 -7
  139. package/dist/lib/browser/chunk-DUO4WTAM.mjs.map +0 -7
  140. package/dist/lib/browser/chunk-WYPR77TX.mjs.map +0 -7
  141. package/dist/lib/browser/intent-resolver-KPGHK5JU.mjs +0 -25
  142. package/dist/lib/browser/intent-resolver-KPGHK5JU.mjs.map +0 -7
  143. package/dist/lib/browser/react-surface-3YST34QI.mjs +0 -38
  144. package/dist/lib/browser/react-surface-3YST34QI.mjs.map +0 -7
  145. package/dist/lib/node-esm/ChessboardContainer-7OQ6TOKB.mjs +0 -97
  146. package/dist/lib/node-esm/ChessboardContainer-7OQ6TOKB.mjs.map +0 -7
  147. package/dist/lib/node-esm/blueprint-definition-2LWD6BR3.mjs +0 -12
  148. package/dist/lib/node-esm/chunk-F4C2HVZL.mjs +0 -295
  149. package/dist/lib/node-esm/chunk-F4C2HVZL.mjs.map +0 -7
  150. package/dist/lib/node-esm/chunk-KNOOJFIR.mjs.map +0 -7
  151. package/dist/lib/node-esm/chunk-NU4GSP5Y.mjs.map +0 -7
  152. package/dist/lib/node-esm/chunk-QKXLEJNZ.mjs.map +0 -7
  153. package/dist/lib/node-esm/intent-resolver-ZAELGF7I.mjs +0 -26
  154. package/dist/lib/node-esm/intent-resolver-ZAELGF7I.mjs.map +0 -7
  155. package/dist/lib/node-esm/react-surface-KV2KBSIU.mjs +0 -39
  156. package/dist/lib/node-esm/react-surface-KV2KBSIU.mjs.map +0 -7
  157. package/dist/types/src/capabilities/artifact-definition.d.ts +0 -11
  158. package/dist/types/src/capabilities/artifact-definition.d.ts.map +0 -1
  159. package/dist/types/src/capabilities/blueprint-definition.d.ts +0 -6
  160. package/dist/types/src/capabilities/blueprint-definition.d.ts.map +0 -1
  161. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  162. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  163. package/dist/types/src/capabilities/react-surface.d.ts +0 -4
  164. package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
  165. package/dist/types/src/functions/create.d.ts.map +0 -1
  166. package/dist/types/src/functions/index.d.ts.map +0 -1
  167. package/dist/types/src/functions/move.d.ts.map +0 -1
  168. package/dist/types/src/functions/play.d.ts +0 -9
  169. package/dist/types/src/functions/play.d.ts.map +0 -1
  170. package/dist/types/src/types/ChessAction.d.ts +0 -24
  171. package/dist/types/src/types/ChessAction.d.ts.map +0 -1
  172. package/src/capabilities/artifact-definition.ts +0 -129
  173. package/src/capabilities/blueprint-definition.ts +0 -36
  174. package/src/capabilities/intent-resolver.ts +0 -22
  175. package/src/capabilities/react-surface.tsx +0 -23
  176. package/src/types/ChessAction.ts +0 -19
  177. /package/dist/lib/browser/{blueprint-definition-EAL54B6V.mjs.map → blueprints/index.mjs.map} +0 -0
  178. /package/dist/lib/{node-esm/blueprint-definition-2LWD6BR3.mjs.map → browser/chunk-J5LGTIGS.mjs.map} +0 -0
  179. /package/dist/lib/browser/{chunk-Q5TZCIH7.mjs.map → chunk-QGVMZ4PK.mjs.map} +0 -0
  180. /package/dist/lib/node-esm/{chunk-VVXTAVIS.mjs.map → chunk-IFK6UAKF.mjs.map} +0 -0
@@ -0,0 +1,27 @@
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
+ addToCollectionOnCreate: true,
22
+ },
23
+ },
24
+ }),
25
+ AppPlugin.addSchemaModule({ schema: [Chess.Game] }),
26
+ Plugin.make,
27
+ );
@@ -3,64 +3,45 @@
3
3
  //
4
4
 
5
5
  import { type Meta, type StoryObj } from '@storybook/react-vite';
6
- import React from 'react';
6
+ import React, { useMemo } from 'react';
7
7
 
8
8
  import { withTheme } from '@dxos/react-ui/testing';
9
- import { CardContainer } from '@dxos/react-ui-stack/testing';
9
+ import { CardContainer } from '@dxos/react-ui-mosaic/testing';
10
10
 
11
11
  import { meta as pluginMeta } from '../meta';
12
12
  import { Chess } from '../types';
13
13
 
14
14
  import { Chessboard } from './Chessboard';
15
15
 
16
- type DefaultStoryProps = {
17
- role: 'card--popover' | 'card--intrinsic' | 'card--extrinsic';
18
- game: Chess.Game;
19
- };
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 *';
20
18
 
21
- const meta = {
22
- title: 'plugins/plugin-chess/Card',
23
- render: ({ role, game }) => (
24
- <CardContainer icon={pluginMeta.icon} role={role}>
19
+ // TODO(wittjosiah): ECHO objects don't work when passed via Storybook args.
20
+ const CardStory = () => {
21
+ const game = useMemo(() => Chess.make({ pgn: SAMPLE_PGN }), []);
22
+ return (
23
+ <CardContainer icon={pluginMeta.icon}>
25
24
  <Chessboard.Root game={game}>
26
- <Chessboard.Content role={role}>
25
+ <Chessboard.Content>
27
26
  <Chessboard.Board />
28
27
  </Chessboard.Content>
29
28
  </Chessboard.Root>
30
29
  </CardContainer>
31
- ),
32
- decorators: [withTheme],
30
+ );
31
+ };
32
+
33
+ const meta = {
34
+ title: 'plugins/plugin-chess/Card',
35
+ render: () => <CardStory />,
36
+ decorators: [withTheme()],
33
37
  parameters: {
34
38
  layout: 'centered',
35
39
  },
36
40
  tags: ['cards'],
37
- } satisfies Meta<DefaultStoryProps>;
41
+ } satisfies Meta;
38
42
 
39
43
  export default meta;
40
44
 
41
- const game = Chess.makeGame({
42
- 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 *',
43
- });
44
-
45
45
  type Story = StoryObj<typeof meta>;
46
46
 
47
- export const Popover: Story = {
48
- args: {
49
- role: 'card--popover',
50
- game: game,
51
- },
52
- };
53
-
54
- export const Intrinsic: Story = {
55
- args: {
56
- role: 'card--intrinsic',
57
- game: game,
58
- },
59
- };
60
-
61
- export const Extrinsic: Story = {
62
- args: {
63
- role: 'card--extrinsic',
64
- game: game,
65
- },
66
- };
47
+ export const Popover: Story = {};
@@ -3,6 +3,7 @@
3
3
  //
4
4
 
5
5
  import { type Meta, type StoryObj } from '@storybook/react-vite';
6
+ import React, { useMemo } from 'react';
6
7
 
7
8
  import { withClientProvider } from '@dxos/react-client/testing';
8
9
  import { withTheme } from '@dxos/react-ui/testing';
@@ -12,38 +13,41 @@ import { Chess } from '../types';
12
13
 
13
14
  import { ChessboardArticle } from './ChessboardArticle';
14
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 <ChessboardArticle subject={game} />;
23
+ };
24
+
15
25
  const meta = {
16
26
  title: 'plugins/plugin-chess/Chessboard',
17
- component: ChessboardArticle,
18
- decorators: [withTheme, withClientProvider({ createIdentity: true })],
27
+ component: DefaultStory,
28
+ decorators: [withTheme(), withClientProvider({ createIdentity: true })],
19
29
  parameters: {
20
30
  layout: 'fullscreen',
21
31
  translations,
22
32
  },
23
- } satisfies Meta<typeof ChessboardArticle>;
33
+ } satisfies Meta<typeof DefaultStory>;
24
34
 
25
35
  export default meta;
26
36
 
27
37
  type Story = StoryObj<typeof meta>;
28
38
 
29
39
  export const Default: Story = {
30
- args: {
31
- game: Chess.makeGame(),
32
- },
40
+ args: {},
33
41
  };
34
42
 
35
43
  export const EndGame: Story = {
36
44
  args: {
37
- game: Chess.makeGame({
38
- 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 *',
39
- }),
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 *',
40
46
  },
41
47
  };
42
48
 
43
49
  export const Promption: Story = {
44
50
  args: {
45
- game: Chess.makeGame({
46
- 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 *',
47
- }),
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 *',
48
52
  },
49
53
  };
@@ -2,10 +2,12 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
+ import { type Registry, RegistryContext } from '@effect-atom/atom-react';
5
6
  import React, {
6
7
  type PropsWithChildren,
7
8
  forwardRef,
8
9
  useCallback,
10
+ useContext,
9
11
  useEffect,
10
12
  useImperativeHandle,
11
13
  useMemo,
@@ -13,6 +15,7 @@ import React, {
13
15
  } from 'react';
14
16
 
15
17
  import { addEventListener } from '@dxos/async';
18
+ import { Obj } from '@dxos/echo';
16
19
  import { type ThemedClassName } from '@dxos/react-ui';
17
20
  import {
18
21
  ChessModel,
@@ -24,7 +27,7 @@ import {
24
27
  useGameboardContext,
25
28
  } from '@dxos/react-ui-gameboard';
26
29
  import { useSoundEffect } from '@dxos/react-ui-sfx';
27
- import { mx } from '@dxos/react-ui-theme';
30
+ import { mx } from '@dxos/ui-theme';
28
31
 
29
32
  import { type Chess } from '../types';
30
33
 
@@ -35,8 +38,11 @@ export interface ChessboardController {
35
38
  }
36
39
 
37
40
  export class ExtendedChessModel extends ChessModel {
38
- constructor(readonly object: Chess.Game) {
39
- super();
41
+ constructor(
42
+ registry: Registry.Registry,
43
+ readonly object: Chess.Game,
44
+ ) {
45
+ super(registry);
40
46
  }
41
47
  }
42
48
 
@@ -49,7 +55,8 @@ type RootProps = PropsWithChildren<{
49
55
  }>;
50
56
 
51
57
  const Root = forwardRef<ChessboardController, RootProps>(({ game, children }, forwardedRef) => {
52
- const model = useMemo(() => new ExtendedChessModel(game), []);
58
+ const registry = useContext(RegistryContext);
59
+ const model = useMemo(() => new ExtendedChessModel(registry, game), [registry]);
53
60
  const click = useSoundEffect('Click');
54
61
 
55
62
  // Controller.
@@ -79,7 +86,9 @@ const Root = forwardRef<ChessboardController, RootProps>(({ game, children }, fo
79
86
  }
80
87
 
81
88
  void click.play();
82
- game.pgn = model.pgn;
89
+ Obj.change(game, (g) => {
90
+ g.pgn = model.pgn;
91
+ });
83
92
  return true;
84
93
  },
85
94
  [model],
@@ -103,7 +112,7 @@ type ContentProps = ThemedClassName<PropsWithChildren<{ role?: Role }>>;
103
112
  const Content = ({ classNames, children, role }: ContentProps) => {
104
113
  return (
105
114
  <Gameboard.Content
106
- classNames={mx(classNames, role === 'card--popover' && 'size-container popover-square')}
115
+ classNames={mx(classNames, role === 'card--popover' && 'size-container card-square')}
107
116
  grow={!role || role === 'card--extrinsic'}
108
117
  contain={!role || role === 'card--extrinsic' || role === 'card--popover'}
109
118
  >
@@ -116,10 +125,13 @@ const Content = ({ classNames, children, role }: ContentProps) => {
116
125
  // Board
117
126
  //
118
127
 
128
+ const BOARD_NAME = 'Chessboard.Board';
129
+
119
130
  type BoardProps = NaturalChessboardProps;
120
131
 
121
132
  const Board = (props: BoardProps) => {
122
- const { model } = useGameboardContext<ChessModel>(Board.displayName);
133
+ const registry = useContext(RegistryContext);
134
+ const { model } = useGameboardContext<ChessModel>(BOARD_NAME);
123
135
 
124
136
  // Keyboard navigation.
125
137
  const ref = useRef<HTMLDivElement>(null);
@@ -132,6 +144,7 @@ const Board = (props: BoardProps) => {
132
144
  ref.current.setAttribute('data-arrow-keys', 'all');
133
145
 
134
146
  return addEventListener(ref.current, 'keydown', (ev) => {
147
+ const moveIndex = registry.get(model.moveIndex);
135
148
  switch (ev.key) {
136
149
  case 'ArrowUp':
137
150
  model.setMoveIndex(0);
@@ -140,23 +153,23 @@ const Board = (props: BoardProps) => {
140
153
  model.setMoveIndex(model.game.history().length);
141
154
  break;
142
155
  case 'ArrowLeft':
143
- if (model.moveIndex.value > 0) {
144
- model.setMoveIndex(model.moveIndex.value - 1);
156
+ if (moveIndex > 0) {
157
+ model.setMoveIndex(moveIndex - 1);
145
158
  }
146
159
  break;
147
160
  case 'ArrowRight':
148
- if (model.moveIndex.value < model.game.history().length) {
149
- model.setMoveIndex(model.moveIndex.value + 1);
161
+ if (moveIndex < model.game.history().length) {
162
+ model.setMoveIndex(moveIndex + 1);
150
163
  }
151
164
  break;
152
165
  }
153
166
  });
154
- }, [model]);
167
+ }, [registry, model]);
155
168
 
156
169
  return <NaturalChessboard ref={ref} {...props} />;
157
170
  };
158
171
 
159
- Board.displayName = 'Chessboard.Board';
172
+ Board.displayName = BOARD_NAME;
160
173
 
161
174
  //
162
175
  // Chessboard
@@ -4,17 +4,19 @@
4
4
 
5
5
  import React, { useCallback, useRef, useState } from 'react';
6
6
 
7
- import { Toolbar, useTranslation } from '@dxos/react-ui';
7
+ import { type SurfaceComponentProps } from '@dxos/app-toolkit/ui';
8
+ import { Layout, Toolbar, useTranslation } from '@dxos/react-ui';
8
9
  import { type Player } from '@dxos/react-ui-gameboard';
9
- import { StackItem } from '@dxos/react-ui-stack';
10
- import { mx } from '@dxos/react-ui-theme';
10
+ import { mx } from '@dxos/ui-theme';
11
11
 
12
12
  import { meta } from '../meta';
13
13
  import { type Chess } from '../types';
14
14
 
15
15
  import { Chessboard, type ChessboardController, type ChessboardInfoProps } from './Chessboard';
16
16
 
17
- export const ChessboardArticle = ({ game, role }: { game: Chess.Game; role?: string }) => {
17
+ export type ChessboardArticleProps = SurfaceComponentProps<Chess.Game>;
18
+
19
+ export const ChessboardArticle = ({ role, subject: game }: ChessboardArticleProps) => {
18
20
  const { t } = useTranslation(meta.id);
19
21
  const [orientation, setOrientation] = useState<Player>('white');
20
22
  const [open, setOpen] = useState(true);
@@ -26,7 +28,7 @@ export const ChessboardArticle = ({ game, role }: { game: Chess.Game; role?: str
26
28
  }, []);
27
29
 
28
30
  return (
29
- <StackItem.Content toolbar classNames='@container'>
31
+ <Layout.Main toolbar classNames='@container'>
30
32
  <Chessboard.Root game={game} ref={controller}>
31
33
  <Toolbar.Root>
32
34
  <Toolbar.IconButton
@@ -63,6 +65,6 @@ export const ChessboardArticle = ({ game, role }: { game: Chess.Game; role?: str
63
65
  )}
64
66
  </div>
65
67
  </Chessboard.Root>
66
- </StackItem.Content>
68
+ </Layout.Main>
67
69
  );
68
70
  };
@@ -4,31 +4,27 @@
4
4
 
5
5
  import React from 'react';
6
6
 
7
- import { getSpace } from '@dxos/react-client/echo';
7
+ import { type SurfaceComponentProps } from '@dxos/app-toolkit/ui';
8
+ import { Obj } from '@dxos/echo';
8
9
 
9
10
  import { type Chess } from '../types';
10
11
 
11
12
  import { Chessboard } from './Chessboard';
12
13
  import { ChessboardArticle } from './ChessboardArticle';
13
14
 
14
- export type ChessboardContainerProps = {
15
- game: Chess.Game;
16
- role?: string;
17
- };
15
+ export type ChessboardContainerProps = SurfaceComponentProps<Chess.Game>;
18
16
 
19
- export const ChessboardContainer = ({ game, role }: ChessboardContainerProps) => {
20
- const space = getSpace(game);
21
- if (!space) {
17
+ export const ChessboardContainer = ({ role, subject: game }: ChessboardContainerProps) => {
18
+ const db = Obj.getDatabase(game);
19
+ if (!db) {
22
20
  return null;
23
21
  }
24
22
 
25
23
  switch (role) {
26
- case 'card--popover':
27
- case 'card--intrinsic':
28
- case 'card--extrinsic': {
24
+ case 'card--content': {
29
25
  return (
30
26
  <Chessboard.Root game={game}>
31
- <Chessboard.Content role={role}>
27
+ <Chessboard.Content>
32
28
  <Chessboard.Board />
33
29
  </Chessboard.Content>
34
30
  </Chessboard.Root>
@@ -36,7 +32,7 @@ export const ChessboardContainer = ({ game, role }: ChessboardContainerProps) =>
36
32
  }
37
33
 
38
34
  default: {
39
- return <ChessboardArticle game={game} role={role} />;
35
+ return <ChessboardArticle role={role} subject={game} />;
40
36
  }
41
37
  }
42
38
  };
@@ -2,18 +2,22 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
+ import { useAtomValue } from '@effect-atom/atom-react';
5
6
  import React, { type JSX, type PropsWithChildren, useEffect, useMemo, useRef } from 'react';
6
7
 
7
8
  import { generateName } from '@dxos/display-name';
8
- import { type SpaceMember, getSpace, useMembers } from '@dxos/react-client/echo';
9
+ import { Obj } from '@dxos/echo';
10
+ import { type SpaceMember, useMembers } from '@dxos/react-client/echo';
9
11
  import { Icon, IconButton, Select, type ThemedClassName, useTranslation } from '@dxos/react-ui';
10
12
  import { type Player, useGameboardContext } from '@dxos/react-ui-gameboard';
11
- import { mx } from '@dxos/react-ui-theme';
13
+ import { mx } from '@dxos/ui-theme';
12
14
 
13
15
  import { meta } from '../meta';
14
16
 
15
17
  import { type ExtendedChessModel } from './Chessboard';
16
18
 
19
+ const INFO_NAME = 'Chessboard.Info';
20
+
17
21
  export type InfoProps = ThemedClassName<
18
22
  {
19
23
  orientation?: Player;
@@ -24,8 +28,9 @@ export type InfoProps = ThemedClassName<
24
28
 
25
29
  export const Info = ({ classNames, orientation = 'white', onOrientationChange, onClose, ...props }: InfoProps) => {
26
30
  const { t } = useTranslation(meta.id);
27
- const { model } = useGameboardContext<ExtendedChessModel>(Info.displayName);
28
- const members = useMembers(getSpace(model.object)?.key);
31
+ const { model } = useGameboardContext<ExtendedChessModel>(INFO_NAME);
32
+ const db = Obj.getDatabase(model.object);
33
+ const members = useMembers(db?.spaceId);
29
34
 
30
35
  return (
31
36
  <div
@@ -46,7 +51,9 @@ export const Info = ({ classNames, orientation = 'white', onOrientationChange, o
46
51
  <PlayerSelector
47
52
  value={model.object.players?.[orientation === 'white' ? 'black' : 'white']}
48
53
  onValueChange={(value) => {
49
- model.object.players![orientation === 'white' ? 'black' : 'white'] = value;
54
+ Obj.change(model.object, (obj) => {
55
+ obj.players![orientation === 'white' ? 'black' : 'white'] = value;
56
+ });
50
57
  }}
51
58
  members={members}
52
59
  />
@@ -73,7 +80,9 @@ export const Info = ({ classNames, orientation = 'white', onOrientationChange, o
73
80
  <PlayerSelector
74
81
  value={model.object.players?.[orientation]}
75
82
  onValueChange={(value) => {
76
- model.object.players![orientation] = value;
83
+ Obj.change(model.object, (obj) => {
84
+ obj.players![orientation] = value;
85
+ });
77
86
  }}
78
87
  members={members}
79
88
  />
@@ -82,7 +91,7 @@ export const Info = ({ classNames, orientation = 'white', onOrientationChange, o
82
91
  );
83
92
  };
84
93
 
85
- Info.displayName = 'Chessboard.Info';
94
+ Info.displayName = INFO_NAME;
86
95
 
87
96
  //
88
97
  // History
@@ -97,6 +106,7 @@ type HistoryProps = ThemedClassName<{
97
106
 
98
107
  const History = ({ classNames, model, min, max, onSelect }: HistoryProps) => {
99
108
  const { t } = useTranslation(meta.id);
109
+ const moveIndex = useAtomValue(model.moveIndex);
100
110
  const label = model.game.isGameOver()
101
111
  ? model.game.isCheckmate()
102
112
  ? t('game.checkmate label')
@@ -130,11 +140,11 @@ const History = ({ classNames, model, min, max, onSelect }: HistoryProps) => {
130
140
  }, [history.length]);
131
141
 
132
142
  useEffect(() => {
133
- const div = scrollerRef.current?.querySelector(`[data-index="${model.moveIndex.value - 1}"]`);
143
+ const div = scrollerRef.current?.querySelector(`[data-index="${moveIndex - 1}"]`);
134
144
  scrollerRef.current?.classList.add('scrollbar-none');
135
145
  div?.scrollIntoView({ behavior: 'smooth' });
136
146
  scrollerRef.current?.classList.remove('scrollbar-none');
137
- }, [model.moveIndex.value]);
147
+ }, [moveIndex]);
138
148
 
139
149
  return (
140
150
  <div
@@ -151,7 +161,7 @@ const History = ({ classNames, model, min, max, onSelect }: HistoryProps) => {
151
161
  {a && (
152
162
  <div
153
163
  data-index={a.index}
154
- className={mx('pis-2 cursor-pointer', a.index === model.moveIndex.value - 1 && 'bg-primary-500')}
164
+ className={mx('pis-2 cursor-pointer', a.index === moveIndex - 1 && 'bg-primary-500')}
155
165
  onClick={() => onSelect?.(a.index + 1)}
156
166
  >
157
167
  {a.move}
@@ -160,7 +170,7 @@ const History = ({ classNames, model, min, max, onSelect }: HistoryProps) => {
160
170
  {b && (
161
171
  <div
162
172
  data-index={b.index}
163
- className={mx('pis-2 cursor-pointer', b.index === model.moveIndex.value - 1 && 'bg-primary-500')}
173
+ className={mx('pis-2 cursor-pointer', b.index === moveIndex - 1 && 'bg-primary-500')}
164
174
  onClick={() => onSelect?.(b.index + 1)}
165
175
  >
166
176
  {b.move}
package/src/index.ts CHANGED
@@ -2,9 +2,9 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
+ export * from './blueprints';
5
6
  export * from './capabilities';
6
7
  export * from './components';
7
- export * from './functions';
8
8
  export * from './meta';
9
9
  export * from './types';
10
10
 
package/src/meta.ts CHANGED
@@ -2,10 +2,10 @@
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 = {
8
+ export const meta: Plugin.Meta = {
9
9
  id: 'dxos.org/plugin/chess',
10
10
  name: 'Chess',
11
11
  description: trim`
@@ -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,7 +30,7 @@ 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({
33
+ Type.object({
34
34
  typename: 'dxos.org/type/Chess',
35
35
  version: '0.2.0',
36
36
  }),
@@ -39,7 +39,7 @@ export const Game = Schema.Struct({
39
39
 
40
40
  export interface Game extends Schema.Schema.Type<typeof Game> {}
41
41
 
42
- export const makeGame = ({ name, pgn, fen }: { name?: string; pgn?: string; fen?: string } = {}) => {
42
+ export const make = ({ name, pgn, fen }: { name?: string; pgn?: string; fen?: string } = {}) => {
43
43
  const chess = new ChessJS();
44
44
  if (pgn) {
45
45
  try {
@@ -51,8 +51,8 @@ export const makeGame = ({ name, pgn, fen }: { name?: string; pgn?: string; fen?
51
51
 
52
52
  return Obj.make(Game, {
53
53
  name,
54
- players: {},
55
54
  pgn,
56
55
  fen,
56
+ players: {},
57
57
  });
58
58
  };
@@ -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