@dxos/plugin-chess 0.8.4-main.fd6878d → 0.8.4-main.fffef41

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 (122) hide show
  1. package/dist/lib/browser/{ChessboardContainer-NNIOQIRP.mjs → ChessboardContainer-5YXEM4VR.mjs} +29 -23
  2. package/dist/lib/browser/ChessboardContainer-5YXEM4VR.mjs.map +7 -0
  3. package/dist/lib/browser/blueprint-definition-FD4TL5EE.mjs +11 -0
  4. package/dist/lib/browser/blueprint-definition-FD4TL5EE.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-5DOZV3PW.mjs +294 -0
  6. package/dist/lib/browser/chunk-5DOZV3PW.mjs.map +7 -0
  7. package/dist/lib/browser/{chunk-PE3IWOFR.mjs → chunk-DUO4WTAM.mjs} +5 -5
  8. package/dist/lib/browser/chunk-DUO4WTAM.mjs.map +7 -0
  9. package/dist/lib/browser/{chunk-OBJAHY6H.mjs → chunk-FBLAVAMY.mjs} +17 -12
  10. package/dist/lib/browser/chunk-FBLAVAMY.mjs.map +7 -0
  11. package/dist/lib/browser/{chunk-PPBBLHAC.mjs → chunk-Q5TZCIH7.mjs} +2 -2
  12. package/dist/lib/browser/chunk-TIIGNOGK.mjs +169 -0
  13. package/dist/lib/browser/chunk-TIIGNOGK.mjs.map +7 -0
  14. package/dist/lib/browser/index.mjs +27 -19
  15. package/dist/lib/browser/index.mjs.map +3 -3
  16. package/dist/lib/browser/{intent-resolver-JWKKRNGG.mjs → intent-resolver-GXZN2EBT.mjs} +5 -5
  17. package/dist/lib/browser/{intent-resolver-JWKKRNGG.mjs.map → intent-resolver-GXZN2EBT.mjs.map} +1 -1
  18. package/dist/lib/browser/meta.json +1 -1
  19. package/dist/lib/browser/{react-surface-RIXD6RTS.mjs → react-surface-KTTAUHAA.mjs} +7 -7
  20. package/dist/lib/browser/{react-surface-RIXD6RTS.mjs.map → react-surface-KTTAUHAA.mjs.map} +1 -1
  21. package/dist/lib/browser/types/index.mjs +2 -2
  22. package/dist/lib/node-esm/{ChessboardContainer-FCPUV2T2.mjs → ChessboardContainer-7OQ6TOKB.mjs} +29 -23
  23. package/dist/lib/node-esm/ChessboardContainer-7OQ6TOKB.mjs.map +7 -0
  24. package/dist/lib/node-esm/blueprint-definition-O7ZM3HUF.mjs +12 -0
  25. package/dist/lib/node-esm/blueprint-definition-O7ZM3HUF.mjs.map +7 -0
  26. package/dist/lib/node-esm/chunk-F4C2HVZL.mjs +295 -0
  27. package/dist/lib/node-esm/chunk-F4C2HVZL.mjs.map +7 -0
  28. package/dist/lib/node-esm/{chunk-6OWCPDUA.mjs → chunk-KNOOJFIR.mjs} +5 -5
  29. package/dist/lib/node-esm/chunk-KNOOJFIR.mjs.map +7 -0
  30. package/dist/lib/node-esm/{chunk-LCCUF5X5.mjs → chunk-MP3A3AGA.mjs} +17 -12
  31. package/dist/lib/node-esm/chunk-MP3A3AGA.mjs.map +7 -0
  32. package/dist/lib/node-esm/chunk-RTCAAOLF.mjs +170 -0
  33. package/dist/lib/node-esm/chunk-RTCAAOLF.mjs.map +7 -0
  34. package/dist/lib/node-esm/{chunk-42EKKMOO.mjs → chunk-VVXTAVIS.mjs} +2 -2
  35. package/dist/lib/node-esm/index.mjs +27 -19
  36. package/dist/lib/node-esm/index.mjs.map +3 -3
  37. package/dist/lib/node-esm/{intent-resolver-G6XJAW6C.mjs → intent-resolver-HK5L6P6Z.mjs} +5 -5
  38. package/dist/lib/node-esm/{intent-resolver-G6XJAW6C.mjs.map → intent-resolver-HK5L6P6Z.mjs.map} +1 -1
  39. package/dist/lib/node-esm/meta.json +1 -1
  40. package/dist/lib/node-esm/{react-surface-GGRDWZJT.mjs → react-surface-VO4PSY6O.mjs} +7 -7
  41. package/dist/lib/node-esm/{react-surface-GGRDWZJT.mjs.map → react-surface-VO4PSY6O.mjs.map} +1 -1
  42. package/dist/lib/node-esm/types/index.mjs +2 -2
  43. package/dist/types/src/ChessPlugin.d.ts +1 -1
  44. package/dist/types/src/ChessPlugin.d.ts.map +1 -1
  45. package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -1
  46. package/dist/types/src/capabilities/blueprint-definition.d.ts +4 -1
  47. package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -1
  48. package/dist/types/src/capabilities/index.d.ts +3 -2
  49. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  50. package/dist/types/src/capabilities/intent-resolver.d.ts +1 -1
  51. package/dist/types/src/capabilities/react-surface.d.ts +1 -1
  52. package/dist/types/src/components/Card.stories.d.ts +14 -41
  53. package/dist/types/src/components/Card.stories.d.ts.map +1 -1
  54. package/dist/types/src/components/Chessboard.d.ts +19 -13
  55. package/dist/types/src/components/Chessboard.d.ts.map +1 -1
  56. package/dist/types/src/components/Chessboard.stories.d.ts +41 -39
  57. package/dist/types/src/components/Chessboard.stories.d.ts.map +1 -1
  58. package/dist/types/src/components/ChessboardArticle.d.ts +2 -1
  59. package/dist/types/src/components/ChessboardArticle.d.ts.map +1 -1
  60. package/dist/types/src/components/{ChessboardInfo.d.ts → Info.d.ts} +7 -6
  61. package/dist/types/src/components/Info.d.ts.map +1 -0
  62. package/dist/types/src/functions/create.d.ts +14 -0
  63. package/dist/types/src/functions/create.d.ts.map +1 -0
  64. package/dist/types/src/functions/index.d.ts +1 -0
  65. package/dist/types/src/functions/index.d.ts.map +1 -1
  66. package/dist/types/src/functions/move.d.ts +3 -1
  67. package/dist/types/src/functions/move.d.ts.map +1 -1
  68. package/dist/types/src/functions/play.d.ts +2 -1
  69. package/dist/types/src/functions/play.d.ts.map +1 -1
  70. package/dist/types/src/meta.d.ts +0 -1
  71. package/dist/types/src/meta.d.ts.map +1 -1
  72. package/dist/types/src/translations.d.ts +8 -6
  73. package/dist/types/src/translations.d.ts.map +1 -1
  74. package/dist/types/src/types/Chess.d.ts +8 -5
  75. package/dist/types/src/types/Chess.d.ts.map +1 -1
  76. package/dist/types/src/types/ChessAction.d.ts +3 -2
  77. package/dist/types/src/types/ChessAction.d.ts.map +1 -1
  78. package/dist/types/tsconfig.tsbuildinfo +1 -1
  79. package/package.json +42 -35
  80. package/src/ChessPlugin.tsx +47 -46
  81. package/src/capabilities/artifact-definition.ts +3 -2
  82. package/src/capabilities/blueprint-definition.ts +9 -7
  83. package/src/capabilities/index.ts +2 -0
  84. package/src/components/Card.stories.tsx +13 -15
  85. package/src/components/Chessboard.stories.tsx +13 -14
  86. package/src/components/Chessboard.tsx +104 -28
  87. package/src/components/ChessboardArticle.tsx +32 -21
  88. package/src/components/ChessboardContainer.tsx +1 -1
  89. package/src/components/Info.tsx +236 -0
  90. package/src/functions/create.ts +32 -0
  91. package/src/functions/index.ts +1 -0
  92. package/src/functions/move.ts +16 -14
  93. package/src/functions/play.ts +25 -15
  94. package/src/meta.ts +4 -4
  95. package/src/translations.ts +8 -6
  96. package/src/types/Chess.ts +23 -19
  97. package/src/types/ChessAction.ts +1 -1
  98. package/dist/lib/browser/ChessboardContainer-NNIOQIRP.mjs.map +0 -7
  99. package/dist/lib/browser/blueprint-definition-OJQYAZGZ.mjs +0 -38
  100. package/dist/lib/browser/blueprint-definition-OJQYAZGZ.mjs.map +0 -7
  101. package/dist/lib/browser/chunk-2W3S5N6C.mjs +0 -257
  102. package/dist/lib/browser/chunk-2W3S5N6C.mjs.map +0 -7
  103. package/dist/lib/browser/chunk-EJMPHRSR.mjs +0 -94
  104. package/dist/lib/browser/chunk-EJMPHRSR.mjs.map +0 -7
  105. package/dist/lib/browser/chunk-OBJAHY6H.mjs.map +0 -7
  106. package/dist/lib/browser/chunk-PE3IWOFR.mjs.map +0 -7
  107. package/dist/lib/node-esm/ChessboardContainer-FCPUV2T2.mjs.map +0 -7
  108. package/dist/lib/node-esm/blueprint-definition-F5SGHCDA.mjs +0 -39
  109. package/dist/lib/node-esm/blueprint-definition-F5SGHCDA.mjs.map +0 -7
  110. package/dist/lib/node-esm/chunk-5APYXPBX.mjs +0 -95
  111. package/dist/lib/node-esm/chunk-5APYXPBX.mjs.map +0 -7
  112. package/dist/lib/node-esm/chunk-6OWCPDUA.mjs.map +0 -7
  113. package/dist/lib/node-esm/chunk-LCCUF5X5.mjs.map +0 -7
  114. package/dist/lib/node-esm/chunk-QAGOXJGH.mjs +0 -258
  115. package/dist/lib/node-esm/chunk-QAGOXJGH.mjs.map +0 -7
  116. package/dist/types/src/components/ChessboardInfo.d.ts.map +0 -1
  117. package/dist/types/src/components/ChessboardPlayers.d.ts +0 -8
  118. package/dist/types/src/components/ChessboardPlayers.d.ts.map +0 -1
  119. package/src/components/ChessboardInfo.tsx +0 -140
  120. package/src/components/ChessboardPlayers.tsx +0 -97
  121. /package/dist/lib/browser/{chunk-PPBBLHAC.mjs.map → chunk-Q5TZCIH7.mjs.map} +0 -0
  122. /package/dist/lib/node-esm/{chunk-42EKKMOO.mjs.map → chunk-VVXTAVIS.mjs.map} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/plugin-chess",
