@dxos/plugin-chess 0.8.4-main.ae835ea → 0.8.4-main.bc674ce

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 (182) hide show
  1. package/dist/lib/browser/ChessboardContainer-JZ4ANG4O.mjs +81 -0
  2. package/dist/lib/browser/ChessboardContainer-JZ4ANG4O.mjs.map +7 -0
  3. package/dist/lib/browser/blueprint-definition-P7TYXWMF.mjs +18 -0
  4. package/dist/lib/browser/blueprint-definition-P7TYXWMF.mjs.map +7 -0
  5. package/dist/lib/browser/blueprints/index.mjs +11 -0
  6. package/dist/lib/browser/{chunk-FBLAVAMY.mjs → chunk-66H3V2YV.mjs} +15 -35
  7. package/dist/lib/browser/chunk-66H3V2YV.mjs.map +7 -0
  8. package/dist/lib/browser/chunk-73BDP7UV.mjs +275 -0
  9. package/dist/lib/browser/chunk-73BDP7UV.mjs.map +7 -0
  10. package/dist/lib/browser/{chunk-TIIGNOGK.mjs → chunk-FO4ZNFN6.mjs} +105 -45
  11. package/dist/lib/browser/chunk-FO4ZNFN6.mjs.map +7 -0
  12. package/dist/lib/browser/{chunk-DUO4WTAM.mjs → chunk-H3NUMCQ6.mjs} +1 -8
  13. package/dist/lib/browser/chunk-H3NUMCQ6.mjs.map +7 -0
  14. package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
  15. package/dist/lib/browser/{chunk-WLXUZMHC.mjs → chunk-OW6S2SRG.mjs} +2 -2
  16. package/dist/lib/browser/cli/index.mjs +28 -0
  17. package/dist/lib/browser/cli/index.mjs.map +7 -0
  18. package/dist/lib/browser/index.mjs +46 -71
  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-VNOWFKC6.mjs +37 -0
  22. package/dist/lib/browser/react-surface-VNOWFKC6.mjs.map +7 -0
  23. package/dist/lib/browser/types/index.mjs +3 -5
  24. package/dist/lib/node-esm/ChessboardContainer-7ONFYN7L.mjs +82 -0
  25. package/dist/lib/node-esm/ChessboardContainer-7ONFYN7L.mjs.map +7 -0
  26. package/dist/lib/node-esm/blueprint-definition-SL4LBVV5.mjs +19 -0
  27. package/dist/lib/node-esm/blueprint-definition-SL4LBVV5.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-FKRBFLJC.mjs → chunk-24GJHLHM.mjs} +2 -2
  31. package/dist/lib/node-esm/{chunk-RTCAAOLF.mjs → chunk-C7IWIXCJ.mjs} +105 -45
  32. package/dist/lib/node-esm/chunk-C7IWIXCJ.mjs.map +7 -0
  33. package/dist/lib/node-esm/{chunk-KNOOJFIR.mjs → chunk-F5OMIM4F.mjs} +1 -7
  34. package/dist/lib/node-esm/chunk-F5OMIM4F.mjs.map +7 -0
  35. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  36. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
  37. package/dist/lib/node-esm/{chunk-MP3A3AGA.mjs → chunk-OUNGNJFP.mjs} +15 -35
  38. package/dist/lib/node-esm/chunk-OUNGNJFP.mjs.map +7 -0
  39. package/dist/lib/node-esm/chunk-WXEPWOHT.mjs +276 -0
  40. package/dist/lib/node-esm/chunk-WXEPWOHT.mjs.map +7 -0
  41. package/dist/lib/node-esm/cli/index.mjs +29 -0
  42. package/dist/lib/node-esm/cli/index.mjs.map +7 -0
  43. package/dist/lib/node-esm/index.mjs +46 -71
  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-4PRNWQ2V.mjs → react-surface-HSHCIOAS.mjs} +15 -16
  47. package/dist/lib/node-esm/react-surface-HSHCIOAS.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/blueprints/functions/create.d.ts +15 -0
  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/{functions → blueprints/functions}/move.d.ts +1 -1
  58. package/dist/types/src/blueprints/functions/move.d.ts.map +1 -0
  59. package/dist/types/src/{functions → blueprints/functions}/play.d.ts +1 -1
  60. package/dist/types/src/blueprints/functions/play.d.ts.map +1 -0
  61. package/dist/types/src/blueprints/functions/print.d.ts +8 -0
  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 +9 -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 -4
  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/translations.d.ts +1 -0
  101. package/dist/types/src/translations.d.ts.map +1 -1
  102. package/dist/types/src/types/Chess.d.ts +18 -18
  103. package/dist/types/src/types/Chess.d.ts.map +1 -1
  104. package/dist/types/src/types/index.d.ts +0 -1
  105. package/dist/types/src/types/index.d.ts.map +1 -1
  106. package/dist/types/tsconfig.tsbuildinfo +1 -1
  107. package/package.json +57 -42
  108. package/src/ChessPlugin.tsx +25 -52
  109. package/src/blueprints/chess-blueprint.ts +28 -0
  110. package/src/{functions → blueprints/functions}/create.ts +10 -4
  111. package/src/{functions → blueprints/functions}/index.ts +1 -0
  112. package/src/{functions → blueprints/functions}/move.ts +9 -5
  113. package/src/{functions → blueprints/functions}/play.ts +9 -5
  114. package/src/blueprints/functions/print.ts +42 -0
  115. package/src/blueprints/index.ts +6 -0
  116. package/src/capabilities/artifact-definition/artifact-definition.ts +135 -0
  117. package/src/capabilities/artifact-definition/index.ts +7 -0
  118. package/src/capabilities/blueprint-definition/blueprint-definition.ts +23 -0
  119. package/src/capabilities/blueprint-definition/index.ts +7 -0
  120. package/src/capabilities/index.ts +1 -6
  121. package/src/capabilities/react-surface/index.ts +7 -0
  122. package/src/capabilities/react-surface/react-surface.tsx +27 -0
  123. package/src/cli/index.ts +5 -0
  124. package/src/cli/plugin.ts +26 -0
  125. package/src/components/Card.stories.tsx +18 -37
  126. package/src/components/Chessboard.stories.tsx +15 -11
  127. package/src/components/Chessboard.tsx +21 -10
  128. package/src/components/ChessboardArticle.tsx +13 -11
  129. package/src/components/ChessboardContainer.tsx +9 -13
  130. package/src/components/Info.tsx +19 -11
  131. package/src/index.ts +1 -1
  132. package/src/meta.ts +2 -2
  133. package/src/translations.ts +1 -0
  134. package/src/types/Chess.ts +7 -9
  135. package/src/types/index.ts +0 -1
  136. package/dist/lib/browser/ChessboardContainer-SZMONNHG.mjs +0 -96
  137. package/dist/lib/browser/ChessboardContainer-SZMONNHG.mjs.map +0 -7
  138. package/dist/lib/browser/blueprint-definition-FD4TL5EE.mjs +0 -11
  139. package/dist/lib/browser/chunk-DUO4WTAM.mjs.map +0 -7
  140. package/dist/lib/browser/chunk-FBLAVAMY.mjs.map +0 -7
  141. package/dist/lib/browser/chunk-R6KK3WAS.mjs +0 -294
  142. package/dist/lib/browser/chunk-R6KK3WAS.mjs.map +0 -7
  143. package/dist/lib/browser/chunk-TIIGNOGK.mjs.map +0 -7
  144. package/dist/lib/browser/intent-resolver-GXZN2EBT.mjs +0 -25
  145. package/dist/lib/browser/intent-resolver-GXZN2EBT.mjs.map +0 -7
  146. package/dist/lib/browser/react-surface-EVJLBV6U.mjs +0 -38
  147. package/dist/lib/browser/react-surface-EVJLBV6U.mjs.map +0 -7
  148. package/dist/lib/node-esm/ChessboardContainer-GAIIADOA.mjs +0 -97
  149. package/dist/lib/node-esm/ChessboardContainer-GAIIADOA.mjs.map +0 -7
  150. package/dist/lib/node-esm/blueprint-definition-O7ZM3HUF.mjs +0 -12
  151. package/dist/lib/node-esm/chunk-IVEIH4ER.mjs +0 -295
  152. package/dist/lib/node-esm/chunk-IVEIH4ER.mjs.map +0 -7
  153. package/dist/lib/node-esm/chunk-KNOOJFIR.mjs.map +0 -7
  154. package/dist/lib/node-esm/chunk-MP3A3AGA.mjs.map +0 -7
  155. package/dist/lib/node-esm/chunk-RTCAAOLF.mjs.map +0 -7
  156. package/dist/lib/node-esm/intent-resolver-HK5L6P6Z.mjs +0 -26
  157. package/dist/lib/node-esm/intent-resolver-HK5L6P6Z.mjs.map +0 -7
  158. package/dist/lib/node-esm/react-surface-4PRNWQ2V.mjs.map +0 -7
  159. package/dist/types/src/capabilities/artifact-definition.d.ts +0 -11
  160. package/dist/types/src/capabilities/artifact-definition.d.ts.map +0 -1
  161. package/dist/types/src/capabilities/blueprint-definition.d.ts +0 -6
  162. package/dist/types/src/capabilities/blueprint-definition.d.ts.map +0 -1
  163. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  164. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  165. package/dist/types/src/capabilities/react-surface.d.ts +0 -4
  166. package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
  167. package/dist/types/src/functions/create.d.ts +0 -14
  168. package/dist/types/src/functions/create.d.ts.map +0 -1
  169. package/dist/types/src/functions/index.d.ts.map +0 -1
  170. package/dist/types/src/functions/move.d.ts.map +0 -1
  171. package/dist/types/src/functions/play.d.ts.map +0 -1
  172. package/dist/types/src/types/ChessAction.d.ts +0 -24
  173. package/dist/types/src/types/ChessAction.d.ts.map +0 -1
  174. package/src/capabilities/artifact-definition.ts +0 -129
  175. package/src/capabilities/blueprint-definition.ts +0 -36
  176. package/src/capabilities/intent-resolver.ts +0 -22
  177. package/src/capabilities/react-surface.tsx +0 -23
  178. package/src/types/ChessAction.ts +0 -19
  179. /package/dist/lib/browser/{blueprint-definition-FD4TL5EE.mjs.map → blueprints/index.mjs.map} +0 -0
  180. /package/dist/lib/{node-esm/blueprint-definition-O7ZM3HUF.mjs.map → browser/chunk-J5LGTIGS.mjs.map} +0 -0
  181. /package/dist/lib/browser/{chunk-WLXUZMHC.mjs.map → chunk-OW6S2SRG.mjs.map} +0 -0
  182. /package/dist/lib/node-esm/{chunk-FKRBFLJC.mjs.map → chunk-24GJHLHM.mjs.map} +0 -0
