@dxos/plugin-chess 0.8.4-main.422d1c7879 → 0.8.4-main.4f23b4e393

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 (194) hide show
  1. package/dist/lib/neutral/ChessArticle-QLLKZGPH.mjs +88 -0
  2. package/dist/lib/neutral/ChessArticle-QLLKZGPH.mjs.map +7 -0
  3. package/dist/lib/neutral/ChessCard-I5RSZZIP.mjs +19 -0
  4. package/dist/lib/neutral/ChessCard-I5RSZZIP.mjs.map +7 -0
  5. package/dist/lib/neutral/ChessPlugin.mjs +30 -0
  6. package/dist/lib/neutral/ChessPlugin.mjs.map +7 -0
  7. package/dist/lib/neutral/ChessPlugin.node.mjs +23 -0
  8. package/dist/lib/neutral/ChessPlugin.node.mjs.map +7 -0
  9. package/dist/lib/neutral/blueprint-definition-PZXHAYLD.mjs +15 -0
  10. package/dist/lib/neutral/blueprint-definition-PZXHAYLD.mjs.map +7 -0
  11. package/dist/lib/neutral/blueprints/index.mjs +8 -0
  12. package/dist/lib/neutral/capabilities/index.mjs +13 -0
  13. package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
  14. package/dist/lib/neutral/chunk-5UOTTW6U.mjs +8 -0
  15. package/dist/lib/neutral/chunk-5UOTTW6U.mjs.map +7 -0
  16. package/dist/lib/neutral/chunk-E4LZPHAQ.mjs +148 -0
  17. package/dist/lib/neutral/chunk-E4LZPHAQ.mjs.map +7 -0
  18. package/dist/lib/neutral/chunk-FFXSIHW6.mjs +21 -0
  19. package/dist/lib/neutral/chunk-FFXSIHW6.mjs.map +7 -0
  20. package/dist/lib/{browser/chunk-MC7L6JNC.mjs → neutral/chunk-XWKNXG62.mjs} +8 -10
  21. package/dist/lib/neutral/chunk-XWKNXG62.mjs.map +7 -0
  22. package/dist/lib/{browser → neutral/components}/index.mjs +8 -158
  23. package/dist/lib/neutral/components/index.mjs.map +7 -0
  24. package/dist/lib/neutral/containers/index.mjs +11 -0
  25. package/dist/lib/neutral/containers/index.mjs.map +7 -0
  26. package/dist/lib/neutral/game-variant-24UKIBRM.mjs +40 -0
  27. package/dist/lib/neutral/game-variant-24UKIBRM.mjs.map +7 -0
  28. package/dist/lib/neutral/index.mjs +18 -0
  29. package/dist/lib/neutral/meta.json +1 -0
  30. package/dist/lib/neutral/meta.mjs +8 -0
  31. package/dist/lib/neutral/move-RQZ7BJY3.mjs +37 -0
  32. package/dist/lib/neutral/move-RQZ7BJY3.mjs.map +7 -0
  33. package/dist/lib/neutral/operation-handler-EKZKFQUG.mjs +13 -0
  34. package/dist/lib/neutral/operation-handler-EKZKFQUG.mjs.map +7 -0
  35. package/dist/lib/{browser/types → neutral/operations}/index.mjs +3 -3
  36. package/dist/lib/neutral/play-GDGCEPQL.mjs +46 -0
  37. package/dist/lib/neutral/play-GDGCEPQL.mjs.map +7 -0
  38. package/dist/lib/neutral/plugin.mjs +16 -0
  39. package/dist/lib/neutral/plugin.mjs.map +7 -0
  40. package/dist/lib/{browser/print-EW7LPW4D.mjs → neutral/print-ZQA74KZI.mjs} +5 -6
  41. package/dist/lib/neutral/print-ZQA74KZI.mjs.map +7 -0
  42. package/dist/lib/neutral/translations.mjs +34 -0
  43. package/dist/lib/neutral/translations.mjs.map +7 -0
  44. package/dist/lib/neutral/types/index.mjs +10 -0
  45. package/dist/types/src/ChessPlugin.d.ts +1 -0
  46. package/dist/types/src/ChessPlugin.d.ts.map +1 -1
  47. package/dist/types/src/ChessPlugin.node.d.ts +8 -0
  48. package/dist/types/src/ChessPlugin.node.d.ts.map +1 -0
  49. package/dist/types/src/blueprints/chess-blueprint.d.ts +2 -2
  50. package/dist/types/src/blueprints/chess-blueprint.d.ts.map +1 -1
  51. package/dist/types/src/blueprints/index.d.ts +0 -1
  52. package/dist/types/src/blueprints/index.d.ts.map +1 -1
  53. package/dist/types/src/capabilities/blueprint-definition.d.ts +2 -2
  54. package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -1
  55. package/dist/types/src/capabilities/game-variant.d.ts +6 -0
  56. package/dist/types/src/capabilities/game-variant.d.ts.map +1 -0
  57. package/dist/types/src/capabilities/index.d.ts +3 -3
  58. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  59. package/dist/types/src/capabilities/operation-handler.d.ts +1 -1
  60. package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -1
  61. package/dist/types/src/components/Chessboard/Chessboard.d.ts +6 -2
  62. package/dist/types/src/components/Chessboard/Chessboard.d.ts.map +1 -1
  63. package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts +32 -23
  64. package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts.map +1 -1
  65. package/dist/types/src/components/Chessboard/Info.d.ts +4 -5
  66. package/dist/types/src/components/Chessboard/Info.d.ts.map +1 -1
  67. package/dist/types/src/components/Chessboard/types.d.ts +2 -2
  68. package/dist/types/src/components/Chessboard/types.d.ts.map +1 -1
  69. package/dist/types/src/containers/ChessArticle/ChessArticle.d.ts +3 -4
  70. package/dist/types/src/containers/ChessArticle/ChessArticle.d.ts.map +1 -1
  71. package/dist/types/src/containers/ChessArticle/ChessArticle.stories.d.ts +32 -23
  72. package/dist/types/src/containers/ChessArticle/ChessArticle.stories.d.ts.map +1 -1
  73. package/dist/types/src/containers/ChessCard/ChessCard.d.ts +3 -4
  74. package/dist/types/src/containers/ChessCard/ChessCard.d.ts.map +1 -1
  75. package/dist/types/src/containers/ChessCard/ChessCard.stories.d.ts.map +1 -1
  76. package/dist/types/src/index.d.ts +0 -2
  77. package/dist/types/src/index.d.ts.map +1 -1
  78. package/dist/types/src/operations/index.d.ts +2 -3
  79. package/dist/types/src/operations/index.d.ts.map +1 -1
  80. package/dist/types/src/operations/move.d.ts +3 -3
  81. package/dist/types/src/operations/move.d.ts.map +1 -1
  82. package/dist/types/src/operations/play.d.ts +3 -3
  83. package/dist/types/src/operations/play.d.ts.map +1 -1
  84. package/dist/types/src/operations/print.d.ts +3 -3
  85. package/dist/types/src/operations/print.d.ts.map +1 -1
  86. package/dist/types/src/{cli/plugin.d.ts → plugin.d.ts} +1 -0
  87. package/dist/types/src/plugin.d.ts.map +1 -0
  88. package/dist/types/src/translations.d.ts +32 -24
  89. package/dist/types/src/translations.d.ts.map +1 -1
  90. package/dist/types/src/types/Chess.d.ts +10 -19
  91. package/dist/types/src/types/Chess.d.ts.map +1 -1
  92. package/dist/types/src/types/ChessOperation.d.ts +24 -0
  93. package/dist/types/src/types/ChessOperation.d.ts.map +1 -0
  94. package/dist/types/src/types/index.d.ts +1 -0
  95. package/dist/types/src/types/index.d.ts.map +1 -1
  96. package/dist/types/tsconfig.tsbuildinfo +1 -1
  97. package/package.json +91 -68
  98. package/src/ChessPlugin.node.ts +23 -0
  99. package/src/ChessPlugin.test.ts +8 -10
  100. package/src/ChessPlugin.tsx +11 -34
  101. package/src/blueprints/chess-blueprint.ts +6 -9
  102. package/src/blueprints/index.ts +0 -1
  103. package/src/capabilities/blueprint-definition.ts +2 -0
  104. package/src/capabilities/game-variant.ts +42 -0
  105. package/src/capabilities/index.ts +3 -2
  106. package/src/capabilities/operation-handler.ts +3 -3
  107. package/src/components/Chessboard/Chessboard.stories.tsx +3 -3
  108. package/src/components/Chessboard/Chessboard.tsx +4 -4
  109. package/src/components/Chessboard/Info.tsx +3 -63
  110. package/src/components/Chessboard/types.ts +1 -1
  111. package/src/containers/ChessArticle/ChessArticle.stories.tsx +9 -3
  112. package/src/containers/ChessArticle/ChessArticle.tsx +45 -10
  113. package/src/containers/ChessCard/ChessCard.stories.tsx +7 -2
  114. package/src/containers/ChessCard/ChessCard.tsx +10 -5
  115. package/src/index.ts +0 -3
  116. package/src/operations/index.ts +2 -7
  117. package/src/operations/move.ts +13 -13
  118. package/src/operations/play.ts +14 -14
  119. package/src/operations/print.ts +3 -3
  120. package/src/plugin.ts +11 -0
  121. package/src/translations.ts +6 -10
  122. package/src/types/Chess.ts +19 -22
  123. package/src/{operations/definitions.ts → types/ChessOperation.ts} +10 -34
  124. package/src/types/index.ts +1 -0
  125. package/dist/lib/browser/blueprints/index.mjs +0 -14
  126. package/dist/lib/browser/chunk-2TJN26DN.mjs +0 -67
  127. package/dist/lib/browser/chunk-2TJN26DN.mjs.map +0 -7
  128. package/dist/lib/browser/chunk-JZMN24DY.mjs +0 -28
  129. package/dist/lib/browser/chunk-JZMN24DY.mjs.map +0 -7
  130. package/dist/lib/browser/chunk-MC7L6JNC.mjs.map +0 -7
  131. package/dist/lib/browser/chunk-XAJZK6Z2.mjs +0 -110
  132. package/dist/lib/browser/chunk-XAJZK6Z2.mjs.map +0 -7
  133. package/dist/lib/browser/cli/index.mjs +0 -34
  134. package/dist/lib/browser/cli/index.mjs.map +0 -7
  135. package/dist/lib/browser/create-AJHN4QT4.mjs +0 -24
  136. package/dist/lib/browser/create-AJHN4QT4.mjs.map +0 -7
  137. package/dist/lib/browser/index.mjs.map +0 -7
  138. package/dist/lib/browser/meta.json +0 -1
  139. package/dist/lib/browser/move-T2NLRBR4.mjs +0 -36
  140. package/dist/lib/browser/move-T2NLRBR4.mjs.map +0 -7
  141. package/dist/lib/browser/operations/index.mjs +0 -19
  142. package/dist/lib/browser/play-7VTMD3SJ.mjs +0 -45
  143. package/dist/lib/browser/play-7VTMD3SJ.mjs.map +0 -7
  144. package/dist/lib/browser/print-EW7LPW4D.mjs.map +0 -7
  145. package/dist/lib/node-esm/blueprints/index.mjs +0 -15
  146. package/dist/lib/node-esm/chunk-4HZWCKMR.mjs +0 -38
  147. package/dist/lib/node-esm/chunk-4HZWCKMR.mjs.map +0 -7
  148. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +0 -11
  149. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +0 -7
  150. package/dist/lib/node-esm/chunk-LQEDIKCV.mjs +0 -29
  151. package/dist/lib/node-esm/chunk-LQEDIKCV.mjs.map +0 -7
  152. package/dist/lib/node-esm/chunk-NYU5JVXP.mjs +0 -111
  153. package/dist/lib/node-esm/chunk-NYU5JVXP.mjs.map +0 -7
  154. package/dist/lib/node-esm/chunk-OIRJVY2R.mjs +0 -68
  155. package/dist/lib/node-esm/chunk-OIRJVY2R.mjs.map +0 -7
  156. package/dist/lib/node-esm/cli/index.mjs +0 -35
  157. package/dist/lib/node-esm/cli/index.mjs.map +0 -7
  158. package/dist/lib/node-esm/create-QSETDT4N.mjs +0 -25
  159. package/dist/lib/node-esm/create-QSETDT4N.mjs.map +0 -7
  160. package/dist/lib/node-esm/index.mjs +0 -390
  161. package/dist/lib/node-esm/index.mjs.map +0 -7
  162. package/dist/lib/node-esm/meta.json +0 -1
  163. package/dist/lib/node-esm/move-5F2ANDTE.mjs +0 -37
  164. package/dist/lib/node-esm/move-5F2ANDTE.mjs.map +0 -7
  165. package/dist/lib/node-esm/operations/index.mjs +0 -20
  166. package/dist/lib/node-esm/play-W4DQCQRX.mjs +0 -46
  167. package/dist/lib/node-esm/play-W4DQCQRX.mjs.map +0 -7
  168. package/dist/lib/node-esm/print-UJHXAXMS.mjs +0 -31
  169. package/dist/lib/node-esm/print-UJHXAXMS.mjs.map +0 -7
  170. package/dist/lib/node-esm/types/index.mjs +0 -9
  171. package/dist/lib/node-esm/types/index.mjs.map +0 -7
  172. package/dist/types/src/capabilities/artifact-definition.d.ts +0 -12
  173. package/dist/types/src/capabilities/artifact-definition.d.ts.map +0 -1
  174. package/dist/types/src/capabilities/react-surface.d.ts +0 -5
  175. package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
  176. package/dist/types/src/cli/index.d.ts +0 -2
  177. package/dist/types/src/cli/index.d.ts.map +0 -1
  178. package/dist/types/src/cli/plugin.d.ts.map +0 -1
  179. package/dist/types/src/operations/create.d.ts +0 -5
  180. package/dist/types/src/operations/create.d.ts.map +0 -1
  181. package/dist/types/src/operations/definitions.d.ts +0 -51
  182. package/dist/types/src/operations/definitions.d.ts.map +0 -1
  183. package/src/capabilities/artifact-definition.ts +0 -135
  184. package/src/capabilities/react-surface.tsx +0 -35
  185. package/src/cli/index.ts +0 -5
  186. package/src/cli/plugin.ts +0 -37
  187. package/src/operations/create.ts +0 -21
  188. /package/dist/lib/{browser → neutral}/blueprints/index.mjs.map +0 -0
  189. /package/dist/lib/{browser → neutral}/chunk-J5LGTIGS.mjs +0 -0
  190. /package/dist/lib/{browser → neutral}/chunk-J5LGTIGS.mjs.map +0 -0
  191. /package/dist/lib/{browser/operations → neutral}/index.mjs.map +0 -0
  192. /package/dist/lib/{browser/types/index.mjs.map → neutral/meta.mjs.map} +0 -0
  193. /package/dist/lib/{node-esm/blueprints → neutral/operations}/index.mjs.map +0 -0
  194. /package/dist/lib/{node-esm/operations → neutral/types}/index.mjs.map +0 -0