3
- "version": "0.8.4-main.fd6878d",
3
+ "version": "0.8.4-main.fffef41",
4
4
  "description": "Chess for new plugin",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -20,6 +20,12 @@
20
20
  "types": "./dist/types/src/types/index.d.ts",
21
21
  "browser": "./dist/lib/browser/types/index.mjs",
22
22
  "node": "./dist/lib/node-esm/types/index.mjs"
23
+ },
24
+ "./functions": {
25
+ "source": "./src/functions/index.ts",
26
+ "types": "./dist/types/src/functions/index.d.ts",
27
+ "browser": "./dist/lib/browser/functions/index.mjs",
28
+ "node": "./dist/lib/node-esm/functions/index.mjs"
23
29
  }
24
30
  },
25
31
  "types": "dist/types/src/index.d.ts",
@@ -36,45 +42,46 @@
36
42
  ],
37
43
  "dependencies": {
38
44
  "@preact-signals/safe-react": "^0.9.0",
39
- "@preact/signals-core": "^1.9.0",
45
+ "@preact/signals-core": "^1.12.1",
40
46
  "chess.js": "^1.0.0",
41
- "effect": "3.17.7",
42
- "@dxos/ai": "0.8.4-main.fd6878d",
43
- "@dxos/app-framework": "0.8.4-main.fd6878d",
44
- "@dxos/assistant": "0.8.4-main.fd6878d",
45
- "@dxos/async": "0.8.4-main.fd6878d",
46
- "@dxos/blueprints": "0.8.4-main.fd6878d",
47
- "@dxos/display-name": "0.8.4-main.fd6878d",
48
- "@dxos/echo-schema": "0.8.4-main.fd6878d",
49
- "@dxos/functions": "0.8.4-main.fd6878d",
50
- "@dxos/invariant": "0.8.4-main.fd6878d",
51
- "@dxos/echo": "0.8.4-main.fd6878d",
52
- "@dxos/live-object": "0.8.4-main.fd6878d",
53
- "@dxos/log": "0.8.4-main.fd6878d",
54
- "@dxos/plugin-client": "0.8.4-main.fd6878d",
55
- "@dxos/plugin-graph": "0.8.4-main.fd6878d",
56
- "@dxos/plugin-space": "0.8.4-main.fd6878d",
57
- "@dxos/react-ui-stack": "0.8.4-main.fd6878d",
58
- "@dxos/util": "0.8.4-main.fd6878d",
59
- "@dxos/react-client": "0.8.4-main.fd6878d",
60
- "@dxos/react-ui-gameboard": "0.8.4-main.fd6878d"
47
+ "effect": "3.18.3",
48
+ "@dxos/ai": "0.8.4-main.fffef41",
49
+ "@dxos/app-framework": "0.8.4-main.fffef41",
50
+ "@dxos/assistant": "0.8.4-main.fffef41",
51
+ "@dxos/display-name": "0.8.4-main.fffef41",
52
+ "@dxos/blueprints": "0.8.4-main.fffef41",
53
+ "@dxos/echo": "0.8.4-main.fffef41",
54
+ "@dxos/functions": "0.8.4-main.fffef41",
55
+ "@dxos/invariant": "0.8.4-main.fffef41",
56
+ "@dxos/log": "0.8.4-main.fffef41",
57
+ "@dxos/plugin-client": "0.8.4-main.fffef41",
58
+ "@dxos/async": "0.8.4-main.fffef41",
59
+ "@dxos/live-object": "0.8.4-main.fffef41",
60
+ "@dxos/plugin-graph": "0.8.4-main.fffef41",
61
+ "@dxos/plugin-space": "0.8.4-main.fffef41",
62
+ "@dxos/react-client": "0.8.4-main.fffef41",
63
+ "@dxos/react-ui-sfx": "0.8.4-main.fffef41",
64
+ "@dxos/react-ui-stack": "0.8.4-main.fffef41",
65
+ "@dxos/schema": "0.8.4-main.fffef41",
66
+ "@dxos/util": "0.8.4-main.fffef41",
67
+ "@dxos/react-ui-gameboard": "0.8.4-main.fffef41"
61
68
  },