@@ -0,0 +1,26 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Effect from 'effect/Effect';
6
+
7
+ import { Common, Plugin } from '@dxos/app-framework';
8
+ import { type CreateObject } from '@dxos/plugin-space/types';
9
+
10
+ import { meta } from '../meta';
11
+ import { Chess } from '../types';
12
+
13
+ // TODO(wittjosiah): Factor out shared modules.
14
+ export const ChessPlugin = Plugin.define(meta).pipe(
15
+ Common.Plugin.addSchemaModule({ schema: [Chess.Game] }),
16
+ Common.Plugin.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
+ Plugin.make,
26
+ );
@@ -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
- ),
30
+ );
31
+ };
32
+
33
+ const meta = {
34
+ title: 'plugins/plugin-chess/Card',
35
+ render: () => <CardStory />,
32
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,
27
+ component: DefaultStory,
18
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],
@@ -119,6 +128,7 @@ const Content = ({ classNames, children, role }: ContentProps) => {
119
128
  type BoardProps = NaturalChessboardProps;
120
129
 
121
130
  const Board = (props: BoardProps) => {
131
+ const registry = useContext(RegistryContext);
122
132
  const { model } = useGameboardContext<ChessModel>(Board.displayName);
123
133
 
124
134
  // Keyboard navigation.
@@ -132,6 +142,7 @@ const Board = (props: BoardProps) => {
132
142
  ref.current.setAttribute('data-arrow-keys', 'all');
133
143
 
134
144
  return addEventListener(ref.current, 'keydown', (ev) => {
145
+ const moveIndex = registry.get(model.moveIndex);
135
146
  switch (ev.key) {
136
147
  case 'ArrowUp':
137
148
  model.setMoveIndex(0);
@@ -140,18 +151,18 @@ const Board = (props: BoardProps) => {
140
151
  model.setMoveIndex(model.game.history().length);
141
152
  break;
142
153
  case 'ArrowLeft':
143
- if (model.moveIndex.value > 0) {
144
- model.setMoveIndex(model.moveIndex.value - 1);
154
+ if (moveIndex > 0) {
155
+ model.setMoveIndex(moveIndex - 1);
145
156
  }
146
157
  break;
147
158
  case 'ArrowRight':
148
- if (model.moveIndex.value < model.game.history().length) {
149
- model.setMoveIndex(model.moveIndex.value + 1);
159
+ if (moveIndex < model.game.history().length) {
160
+ model.setMoveIndex(moveIndex + 1);
150
161
  }
151
162
  break;
152
163
  }
153
164
  });
154
- }, [model]);
165
+ }, [registry, model]);
155
166
 
156
167
  return <NaturalChessboard ref={ref} {...props} />;
157
168
  };
@@ -4,17 +4,20 @@
4
4
 
5
5
  import React, { useCallback, useRef, useState } from 'react';
6
6
 
7
- import { IconButton, Toolbar, useTranslation } from '@dxos/react-ui';
7
+ import { type SurfaceComponentProps } from '@dxos/app-framework/react';
8
+ import { 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 { Layout } from '@dxos/react-ui-mosaic';
11
+ import { mx } from '@dxos/ui-theme';
11
12
 
12
13
  import { meta } from '../meta';
13
14
  import { type Chess } from '../types';
14
15
 
15
16
  import { Chessboard, type ChessboardController, type ChessboardInfoProps } from './Chessboard';
16
17
 
17
- export const ChessboardArticle = ({ game, role }: { game: Chess.Game; role?: string }) => {
18
+ export type ChessboardArticleProps = SurfaceComponentProps<Chess.Game>;
19
+
20
+ export const ChessboardArticle = ({ role, subject: game }: ChessboardArticleProps) => {
18
21
  const { t } = useTranslation(meta.id);
19
22
  const [orientation, setOrientation] = useState<Player>('white');
20
23
  const [open, setOpen] = useState(true);
@@ -26,22 +29,21 @@ export const ChessboardArticle = ({ game, role }: { game: Chess.Game; role?: str
26
29
  }, []);
27
30
 
28
31
  return (
29
- <StackItem.Content toolbar>
32
+ <Layout.Main toolbar classNames='@container'>
30
33
  <Chessboard.Root game={game} ref={controller}>
31
34
  <Toolbar.Root>
32
- <IconButton
33
- variant='ghost'
35
+ <Toolbar.IconButton
34
36
  icon='ph--info--regular'
35
37
  iconOnly
36
38
  label={t('toggle info button')}
37
- size={6}
38
- classNames={mx('invisible', !open && '@3xl:visible')}
39
+ disabled={open}
40
+ classNames={mx('invisible @3xl:visible')}
39
41
  onClick={() => setOpen((open) => !open)}
40
42
  />
41
43
  </Toolbar.Root>
42
44
  <div
43
45
  className={mx(
44
- 'grid _grid-rows-[1fr_4rem] bs-full is-full gap-2',
46
+ 'grid bs-full is-full gap-2',
45
47
  open && '@3xl:grid-cols-[1fr_320px]',
46
48
  role === 'section' && 'aspect-square',
47
49
  role === 'section' && open && '@3xl:aspect-auto',
@@ -64,6 +66,6 @@ export const ChessboardArticle = ({ game, role }: { game: Chess.Game; role?: str
64
66
  )}
65
67
  </div>
66
68
  </Chessboard.Root>
67
- </StackItem.Content>
69
+ </Layout.Main>
68
70
  );
69
71
  };
@@ -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-framework/react';
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,13 +2,15 @@
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
 
@@ -25,7 +27,8 @@ export type InfoProps = ThemedClassName<
25
27
  export const Info = ({ classNames, orientation = 'white', onOrientationChange, onClose, ...props }: InfoProps) => {
26
28
  const { t } = useTranslation(meta.id);
27
29
  const { model } = useGameboardContext<ExtendedChessModel>(Info.displayName);
28
- const members = useMembers(getSpace(model.object)?.key);
30
+ const db = Obj.getDatabase(model.object);
31
+ const members = useMembers(db?.spaceId);
29
32
 
30
33
  return (
31
34
  <div
@@ -46,7 +49,9 @@ export const Info = ({ classNames, orientation = 'white', onOrientationChange, o
46
49
  <PlayerSelector
47
50
  value={model.object.players?.[orientation === 'white' ? 'black' : 'white']}
48
51
  onValueChange={(value) => {
49
- model.object.players![orientation === 'white' ? 'black' : 'white'] = value;
52
+ Obj.change(model.object, (obj) => {
53
+ obj.players![orientation === 'white' ? 'black' : 'white'] = value;
54
+ });
50
55
  }}
51
56
  members={members}
52
57
  />
@@ -73,7 +78,9 @@ export const Info = ({ classNames, orientation = 'white', onOrientationChange, o
73
78
  <PlayerSelector
74
79
  value={model.object.players?.[orientation]}
75
80
  onValueChange={(value) => {
76
- model.object.players![orientation] = value;
81
+ Obj.change(model.object, (obj) => {
82
+ obj.players![orientation] = value;
83
+ });
77
84
  }}
78
85
  members={members}
79
86
  />
@@ -97,6 +104,7 @@ type HistoryProps = ThemedClassName<{
97
104
 
98
105
  const History = ({ classNames, model, min, max, onSelect }: HistoryProps) => {
99
106
  const { t } = useTranslation(meta.id);
107
+ const moveIndex = useAtomValue(model.moveIndex);
100
108
  const label = model.game.isGameOver()
101
109
  ? model.game.isCheckmate()
102
110
  ? t('game.checkmate label')
@@ -130,16 +138,16 @@ const History = ({ classNames, model, min, max, onSelect }: HistoryProps) => {
130
138
  }, [history.length]);
131
139
 
132
140
  useEffect(() => {
133
- const div = scrollerRef.current?.querySelector(`[data-index="${model.moveIndex.value - 1}"]`);
141
+ const div = scrollerRef.current?.querySelector(`[data-index="${moveIndex - 1}"]`);
134
142
  scrollerRef.current?.classList.add('scrollbar-none');
135
143
  div?.scrollIntoView({ behavior: 'smooth' });
136
144
  scrollerRef.current?.classList.remove('scrollbar-none');
137
- }, [model.moveIndex.value]);
145
+ }, [moveIndex]);
138
146
 
139
147
  return (
140
148
  <div
141
149
  ref={scrollerRef}
142
- className={mx('overflow-y-scroll', classNames)}
150
+ className={mx('overflow-y-auto', classNames)}
143
151
  style={{
144
152
  minHeight: min === undefined ? 'auto' : `${min * 24}px`,
145
153
  maxHeight: max === undefined ? 'auto' : `${max * 24}px`,
@@ -151,7 +159,7 @@ const History = ({ classNames, model, min, max, onSelect }: HistoryProps) => {
151
159
  {a && (
152
160
  <div
153
161
  data-index={a.index}
154
- className={mx('pis-2 cursor-pointer', a.index === model.moveIndex.value - 1 && 'bg-primary-500')}
162
+ className={mx('pis-2 cursor-pointer', a.index === moveIndex - 1 && 'bg-primary-500')}
155
163
  onClick={() => onSelect?.(a.index + 1)}
156
164
  >
157
165
  {a.move}
@@ -160,7 +168,7 @@ const History = ({ classNames, model, min, max, onSelect }: HistoryProps) => {
160
168
  {b && (
161
169
  <div
162
170
  data-index={b.index}
163
- className={mx('pis-2 cursor-pointer', b.index === model.moveIndex.value - 1 && 'bg-primary-500')}
171
+ className={mx('pis-2 cursor-pointer', b.index === moveIndex - 1 && 'bg-primary-500')}
164
172
  onClick={() => onSelect?.(b.index + 1)}
165
173
  >
166
174
  {b.move}
@@ -186,7 +194,7 @@ type PlayerIndicatorProps = PropsWithChildren<{
186
194
  const PlayerIndicator = ({ children, model, player, icon }: PlayerIndicatorProps) => {
187
195
  const turn = player === (model.game.turn() === 'w' ? 'white' : 'black');
188
196
  return (
189
- <div className='grid grid-cols-[2rem_1fr_2rem] gap-2 bs-[--rail-size] pis-1 pie-1 flex items-center overflow-hidden'>
197
+ <div className='grid grid-cols-[2rem_1fr_2rem] gap-2 bs-[--rail-size] pli-1 flex items-center overflow-hidden'>
190
198
  <div className='place-items-center'>
191
199
  <Icon
192
200
  icon={turn ? 'ph--circle--fill' : 'ph--circle--thin'}
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`
@@ -18,6 +18,7 @@ export const translations = [
18
18
  'object name placeholder': 'New game',
19
19
  'rename object label': 'Rename game',
20
20
  'delete object label': 'Delete game',
21
+ 'object deleted label': 'Game deleted',
21
22
  },
22
23
  [meta.id]: {
23
24
  'plugin name': 'Chess',
@@ -6,9 +6,8 @@ import { Chess as ChessJS } from 'chess.js';
6
6
  import * as Schema from 'effect/Schema';
7
7
 
8
8
  import { Obj, Type } from '@dxos/echo';
9
- import { FormAnnotation, LabelAnnotation } from '@dxos/echo/internal';
9
+ import { FormInputAnnotation, LabelAnnotation } from '@dxos/echo/internal';
10
10
  import { log } from '@dxos/log';
11
- import { ItemAnnotation } from '@dxos/schema';
12
11
 
13
12
  export const Game = Schema.Struct({
14
13
  name: Schema.optional(Schema.String),
@@ -23,25 +22,24 @@ export const Game = Schema.Struct({
23
22
  description: 'DID of black player',
24
23
  }),
25
24
  ),
26
- }).pipe(Schema.mutable, FormAnnotation.set(false), Schema.optional),
25
+ }).pipe(FormInputAnnotation.set(false), Schema.optional),
27
26
  pgn: Schema.String.annotations({
28
27
  description: 'Portable Game Notation.',
29
- }).pipe(FormAnnotation.set(false), Schema.optional),
28
+ }).pipe(FormInputAnnotation.set(false), Schema.optional),
30
29
  fen: Schema.String.annotations({
31
30
  description: 'Forsyth-Edwards Notation.',
32
- }).pipe(FormAnnotation.set(false), Schema.optional),
31
+ }).pipe(FormInputAnnotation.set(false), Schema.optional),
33
32
  }).pipe(
34
- Type.Obj({
33
+ Type.object({
35
34
  typename: 'dxos.org/type/Chess',
36
35
  version: '0.2.0',
37
36
  }),
38
37
  LabelAnnotation.set(['name']),
39
- ItemAnnotation.set(true),
40
38
  );
41
39
 
42
40
  export interface Game extends Schema.Schema.Type<typeof Game> {}
43
41
 
44
- 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 } = {}) => {
45
43
  const chess = new ChessJS();
46
44
  if (pgn) {
47
45
  try {
@@ -53,8 +51,8 @@ export const makeGame = ({ name, pgn, fen }: { name?: string; pgn?: string; fen?
53
51
 
54
52
  return Obj.make(Game, {
55
53
  name,
56
- players: {},
57
54
  pgn,
58
55
  fen,
56
+ players: {},
59
57
  });
60
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-R6KK3WAS.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 { IconButton, 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
- }, /* @__PURE__ */ React.createElement(Chessboard.Root, {
32
- game,
33
- ref: controller
34
- }, /* @__PURE__ */ React.createElement(Toolbar.Root, null, /* @__PURE__ */ React.createElement(IconButton, {
35
- variant: "ghost",
36
- icon: "ph--info--regular",
37
- iconOnly: true,
38
- label: t("toggle info button"),
39
- size: 6,
40
- classNames: mx("invisible", !open && "@3xl:visible"),
41
- onClick: () => setOpen((open2) => !open2)
42
- })), /* @__PURE__ */ React.createElement("div", {
43
- className: mx("grid _grid-rows-[1fr_4rem] 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-SZMONNHG.mjs.map