@@ -2,20 +2,22 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
+ import { Chess as ChessJS } from 'chess.js';
5
6
  import React, { useCallback, useRef, useState } from 'react';
6
7
 
7
- import { type AppSurface } from '@dxos/app-toolkit/ui';
8
+ import { Obj } from '@dxos/echo';
9
+ import { type GameVariantSurfaceProps } from '@dxos/plugin-game';
8
10
  import { Panel, Toolbar, useTranslation } from '@dxos/react-ui';
9
11
  import { type Player } from '@dxos/react-ui-gameboard';
10
12
  import { mx } from '@dxos/ui-theme';
11
13
 
12
14
  import { Chessboard, type ChessboardController, type ChessboardInfoProps } from '#components';
13
15
  import { meta } from '#meta';
14
- import { type Chess } from '#types';
16
+ import { Chess } from '#types';
15
17
 
16
- export type ChessArticleProps = AppSurface.ObjectArticleProps<Chess.Game>;
18
+ export type ChessArticleProps = GameVariantSurfaceProps;
17
19
 
18
- export const ChessArticle = ({ role, attendableId: _attendableId, subject: game }: ChessArticleProps) => {
20
+ export const ChessArticle = ({ role, variant }: ChessArticleProps) => {
19
21
  const { t } = useTranslation(meta.id);
20
22
  const [orientation, setOrientation] = useState<Player>('white');
21
23
  const [showInfo, setShowInfo] = useState(true);
@@ -25,17 +27,50 @@ export const ChessArticle = ({ role, attendableId: _attendableId, subject: game
25
27
  controller.current?.setMoveNumber(index);
26
28
  }, []);
27
29
 
30
+ const isGameOver = (() => {
31
+ if (!Obj.instanceOf(Chess.State, variant) || (!variant.pgn && !variant.fen)) {
32
+ return false;
33
+ }
34
+ try {
35
+ const chess = new ChessJS();
36
+ if (variant.pgn) {
37
+ chess.loadPgn(variant.pgn);
38
+ } else if (variant.fen) {
39
+ chess.load(variant.fen);
40
+ }
41
+ return chess.isGameOver();
42
+ } catch {
43
+ return false;
44
+ }
45
+ })();
46
+
47
+ const handleNewGame = useCallback(() => {
48
+ if (!Obj.instanceOf(Chess.State, variant)) {
49
+ return;
50
+ }
51
+ Obj.update(variant, (variant) => {
52
+ const mutable = variant as Obj.Mutable<typeof variant>;
53
+ mutable.pgn = undefined;
54
+ mutable.fen = undefined;
55
+ });
56
+ }, [variant]);
57
+
58
+ if (!Obj.instanceOf(Chess.State, variant)) {
59
+ return null;
60
+ }
61
+
28
62
  return (
29
- <Chessboard.Root game={game} ref={controller}>
63
+ <Chessboard.Root state={variant} ref={controller}>
30
64
  <Panel.Root role={role} classNames='@container'>
31
65
  <Panel.Toolbar asChild>
32
66
  <Toolbar.Root>
67
+ {isGameOver && <Toolbar.Button onClick={handleNewGame}>{t('new-game.button')}</Toolbar.Button>}
68
+ <div className='grow' />
33
69
  <Toolbar.IconButton
34
70
  icon='ph--info--regular'
35
71
  iconOnly
36
72
  label={t('toggle-info.button')}
37
- disabled={showInfo}
38
- classNames={mx('invisible @3xl:visible')}
73
+ classNames={mx('invisible @4xl:visible')}
39
74
  onClick={() => setShowInfo((open) => !open)}
40
75
  />
41
76
  </Toolbar.Root>
@@ -44,17 +79,17 @@ export const ChessArticle = ({ role, attendableId: _attendableId, subject: game
44
79
  <div
45
80
  className={mx(
46
81
  'grid h-full w-full',
47
- showInfo && '@3xl:grid-cols-[1fr_320px] gap-8',
82
+ showInfo && '@4xl:grid-cols-[1fr_320px] gap-8',
48
83
  role === 'article' && 'p-4',
49
84
  role === 'section' && 'aspect-square',
50
- role === 'section' && showInfo && '@3xl:aspect-auto',
85
+ role === 'section' && showInfo && '@4xl:aspect-auto',
51
86
  )}
52
87
  >
53
88
  <Chessboard.Content>
54
89
  <Chessboard.Board classNames='border rounded-xs' orientation={orientation} />
55
90
  </Chessboard.Content>
56
91
  {showInfo && (
57
- <div className='hidden @3xl:flex flex-col justify-center items-center overflow-hidden'>
92
+ <div className='hidden @4xl:flex flex-col justify-center items-center overflow-hidden'>
58
93
  <Chessboard.Info
59
94
  orientation={orientation}
60
95
  min={8}
@@ -5,6 +5,7 @@
5
5
  import { type Meta, type StoryObj } from '@storybook/react-vite';
6
6
  import React, { useMemo } from 'react';
7
7
 
8
+ import { make as makeGame } from '@dxos/plugin-game';
8
9
  import { CardContainer } from '@dxos/react-ui-mosaic/testing';
9
10
  import { withLayout, withTheme } from '@dxos/react-ui/testing';
10
11
 
@@ -17,10 +18,14 @@ const SAMPLE_PGN =
17
18
  '1. e4 e5 2. Nf3 Nc6 3. Bc4 Bc5 4. c3 Nf6 5. d4 exd4 6. cxd4 Bb4+ 7. Nc3 d5 8. exd5 Nxd5 9. O-O Be6 10. Qb3 Na5 11. Qa4+ c6 12. Bxd5 Bxc3 13. Bxe6 fxe6 14. d5 Qg5 15. dxe6 Qg4 16. e7 Kf7 17. bxc3 Kg6 *';
18
19
 
19
20
  const CardStory = () => {
20
- const game = useMemo(() => Chess.make({ pgn: SAMPLE_PGN }), []);
21
+ const { game, state } = useMemo(() => {
22
+ const state = Chess.make({ pgn: SAMPLE_PGN });
23
+ const game = makeGame({ name: 'Story game', variant: state });
24
+ return { game, state };
25
+ }, []);
21
26
  return (
22
27
  <CardContainer role='popover' icon={pluginMeta.icon}>
23
- <ChessCard subject={game} role='card--content' />
28
+ <ChessCard role='card--content' game={game} variant={state} />
24
29
  </CardContainer>
25
30
  );
26
31
  };
@@ -4,16 +4,21 @@
4
4
 
5
5
  import React from 'react';
6
6
 
7
- import { type AppSurface } from '@dxos/app-toolkit/ui';
7
+ import { Obj } from '@dxos/echo';
8
+ import { type GameVariantSurfaceProps } from '@dxos/plugin-game';
8
9
 
9
10
  import { Chessboard } from '#components';
10
- import { type Chess } from '#types';
11
+ import { Chess } from '#types';
11
12
 
12
- export type ChessCardProps = AppSurface.ObjectCardProps<Chess.Game>;
13
+ export type ChessCardProps = GameVariantSurfaceProps;
14
+
15
+ export const ChessCard = ({ variant }: ChessCardProps) => {
16
+ if (!Obj.instanceOf(Chess.State, variant)) {
17
+ return null;
18
+ }
13
19
 
14
- export const ChessCard = ({ subject: game }: ChessCardProps) => {
15
20
  return (
16
- <Chessboard.Root game={game}>
21
+ <Chessboard.Root state={variant}>
17
22
  <Chessboard.Content>
18
23
  <Chessboard.Board />
19
24
  </Chessboard.Content>
package/src/index.ts CHANGED
@@ -3,8 +3,5 @@
3
3
  //
4
4
 
5
5
  export * from './blueprints';
6
- export * from './components/Chessboard';
7
6
  export * from './meta';
8
7
  export * from './types';
9
-
10
- export * from './ChessPlugin';
@@ -2,15 +2,10 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { OperationHandlerSet } from '@dxos/operation';
5
+ import { OperationHandlerSet } from '@dxos/compute';
6
6
 
7
- const Handlers = OperationHandlerSet.lazy(
8
- () => import('./create'),
7
+ export const ChessOperationHandlerSet = OperationHandlerSet.lazy(
9
8
  () => import('./move'),
10
9
  () => import('./play'),
11
10
  () => import('./print'),
12
11
  );
13
-
14
- export { Create, Move, Play, Print } from './definitions';
15
-
16
- export const ChessHandlers = Handlers;
@@ -5,28 +5,28 @@
5
5
  import { Chess as ChessJS } from 'chess.js';
6
6
  import * as Effect from 'effect/Effect';
7
7
 
8
- import { Database, Obj } from '@dxos/echo';
9
- import { Operation } from '@dxos/operation';
8
+ import { Operation } from '@dxos/compute';
9
+ import { Obj } from '@dxos/echo';
10
+ import { loadGame } from '@dxos/plugin-game';
10
11
 
11
- import { type Chess } from '../types';
12
- import { Move } from './definitions';
12
+ import { Chess, ChessOperation } from '../types';
13
13
 
14
- const handler: Operation.WithHandler<typeof Move> = Move.pipe(
14
+ const handler: Operation.WithHandler<typeof ChessOperation.Move> = ChessOperation.Move.pipe(
15
15
  Operation.withHandler(
16
16
  Effect.fn(function* ({ game, move }) {
17
- const obj = (yield* Database.load(game)) as Chess.Game;
17
+ const { variant } = yield* loadGame(game, Chess.State);
18
18
  const chess = new ChessJS();
19
- if (obj.pgn) {
20
- chess.loadPgn(obj.pgn);
21
- } else if (obj.fen) {
22
- chess.load(obj.fen);
19
+ if (variant.pgn) {
20
+ chess.loadPgn(variant.pgn);
21
+ } else if (variant.fen) {
22
+ chess.load(variant.fen);
23
23
  }
24
24
 
25
25
  chess.move(move, { strict: false });
26
26
  const pgn = chess.pgn();
27
- Obj.change(obj, (obj) => {
28
- const mutableGame = obj as Obj.Mutable<typeof obj>;
29
- mutableGame.pgn = pgn;
27
+ Obj.update(variant, (variant) => {
28
+ const mutable = variant as Obj.Mutable<typeof variant>;
29
+ mutable.pgn = pgn;
30
30
  });
31
31
  return { pgn };
32
32
  }),
@@ -5,27 +5,27 @@
5
5
  import { Chess as ChessJS } from 'chess.js';
6
6
  import * as Effect from 'effect/Effect';
7
7
 
8
- import { Database, Obj } from '@dxos/echo';
9
- import { Operation } from '@dxos/operation';
8
+ import { Operation } from '@dxos/compute';
9
+ import { Obj } from '@dxos/echo';
10
+ import { loadGame } from '@dxos/plugin-game';
10
11
 
11
- import { type Chess } from '../types';
12
- import { Play } from './definitions';
12
+ import { Chess, ChessOperation } from '../types';
13
13
 
14
- const handler: Operation.WithHandler<typeof Play> = Play.pipe(
14
+ const handler: Operation.WithHandler<typeof ChessOperation.Play> = ChessOperation.Play.pipe(
15
15
  Operation.withHandler(
16
16
  Effect.fn(function* ({ game, side = 'any' }) {
17
- const object = (yield* Database.load(game)) as Chess.Game;
17
+ const { variant } = yield* loadGame(game, Chess.State);
18
18
  const chess = new ChessJS();
19
- if (object.pgn) {
20
- chess.loadPgn(object.pgn);
21
- } else if (object.fen) {
22
- chess.load(object.fen);
19
+ if (variant.pgn) {
20
+ chess.loadPgn(variant.pgn);
21
+ } else if (variant.fen) {
22
+ chess.load(variant.fen);
23
23
  }
24
24
 
25
25
  if (
26
26
  !(side === 'any' || (chess.turn() === 'w' && side === 'white') || (chess.turn() === 'b' && side === 'black'))
27
27
  ) {
28
- return { move: undefined, pgn: object.pgn! };
28
+ return { move: undefined, pgn: variant.pgn ?? '' };
29
29
  }
30
30
 
31
31
  const moves = chess.moves();
@@ -33,9 +33,9 @@ const handler: Operation.WithHandler<typeof Play> = Play.pipe(
33
33
 
34
34
  chess.move(move, { strict: false });
35
35
  const pgn = chess.pgn();
36
- Obj.change(object, (object) => {
37
- const mutableGame = object as Obj.Mutable<typeof object>;
38
- mutableGame.pgn = pgn;
36
+ Obj.update(variant, (variant) => {
37
+ const mutable = variant as Obj.Mutable<typeof variant>;
38
+ mutable.pgn = pgn;
39
39
  });
40
40
  return { move, pgn };
41
41
  }),
@@ -5,11 +5,11 @@
5
5
  import { Chess as ChessJS } from 'chess.js';
6
6
  import * as Effect from 'effect/Effect';
7
7
 
8
- import { Operation } from '@dxos/operation';
8
+ import { Operation } from '@dxos/compute';
9
9
 
10
- import { Print } from './definitions';
10
+ import { ChessOperation } from '../types';
11
11
 
12
- const handler: Operation.WithHandler<typeof Print> = Print.pipe(
12
+ const handler: Operation.WithHandler<typeof ChessOperation.Print> = ChessOperation.Print.pipe(
13
13
  Operation.withHandler(
14
14
  Effect.fn(function* ({ pgn, fen }) {
15
15
  try {
package/src/plugin.ts ADDED
@@ -0,0 +1,11 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { Plugin } from '@dxos/app-framework';
6
+
7
+ import { meta } from './meta';
8
+
9
+ export const ChessPlugin = Plugin.lazy(meta, () => import('#plugin'));
10
+
11
+ export { ChessOperationHandlerSet } from './operations';
@@ -10,19 +10,15 @@ import { Chess } from '#types';
10
10
  export const translations = [
11
11
  {
12
12
  'en-US': {
13
- [Chess.Game.typename]: {
14
- 'typename.label': 'Game',
15
- 'typename.label_zero': 'Games',
16
- 'typename.label_one': 'Game',
17
- 'typename.label_other': 'Games',
18
- 'object-name.placeholder': 'New game',
19
- 'add-object.label': 'Add game',
20
- 'rename-object.label': 'Rename game',
21
- 'delete-object.label': 'Delete game',
22
- 'object-deleted.label': 'Game deleted',
13
+ [Chess.State.typename]: {
14
+ 'typename.label': 'Chess',
15
+ 'typename.label_zero': 'Chess games',
16
+ 'typename.label_one': 'Chess game',
17
+ 'typename.label_other': 'Chess games',
23
18
  },
24
19
  [meta.id]: {
25
20
  'plugin.name': 'Chess',
21
+ 'new-game.button': 'New game',
26
22
  'delete-game.label': 'Delete',
27
23
  'game.checkmate.label': 'Checkmate',
28
24
  'game.stalemate.label': 'Stalemate',
@@ -5,24 +5,18 @@
5
5
  import { Chess as ChessJS } from 'chess.js';
6
6
  import * as Schema from 'effect/Schema';
7
7
 
8
+ import { BlueprintsAnnotation } from '@dxos/app-toolkit';
8
9
  import { Annotation, Obj, Type } from '@dxos/echo';
9
- import { FormInputAnnotation, LabelAnnotation } from '@dxos/echo/internal';
10
+ import { FormInputAnnotation, SystemTypeAnnotation } from '@dxos/echo/internal';
10
11
  import { log } from '@dxos/log';
11
12
 
12
- export const Game = Schema.Struct({
13
- name: Schema.optional(Schema.String),
14
- players: Schema.Struct({
15
- white: Schema.optional(
16
- Schema.String.annotations({
17
- description: 'DID of white player',
18
- }),
19
- ),
20
- black: Schema.optional(
21
- Schema.String.annotations({
22
- description: 'DID of black player',
23
- }),
24
- ),
25
- }).pipe(FormInputAnnotation.set(false), Schema.optional),
13
+ export const BLUEPRINT_KEY = 'org.dxos.blueprint.chess';
14
+
15
+ /**
16
+ * Chess variant state. Referenced by the base `Game` object via `Game.variant`.
17
+ * Players, name, and other game-shared fields live on the base `Game`.
18
+ */
19
+ export const State = Schema.Struct({
26
20
  pgn: Schema.String.annotations({
27
21
  description: 'Portable Game Notation.',
28
22
  }).pipe(FormInputAnnotation.set(false), Schema.optional),
@@ -31,19 +25,24 @@ export const Game = Schema.Struct({
31
25
  }).pipe(FormInputAnnotation.set(false), Schema.optional),
32
26
  }).pipe(
33
27
  Type.object({
34
- typename: 'org.dxos.type.chess',
28
+ typename: 'org.dxos.type.chess.state',
35
29
  version: '0.1.0',
36
30
  }),
37
- LabelAnnotation.set(['name']),
38
31
  Annotation.IconAnnotation.set({
39
32
  icon: 'ph--shield-chevron--regular',
40
33
  hue: 'amber',
41
34
  }),
35
+ BlueprintsAnnotation.set([BLUEPRINT_KEY]),
36
+ // Implementation detail of the unified `Game` schema. The user-facing object is `Game`;
37
+ // this state is only ever referenced via `Game.variant`. SystemType keeps it out of the
38
+ // navtree's typed branches so an orphaned state object doesn't reappear after the
39
+ // wrapping Game is deleted.
40
+ SystemTypeAnnotation.set(true),
42
41
  );
43
42
 
44
- export interface Game extends Schema.Schema.Type<typeof Game> {}
43
+ export interface State extends Schema.Schema.Type<typeof State> {}
45
44
 
46
- export const make = ({ name, pgn, fen }: { name?: string; pgn?: string; fen?: string } = {}) => {
45
+ export const make = ({ pgn, fen }: { pgn?: string; fen?: string } = {}): State => {
47
46
  const chess = new ChessJS();
48
47
  if (pgn) {
49
48
  try {
@@ -53,10 +52,8 @@ export const make = ({ name, pgn, fen }: { name?: string; pgn?: string; fen?: st
53
52
  }
54
53
  }
55
54
 
56
- return Obj.make(Game, {
57
- name,
55
+ return Obj.make(State, {
58
56
  pgn,
59
57
  fen,
60
- players: {},
61
58
  });
62
59
  };
@@ -2,39 +2,15 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import * as Schema from 'effect/Schema';
5
+ // @import-as-namespace
6
6
 
7
- import { Database, Ref } from '@dxos/echo';
8
- import { Operation } from '@dxos/operation';
7
+ import * as Schema from 'effect/Schema';
9
8
 
10
- import { Chess } from '../types';
9
+ import { Operation } from '@dxos/compute';
10
+ import { Database } from '@dxos/echo';
11
+ import { GameRef } from '@dxos/plugin-game';
11
12
 
12
- export const Create = Operation.make({
13
- meta: {
14
- key: 'org.dxos.function.chess.create',
15
- name: 'Create Chess',
16
- description: 'Creates a new chess game.',
17
- },
18
- input: Schema.Struct({
19
- name: Schema.optional(
20
- Schema.String.annotations({
21
- description: 'Name of the game.',
22
- }),
23
- ),
24
- pgn: Schema.optional(
25
- Schema.String.annotations({
26
- description: 'Portable Game Notation.',
27
- }),
28
- ),
29
- fen: Schema.optional(
30
- Schema.String.annotations({
31
- description: 'Forsyth-Edwards Notation.',
32
- }),
33
- ),
34
- }),
35
- output: Chess.Game,
36
- services: [Database.Service],
37
- });
13
+ import * as Chess from './Chess';
38
14
 
39
15
  export const Move = Operation.make({
40
16
  meta: {
@@ -43,8 +19,8 @@ export const Move = Operation.make({
43
19
  description: 'Makes a move in the given chess game.',
44
20
  },
45
21
  input: Schema.Struct({
46
- game: Ref.Ref(Chess.Game).annotations({
47
- description: 'The ID of the chess object.',
22
+ game: GameRef(Chess.State).annotations({
23
+ description: 'The ID of the game object (variant must be Chess).',
48
24
  }),
49
25
  move: Schema.String.annotations({
50
26
  description: 'The move to make in the chess game.',
@@ -66,8 +42,8 @@ export const Play = Operation.make({
66
42
  description: 'Uses the chess engine to play the next move.',
67
43
  },
68
44
  input: Schema.Struct({
69
- game: Ref.Ref(Chess.Game).annotations({
70
- description: 'The ID of the chess object.',
45
+ game: GameRef(Chess.State).annotations({
46
+ description: 'The ID of the game object (variant must be Chess).',
71
47
  }),
72
48
  side: Schema.optional(Schema.Literal('white', 'black', 'any')).annotations({
73
49
  description: 'The side to play.',
@@ -3,3 +3,4 @@
3
3
  //
4
4
 
5
5
  export * as Chess from './Chess';
6
+ export * as ChessOperation from './ChessOperation';
@@ -1,14 +0,0 @@
1
- import {
2
- chess_blueprint_default
3
- } from "../chunk-MC7L6JNC.mjs";
4
- import {
5
- operations_exports
6
- } from "../chunk-JZMN24DY.mjs";
7
- import "../chunk-XAJZK6Z2.mjs";
8
- import "../chunk-2TJN26DN.mjs";
9
- import "../chunk-J5LGTIGS.mjs";
10
- export {
11
- chess_blueprint_default as ChessBlueprint,
12
- operations_exports as ChessFunctions
13
- };
14
- //# sourceMappingURL=index.mjs.map
@@ -1,67 +0,0 @@
1
- import {
2
- __export
3
- } from "./chunk-J5LGTIGS.mjs";
4
-
5
- // src/types/Chess.ts
6
- var Chess_exports = {};
7
- __export(Chess_exports, {
8
- Game: () => Game,
9
- make: () => make
10
- });
11
- import { Chess as ChessJS } from "chess.js";
12
- import * as Schema from "effect/Schema";
13
- import { Annotation, Obj, Type } from "@dxos/echo";
14
- import { FormInputAnnotation, LabelAnnotation } from "@dxos/echo/internal";
15
- import { log } from "@dxos/log";
16
- var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-chess/src/types/Chess.ts";
17
- var Game = Schema.Struct({
18
- name: Schema.optional(Schema.String),
19
- players: Schema.Struct({
20
- white: Schema.optional(Schema.String.annotations({
21
- description: "DID of white player"
22
- })),
23
- black: Schema.optional(Schema.String.annotations({
24
- description: "DID of black player"
25
- }))
26
- }).pipe(FormInputAnnotation.set(false), Schema.optional),
27
- pgn: Schema.String.annotations({
28
- description: "Portable Game Notation."
29
- }).pipe(FormInputAnnotation.set(false), Schema.optional),
30
- fen: Schema.String.annotations({
31
- description: "Forsyth-Edwards Notation."
32
- }).pipe(FormInputAnnotation.set(false), Schema.optional)
33
- }).pipe(Type.object({
34
- typename: "org.dxos.type.chess",
35
- version: "0.1.0"
36
- }), LabelAnnotation.set([
37
- "name"
38
- ]), Annotation.IconAnnotation.set({
39
- icon: "ph--shield-chevron--regular",
40
- hue: "amber"
41
- }));
42
- var make = ({ name, pgn, fen } = {}) => {
43
- const chess = new ChessJS();
44
- if (pgn) {
45
- try {
46
- chess.loadPgn(pgn);
47
- } catch {
48
- log.warn(pgn, void 0, {
49
- F: __dxlog_file,
50
- L: 52,
51
- S: void 0,
52
- C: (f, a) => f(...a)
53
- });
54
- }
55
- }
56
- return Obj.make(Game, {
57
- name,
58
- pgn,
59
- fen,
60
- players: {}
61
- });
62
- };
63
-
64
- export {
65
- Chess_exports
66
- };
67
- //# sourceMappingURL=chunk-2TJN26DN.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/types/Chess.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Chess as ChessJS } from 'chess.js';\nimport * as Schema from 'effect/Schema';\n\nimport { Annotation, Obj, Type } from '@dxos/echo';\nimport { FormInputAnnotation, LabelAnnotation } from '@dxos/echo/internal';\nimport { log } from '@dxos/log';\n\nexport const Game = Schema.Struct({\n name: Schema.optional(Schema.String),\n players: Schema.Struct({\n white: Schema.optional(\n Schema.String.annotations({\n description: 'DID of white player',\n }),\n ),\n black: Schema.optional(\n Schema.String.annotations({\n description: 'DID of black player',\n }),\n ),\n }).pipe(FormInputAnnotation.set(false), Schema.optional),\n pgn: Schema.String.annotations({\n description: 'Portable Game Notation.',\n }).pipe(FormInputAnnotation.set(false), Schema.optional),\n fen: Schema.String.annotations({\n description: 'Forsyth-Edwards Notation.',\n }).pipe(FormInputAnnotation.set(false), Schema.optional),\n}).pipe(\n Type.object({\n typename: 'org.dxos.type.chess',\n version: '0.1.0',\n }),\n LabelAnnotation.set(['name']),\n Annotation.IconAnnotation.set({\n icon: 'ph--shield-chevron--regular',\n hue: 'amber',\n }),\n);\n\nexport interface Game extends Schema.Schema.Type<typeof Game> {}\n\nexport const make = ({ name, pgn, fen }: { name?: string; pgn?: string; fen?: string } = {}) => {\n const chess = new ChessJS();\n if (pgn) {\n try {\n chess.loadPgn(pgn);\n } catch {\n log.warn(pgn);\n }\n }\n\n return Obj.make(Game, {\n name,\n pgn,\n fen,\n players: {},\n });\n};\n"],
5
- "mappings": ";;;;;AAAA;;;;;AAIA,SAASA,SAASC,eAAe;AACjC,YAAYC,YAAY;AAExB,SAASC,YAAYC,KAAKC,YAAY;AACtC,SAASC,qBAAqBC,uBAAuB;AACrD,SAASC,WAAW;;AAEb,IAAMC,OAAcC,cAAO;EAChCC,MAAaC,gBAAgBC,aAAM;EACnCC,SAAgBJ,cAAO;IACrBK,OAAcH,gBACLC,cAAOG,YAAY;MACxBC,aAAa;IACf,CAAA,CAAA;IAEFC,OAAcN,gBACLC,cAAOG,YAAY;MACxBC,aAAa;IACf,CAAA,CAAA;EAEJ,CAAA,EAAGE,KAAKb,oBAAoBc,IAAI,KAAA,GAAeR,eAAQ;EACvDS,KAAYR,cAAOG,YAAY;IAC7BC,aAAa;EACf,CAAA,EAAGE,KAAKb,oBAAoBc,IAAI,KAAA,GAAeR,eAAQ;EACvDU,KAAYT,cAAOG,YAAY;IAC7BC,aAAa;EACf,CAAA,EAAGE,KAAKb,oBAAoBc,IAAI,KAAA,GAAeR,eAAQ;AACzD,CAAA,EAAGO,KACDd,KAAKkB,OAAO;EACVC,UAAU;EACVC,SAAS;AACX,CAAA,GACAlB,gBAAgBa,IAAI;EAAC;CAAO,GAC5BjB,WAAWuB,eAAeN,IAAI;EAC5BO,MAAM;EACNC,KAAK;AACP,CAAA,CAAA;AAKK,IAAMC,OAAO,CAAC,EAAElB,MAAMU,KAAKC,IAAG,IAAoD,CAAC,MAAC;AACzF,QAAMQ,QAAQ,IAAI7B,QAAAA;AAClB,MAAIoB,KAAK;AACP,QAAI;AACFS,YAAMC,QAAQV,GAAAA;IAChB,QAAQ;AACNb,UAAIwB,KAAKX,KAAAA,QAAAA;;;;;;IACX;EACF;AAEA,SAAOjB,IAAIyB,KAAKpB,MAAM;IACpBE;IACAU;IACAC;IACAR,SAAS,CAAC;EACZ,CAAA;AACF;",
6
- "names": ["Chess", "ChessJS", "Schema", "Annotation", "Obj", "Type", "FormInputAnnotation", "LabelAnnotation", "log", "Game", "Struct", "name", "optional", "String", "players", "white", "annotations", "description", "black", "pipe", "set", "pgn", "fen", "object", "typename", "version", "IconAnnotation", "icon", "hue", "make", "chess", "loadPgn", "warn"]
7
- }
@@ -1,28 +0,0 @@
1
- import {
2
- Create,
3
- Move,
4
- Play,
5
- Print
6
- } from "./chunk-XAJZK6Z2.mjs";
7
- import {
8
- __export
9
- } from "./chunk-J5LGTIGS.mjs";
10
-
11
- // src/operations/index.ts
12
- var operations_exports = {};
13
- __export(operations_exports, {
14
- ChessHandlers: () => ChessHandlers,
15
- Create: () => Create,
16
- Move: () => Move,
17
- Play: () => Play,
18
- Print: () => Print
19
- });
20
- import { OperationHandlerSet } from "@dxos/operation";
21
- var Handlers = OperationHandlerSet.lazy(() => import("./create-AJHN4QT4.mjs"), () => import("./move-T2NLRBR4.mjs"), () => import("./play-7VTMD3SJ.mjs"), () => import("./print-EW7LPW4D.mjs"));
22
- var ChessHandlers = Handlers;
23
-
24
- export {
25
- ChessHandlers,
26
- operations_exports
27
- };
28
- //# sourceMappingURL=chunk-JZMN24DY.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/operations/index.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { OperationHandlerSet } from '@dxos/operation';\n\nconst Handlers = OperationHandlerSet.lazy(\n () => import('./create'),\n () => import('./move'),\n () => import('./play'),\n () => import('./print'),\n);\n\nexport { Create, Move, Play, Print } from './definitions';\n\nexport const ChessHandlers = Handlers;\n"],
5
- "mappings": ";;;;;;;;;;;AAAA;;;;;;;;AAIA,SAASA,2BAA2B;AAEpC,IAAMC,WAAWC,oBAAoBC,KACnC,MAAM,OAAO,uBAAA,GACb,MAAM,OAAO,qBAAA,GACb,MAAM,OAAO,qBAAA,GACb,MAAM,OAAO,sBAAA,CAAA;AAKR,IAAMC,gBAAgBH;",
6
- "names": ["OperationHandlerSet", "Handlers", "OperationHandlerSet", "lazy", "ChessHandlers"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/blueprints/chess-blueprint.ts"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { type AppCapabilities } from '@dxos/app-toolkit';\nimport { Blueprint, Template } from '@dxos/blueprints';\nimport { trim } from '@dxos/util';\n\nimport { Create, Move, Play, Print } from '#operations';\n\nconst BLUEPRINT_KEY = 'org.dxos.blueprint.chess';\n\nconst operations = [Create, Move, Play, Print];\n\nconst make = () =>\n Blueprint.make({\n key: BLUEPRINT_KEY,\n name: 'Chess',\n tools: Blueprint.toolDefinitions({ operations }),\n instructions: Template.make({\n source: trim`\n You are an expert chess player.\n To analyze a game you can access the \"pgn\" property by loading the context object that represents the current game.\n You could suggest a good next move or offer to play a move.\n Don't actually make a move unless you are asked to.\n `,\n }),\n });\n\nconst blueprint: AppCapabilities.BlueprintDefinition = {\n key: BLUEPRINT_KEY,\n make,\n};\n\nexport default blueprint;\n"],
5
- "mappings": ";AAKA,SAASA,WAAWC,gBAAgB;AACpC,SAASC,YAAY;AAErB,SAASC,QAAQC,MAAMC,MAAMC,aAAa;AAE1C,IAAMC,gBAAgB;AAEtB,IAAMC,aAAa;EAACC;EAAQC;EAAMC;EAAMC;;AAExC,IAAMC,OAAO,MACXC,UAAUD,KAAK;EACbE,KAAKR;EACLS,MAAM;EACNC,OAAOH,UAAUI,gBAAgB;IAAEV;EAAW,CAAA;EAC9CW,cAAcC,SAASP,KAAK;IAC1BQ,QAAQC;;;;;;EAMV,CAAA;AACF,CAAA;AAEF,IAAMC,YAAiD;EACrDR,KAAKR;EACLM;AACF;AAEA,IAAA,0BAAeU;",
6
- "names": ["Blueprint", "Template", "trim", "Create", "Move", "Play", "Print", "BLUEPRINT_KEY", "operations", "Create", "Move", "Play", "Print", "make", "Blueprint", "key", "name", "tools", "toolDefinitions", "instructions", "Template", "source", "trim", "blueprint"]
7
- }