62
69
  "devDependencies": {
63
- "@types/react": "~18.2.0",
64
- "@types/react-dom": "~18.2.0",
65
- "react": "~18.2.0",
66
- "react-dom": "~18.2.0",
67
- "vite": "5.4.7",
68
- "@dxos/plugin-theme": "0.8.4-main.fd6878d",
69
- "@dxos/react-ui": "0.8.4-main.fd6878d",
70
- "@dxos/react-ui-theme": "0.8.4-main.fd6878d",
71
- "@dxos/storybook-utils": "0.8.4-main.fd6878d"
70
+ "@types/react": "~19.2.2",
71
+ "@types/react-dom": "~19.2.2",
72
+ "react": "~19.2.0",
73
+ "react-dom": "~19.2.0",
74
+ "vite": "7.1.9",
75
+ "@dxos/react-ui": "0.8.4-main.fffef41",
76
+ "@dxos/storybook-utils": "0.8.4-main.fffef41",
77
+ "@dxos/react-ui-theme": "0.8.4-main.fffef41",
78
+ "@dxos/plugin-theme": "0.8.4-main.fffef41"
72
79
  },
73
80
  "peerDependencies": {
74
- "react": "~18.2.0",
75
- "react-dom": "~18.2.0",
76
- "@dxos/react-ui": "0.8.4-main.fd6878d",
77
- "@dxos/react-ui-theme": "0.8.4-main.fd6878d"
81
+ "react": "^19.0.0",
82
+ "react-dom": "^19.0.0",
83
+ "@dxos/react-ui": "0.8.4-main.fffef41",
84
+ "@dxos/react-ui-theme": "0.8.4-main.fffef41"
78
85
  },
79
86
  "publishConfig": {
80
87
  "access": "public"
@@ -7,54 +7,55 @@ import { ClientEvents } from '@dxos/plugin-client';
7
7
  import { SpaceCapabilities } from '@dxos/plugin-space';
8
8
  import { defineObjectForm } from '@dxos/plugin-space/types';
9
9
 
10
- import { BlueprintDefinition, IntentResolver, ReactSurface } from './capabilities';
10
+ import { BlueprintDefinition, CHESS_BLUEPRINT_KEY, IntentResolver, ReactSurface } from './capabilities';
11
11
  import { meta } from './meta';
12
12
  import { translations } from './translations';
13
13
  import { Chess, ChessAction } from './types';
14
14
 
15
- export const ChessPlugin = () =>
16
- definePlugin(meta, [
17
- defineModule({
18
- id: `${meta.id}/module/translations`,
19
- activatesOn: Events.SetupTranslations,
20
- activate: () => contributes(Capabilities.Translations, translations),
21
- }),
22
- defineModule({
23
- id: `${meta.id}/module/metadata`,
24
- activatesOn: Events.SetupMetadata,
25
- activate: () =>
26
- contributes(Capabilities.Metadata, {
27
- id: Chess.Game.typename,
28
- metadata: {
29
- icon: 'ph--shield-chevron--regular',
30
- },
15
+ export const ChessPlugin = definePlugin(meta, () => [
16
+ defineModule({
17
+ id: `${meta.id}/module/translations`,
18
+ activatesOn: Events.SetupTranslations,
19
+ activate: () => contributes(Capabilities.Translations, translations),
20
+ }),
21
+ defineModule({
22
+ id: `${meta.id}/module/metadata`,
23
+ activatesOn: Events.SetupMetadata,
24
+ activate: () =>
25
+ contributes(Capabilities.Metadata, {
26
+ id: Chess.Game.typename,
27
+ metadata: {
28
+ icon: 'ph--shield-chevron--regular',
29
+ iconHue: 'amber',
30
+ blueprints: [CHESS_BLUEPRINT_KEY],
31
+ },
32
+ }),
33
+ }),
34
+ defineModule({
35
+ id: `${meta.id}/module/object-form`,
36
+ activatesOn: ClientEvents.SetupSchema,
37
+ activate: () =>
38
+ contributes(
39
+ SpaceCapabilities.ObjectForm,
40
+ defineObjectForm({
41
+ objectSchema: Chess.Game,
42
+ getIntent: () => createIntent(ChessAction.Create),
31
43
  }),
32
- }),
33
- defineModule({
34
- id: `${meta.id}/module/object-form`,
35
- activatesOn: ClientEvents.SetupSchema,
36
- activate: () =>
37
- contributes(
38
- SpaceCapabilities.ObjectForm,
39
- defineObjectForm({
40
- objectSchema: Chess.Game,
41
- getIntent: () => createIntent(ChessAction.Create),
42
- }),
43
- ),
44
- }),
45
- defineModule({
46
- id: `${meta.id}/module/react-surface`,
47
- activatesOn: Events.SetupReactSurface,
48
- activate: ReactSurface,
49
- }),
50
- defineModule({
51
- id: `${meta.id}/module/intent-resolver`,
52
- activatesOn: Events.SetupIntentResolver,
53
- activate: IntentResolver,
54
- }),
55
- defineModule({
56
- id: `${meta.id}/module/blueprint`,
57
- activatesOn: Events.SetupArtifactDefinition,
58
- activate: BlueprintDefinition,
59
- }),
60
- ]);
44
+ ),
45
+ }),
46
+ defineModule({
47
+ id: `${meta.id}/module/react-surface`,
48
+ activatesOn: Events.SetupReactSurface,
49
+ activate: ReactSurface,
50
+ }),
51
+ defineModule({
52
+ id: `${meta.id}/module/intent-resolver`,
53
+ activatesOn: Events.SetupIntentResolver,
54
+ activate: IntentResolver,
55
+ }),
56
+ defineModule({
57
+ id: `${meta.id}/module/blueprint`,
58
+ activatesOn: Events.SetupArtifactDefinition,
59
+ activate: BlueprintDefinition,
60
+ }),
61
+ ]);
@@ -6,7 +6,8 @@
6
6
  // @ts-nocheck
7
7
 
8
8
  import { Chess as ChessJS } from 'chess.js';
9
- import { Schema, pipe } from 'effect';
9
+ import * as Function from 'effect/Function';
10
+ import * as Schema from 'effect/Schema';
10
11
 
11
12
  import { ToolResult, createTool } from '@dxos/ai';
12
13
  import { Capabilities, type PromiseIntentDispatcher, chain, contributes, createIntent } from '@dxos/app-framework';
@@ -50,7 +51,7 @@ export default () => {
50
51
  execute: async ({ pgn }, { extensions }) => {
51
52
  invariant(extensions?.space, 'No space');
52
53
  invariant(extensions?.dispatch, 'No intent dispatcher');
53
- const intent = pipe(
54
+ const intent = Function.pipe(
54
55
  createIntent(ChessAction.Create, { pgn }),
55
56
  chain(SpaceAction.AddObject, { target: extensions.space }),
56
57
  );
@@ -2,33 +2,35 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { ToolId } from '@dxos/ai';
6
5
  import { Capabilities, contributes } from '@dxos/app-framework';
7
6
  import { Blueprint, Template } from '@dxos/blueprints';
7
+ import { type FunctionDefinition } from '@dxos/functions';
8
8
  import { trim } from '@dxos/util';
9
9
 
10
- import { move, play } from '../functions';
10
+ import { create, move, play } from '../functions';
11
11
 
12
- const functions = [move, play];
12
+ const functions: FunctionDefinition[] = [create, move, play];
13
+
14
+ export const CHESS_BLUEPRINT_KEY = 'dxos.org/blueprint/chess';
13
15
 
14
16
  export default () => {
15
17
  return [
18
+ contributes(Capabilities.Functions, functions),
16
19
  contributes(
17
20
  Capabilities.BlueprintDefinition,
18
21
  Blueprint.make({
19
- key: 'dxos.org/blueprint/chess',
22
+ key: CHESS_BLUEPRINT_KEY,
20
23
  name: 'Chess',
24
+ tools: Blueprint.toolDefinitions({ functions }),
21
25
  instructions: Template.make({
22
26
  source: trim`
23
27
  You are an expert chess player.
28
+ To analyze a game you can access the "pgn" property by loading the context object that represents the current game.
24
29
  You could suggest a good next move or offer to play a move.
25
30
  Don't actually make a move unless you are asked to.
26
- To analyze a game you can retrieve the "pgn" property from the context object.
27
31
  `,
28
32
  }),
29
- tools: functions.map((tool) => ToolId.make(tool.name)),
30
33
  }),
31
34
  ),
32
- contributes(Capabilities.Functions, functions),
33
35
  ];
34
36
  };
@@ -7,3 +7,5 @@ import { lazy } from '@dxos/app-framework';
7
7
  export const BlueprintDefinition = lazy(() => import('./blueprint-definition'));
8
8
  export const IntentResolver = lazy(() => import('./intent-resolver'));
9
9
  export const ReactSurface = lazy(() => import('./react-surface'));
10
+
11
+ export * from './blueprint-definition';
@@ -2,15 +2,13 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
6
-
7
5
  import { type Meta, type StoryObj } from '@storybook/react-vite';
8
6
  import React from 'react';
9
7
 
8
+ import { withTheme } from '@dxos/react-ui/testing';
10
9
  import { CardContainer } from '@dxos/react-ui-stack/testing';
11
- import { withTheme } from '@dxos/storybook-utils';
12
10
 
13
- import { meta } from '../meta';
11
+ import { meta as pluginMeta } from '../meta';
14
12
  import { Chess } from '../types';
15
13
 
16
14
  import { Chessboard } from './Chessboard';
@@ -20,10 +18,10 @@ type DefaultStoryProps = {
20
18
  game: Chess.Game;
21
19
  };
22
20
 
23
- const storybook: Meta<DefaultStoryProps> = {
21
+ const meta = {
24
22
  title: 'plugins/plugin-chess/Card',
25
23
  render: ({ role, game }) => (
26
- <CardContainer icon={meta.icon} role={role}>
24
+ <CardContainer icon={pluginMeta.icon} role={role}>
27
25
  <Chessboard.Root game={game}>
28
26
  <Chessboard.Content role={role}>
29
27
  <Chessboard.Board />
@@ -36,33 +34,33 @@ const storybook: Meta<DefaultStoryProps> = {
36
34
  layout: 'centered',
37
35
  },
38
36
  tags: ['cards'],
39
- };
37
+ } satisfies Meta<DefaultStoryProps>;
40
38
 
41
- export default storybook;
39
+ export default meta;
42
40
 
43
41
  const game = Chess.makeGame({
44
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 *',
45
43
  });
46
44
 
47
- type Story = StoryObj<DefaultStoryProps>;
45
+ type Story = StoryObj<typeof meta>;
48
46
 
49
- export const Popover = {
47
+ export const Popover: Story = {
50
48
  args: {
51
49
  role: 'card--popover',
52
50
  game: game,
53
51
  },
54
- } satisfies Story;
52
+ };
55
53
 
56
- export const Intrinsic = {
54
+ export const Intrinsic: Story = {
57
55
  args: {
58
56
  role: 'card--intrinsic',
59
57
  game: game,
60
58
  },
61
- } satisfies Story;
59
+ };
62
60
 
63
- export const Extrinsic = {
61
+ export const Extrinsic: Story = {
64
62
  args: {
65
63
  role: 'card--extrinsic',
66
64
  game: game,
67
65
  },
68
- } satisfies Story;
66
+ };
@@ -2,49 +2,48 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
6
-
7
5
  import { type Meta, type StoryObj } from '@storybook/react-vite';
8
6
 
9
7
  import { withClientProvider } from '@dxos/react-client/testing';
10
- import { withLayout, withTheme } from '@dxos/storybook-utils';
8
+ import { withTheme } from '@dxos/react-ui/testing';
11
9
 
12
10
  import { translations } from '../translations';
13
11
  import { Chess } from '../types';
14
12
 
15
13
  import { ChessboardArticle } from './ChessboardArticle';
16
14
 
17
- const meta: Meta<typeof ChessboardArticle> = {
15
+ const meta = {
18
16
  title: 'plugins/plugin-chess/Chessboard',
19
17
  component: ChessboardArticle,
20
- decorators: [withClientProvider({ createIdentity: true }), withTheme, withLayout({ fullscreen: true })],
18
+ decorators: [withTheme, withClientProvider({ createIdentity: true })],
21
19
  parameters: {
20
+ layout: 'fullscreen',
22
21
  translations,
23
22
  },
24
- };
25
-
26
- type Story = StoryObj<typeof meta>;
23
+ } satisfies Meta<typeof ChessboardArticle>;
27
24
 
28
25
  export default meta;
29
26
 
30
- export const Default = {
27
+ type Story = StoryObj<typeof meta>;
28
+
29
+ export const Default: Story = {
31
30
  args: {
32
31
  game: Chess.makeGame(),
33
32
  },
34
- } satisfies Story;
33
+ };
35
34
 
36
- export const EndGame = {
35
+ export const EndGame: Story = {
37
36
  args: {
38
37
  game: Chess.makeGame({
39
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 *',
40
39
  }),
41
40
  },
42
- } satisfies Story;
41
+ };
43
42
 
44
- export const Promption = {
43
+ export const Promption: Story = {
45
44
  args: {
46
45
  game: Chess.makeGame({
47
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 *',
48
47
  }),
49
48
  },
50
- } satisfies Story;
49
+ };
@@ -2,23 +2,37 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import React, { type PropsWithChildren, useCallback, useEffect, useMemo } from 'react';
6
-
7
- import { log } from '@dxos/log';
5
+ import React, {
6
+ type PropsWithChildren,
7
+ forwardRef,
8
+ useCallback,
9
+ useEffect,
10
+ useImperativeHandle,
11
+ useMemo,
12
+ useRef,
13
+ } from 'react';
14
+
15
+ import { addEventListener } from '@dxos/async';
8
16
  import { type ThemedClassName } from '@dxos/react-ui';
9
17
  import {
10
18
  ChessModel,
11
19
  Gameboard,
12
20
  type GameboardRootProps,
13
- Chessboard as NativeChessboard,
14
- type ChessboardProps as NativeChessboardProps,
21
+ Chessboard as NaturalChessboard,
22
+ type ChessboardProps as NaturalChessboardProps,
23
+ getRawPgn,
24
+ useGameboardContext,
15
25
  } from '@dxos/react-ui-gameboard';
26
+ import { useSoundEffect } from '@dxos/react-ui-sfx';
16
27
  import { mx } from '@dxos/react-ui-theme';
17
28
 
18
29
  import { type Chess } from '../types';
19
30
 
20
- import { ChessboardInfo, type ChessboardInfoProps } from './ChessboardInfo';
21
- import { ChessboardPlayers, type ChessboardPlayersProps } from './ChessboardPlayers';
31
+ import { Info, type InfoProps } from './Info';
32
+
33
+ export interface ChessboardController {
34
+ setMoveNumber(index: number): void;
35
+ }
22
36
 
23
37
  export class ExtendedChessModel extends ChessModel {
24
38
  constructor(readonly object: Chess.Game) {
@@ -30,25 +44,43 @@ export class ExtendedChessModel extends ChessModel {
30
44
  // Root
31
45
  //
32
46
 
33
- type ChessboardRootProps = PropsWithChildren<{
47
+ type RootProps = PropsWithChildren<{
34
48
  game: Chess.Game;
35
49
  }>;
36
50
 
37
- const ChessboardRoot = ({ game, children }: ChessboardRootProps) => {
51
+ const Root = forwardRef<ChessboardController, RootProps>(({ game, children }, forwardedRef) => {
38
52
  const model = useMemo(() => new ExtendedChessModel(game), []);
53
+ const click = useSoundEffect('Click');
54
+
55
+ // Controller.
56
+ useImperativeHandle(forwardedRef, () => {
57
+ return {
58
+ setMoveNumber: (index) => model.setMoveIndex(index),
59
+ };
60
+ }, [model]);
61
+
62
+ // External change.
63
+ // NOTE: Warning if user has not interacted with the board.
39
64
  useEffect(() => {
40
- model.update(game.pgn);
41
- log('update', { pgn: game.pgn });
65
+ if (model.pgn !== getRawPgn(game.pgn ?? '')) {
66
+ const silent = model.pgn === '*';
67
+ model.update(game.pgn);
68
+ if (!silent) {
69
+ void click.play();
70
+ }
71
+ }
42
72
  }, [game.pgn]);
43
73
 
74
+ // Move.
44
75
  const handleDrop = useCallback<NonNullable<GameboardRootProps<ChessModel>['onDrop']>>(
45
76
  (move) => {
46
- if (model.makeMove(move)) {
47
- game.pgn = model.pgn;
48
- return true;
77
+ if (!model.makeMove(move)) {
78
+ return false;
49
79
  }
50
80
 
51
- return false;
81
+ void click.play();
82
+ game.pgn = model.pgn;
83
+ return true;
52
84
  },
53
85
  [model],
54
86
  );
@@ -58,7 +90,7 @@ const ChessboardRoot = ({ game, children }: ChessboardRootProps) => {
58
90
  {children}
59
91
  </Gameboard.Root>
60
92
  );
61
- };
93
+ });
62
94
 
63
95
  //
64
96
  // Content
@@ -66,9 +98,9 @@ const ChessboardRoot = ({ game, children }: ChessboardRootProps) => {
66
98
 
67
99
  type Role = 'card--popover' | 'card--intrinsic' | 'card--extrinsic';
68
100
 
69
- type ChessboardContentProps = ThemedClassName<PropsWithChildren<{ role?: Role }>>;
101
+ type ContentProps = ThemedClassName<PropsWithChildren<{ role?: Role }>>;
70
102
 
71
- const ChessboardContent = ({ classNames, children, role }: ChessboardContentProps) => {
103
+ const Content = ({ classNames, children, role }: ContentProps) => {
72
104
  return (
73
105
  <Gameboard.Content
74
106
  classNames={mx(classNames, role === 'card--popover' && 'size-container popover-square')}
@@ -80,22 +112,66 @@ const ChessboardContent = ({ classNames, children, role }: ChessboardContentProp
80
112
  );
81
113
  };
82
114
 
115
+ //
116
+ // Board
117
+ //
118
+
119
+ type BoardProps = NaturalChessboardProps;
120
+
121
+ const Board = (props: BoardProps) => {
122
+ const { model } = useGameboardContext<ChessModel>(Board.displayName);
123
+
124
+ // Keyboard navigation.
125
+ const ref = useRef<HTMLDivElement>(null);
126
+ useEffect(() => {
127
+ if (!ref.current) {
128
+ return;
129
+ }
130
+
131
+ // Participate in keyboard navigation (set tabIndex={0})
132
+ ref.current.setAttribute('data-arrow-keys', 'all');
133
+
134
+ return addEventListener(ref.current, 'keydown', (ev) => {
135
+ switch (ev.key) {
136
+ case 'ArrowUp':
137
+ model.setMoveIndex(0);
138
+ break;
139
+ case 'ArrowDown':
140
+ model.setMoveIndex(model.game.history().length);
141
+ break;
142
+ case 'ArrowLeft':
143
+ if (model.moveIndex.value > 0) {
144
+ model.setMoveIndex(model.moveIndex.value - 1);
145
+ }
146
+ break;
147
+ case 'ArrowRight':
148
+ if (model.moveIndex.value < model.game.history().length) {
149
+ model.setMoveIndex(model.moveIndex.value + 1);
150
+ }
151
+ break;
152
+ }
153
+ });
154
+ }, [model]);
155
+
156
+ return <NaturalChessboard ref={ref} {...props} />;
157
+ };
158
+
159
+ Board.displayName = 'Chessboard.Board';
160
+
83
161
  //
84
162
  // Chessboard
85
163
  //
86
164
 
87
165
  export const Chessboard = {
88
- Root: ChessboardRoot,
89
- Content: ChessboardContent,
90
- Board: NativeChessboard,
91
- Info: ChessboardInfo,
92
- Players: ChessboardPlayers,
166
+ Root: Root,
167
+ Content: Content,
168
+ Board: Board,
169
+ Info: Info,
93
170
  };
94
171
 
95
172
  export type {
96
- ChessboardRootProps,
97
- ChessboardContentProps,
98
- NativeChessboardProps as ChessboardBoardProps,
99
- ChessboardInfoProps,
100
- ChessboardPlayersProps,
173
+ RootProps as ChessboardRootProps,
174
+ ContentProps as ChessboardContentProps,
175
+ BoardProps as ChessboardBoardProps,
176
+ InfoProps as ChessboardInfoProps,
101
177
  };