@dxos/plugin-chess 0.7.5-labs.5f04cf6 → 0.7.5-labs.e27f9b9

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 (110) hide show
  1. package/dist/lib/browser/ChessContainer-2MMUB5S7.mjs +86 -0
  2. package/dist/lib/browser/ChessContainer-2MMUB5S7.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-672NU6IC.mjs +8 -0
  4. package/dist/lib/browser/chunk-672NU6IC.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-RGPTBDH7.mjs +41 -0
  6. package/dist/lib/browser/chunk-RGPTBDH7.mjs.map +7 -0
  7. package/dist/lib/browser/index.mjs +11 -19
  8. package/dist/lib/browser/index.mjs.map +3 -3
  9. package/dist/lib/browser/{intent-resolver-UZRNSQFI.mjs → intent-resolver-BKKGQ5TJ.mjs} +15 -12
  10. package/dist/lib/browser/intent-resolver-BKKGQ5TJ.mjs.map +7 -0
  11. package/dist/lib/browser/meta.json +1 -1
  12. package/dist/lib/browser/{react-surface-EP4LXPH7.mjs → react-surface-Y7XMQYOV.mjs} +6 -14
  13. package/dist/lib/browser/react-surface-Y7XMQYOV.mjs.map +7 -0
  14. package/dist/lib/node/ChessContainer-CMYJDMSG.cjs +108 -0
  15. package/dist/lib/node/ChessContainer-CMYJDMSG.cjs.map +7 -0
  16. package/dist/lib/node/{chunk-6F6WTM5L.cjs → chunk-TEZPML34.cjs} +5 -5
  17. package/dist/lib/node/chunk-TEZPML34.cjs.map +7 -0
  18. package/dist/lib/node/{ChessContainer-P4BZ62FN.cjs → chunk-YTD6SK5V.cjs} +37 -16
  19. package/dist/lib/node/chunk-YTD6SK5V.cjs.map +7 -0
  20. package/dist/lib/node/index.cjs +11 -19
  21. package/dist/lib/node/index.cjs.map +3 -3
  22. package/dist/lib/node/{intent-resolver-AENA6D5K.cjs → intent-resolver-OIFDW46S.cjs} +18 -15
  23. package/dist/lib/node/intent-resolver-OIFDW46S.cjs.map +7 -0
  24. package/dist/lib/node/meta.json +1 -1
  25. package/dist/lib/node/{react-surface-JMOSMAIC.cjs → react-surface-35CG6JQF.cjs} +9 -17
  26. package/dist/lib/node/react-surface-35CG6JQF.cjs.map +7 -0
  27. package/dist/lib/node-esm/ChessContainer-WV2CO5WO.mjs +87 -0
  28. package/dist/lib/node-esm/ChessContainer-WV2CO5WO.mjs.map +7 -0
  29. package/dist/lib/node-esm/chunk-GJW6TXCL.mjs +43 -0
  30. package/dist/lib/node-esm/chunk-GJW6TXCL.mjs.map +7 -0
  31. package/dist/lib/node-esm/{chunk-QXDXLFXD.mjs → chunk-YXXJHXSV.mjs} +2 -2
  32. package/dist/lib/node-esm/chunk-YXXJHXSV.mjs.map +7 -0
  33. package/dist/lib/node-esm/index.mjs +11 -19
  34. package/dist/lib/node-esm/index.mjs.map +3 -3
  35. package/dist/lib/node-esm/{intent-resolver-T7NNHOYR.mjs → intent-resolver-35HIBBYC.mjs} +15 -12
  36. package/dist/lib/node-esm/intent-resolver-35HIBBYC.mjs.map +7 -0
  37. package/dist/lib/node-esm/meta.json +1 -1
  38. package/dist/lib/node-esm/{react-surface-ENB7VY45.mjs → react-surface-4FNRAFRL.mjs} +6 -14
  39. package/dist/lib/node-esm/react-surface-4FNRAFRL.mjs.map +7 -0
  40. package/dist/types/src/ChessPlugin.d.ts.map +1 -1
  41. package/dist/types/src/capabilities/index.d.ts +3 -3
  42. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  43. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
  44. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  45. package/dist/types/src/components/ChessComponent.d.ts +6 -0
  46. package/dist/types/src/components/ChessComponent.d.ts.map +1 -0
  47. package/dist/types/src/components/ChessContainer.d.ts +4 -3
  48. package/dist/types/src/components/ChessContainer.d.ts.map +1 -1
  49. package/dist/types/src/components/ChessPanel.d.ts +11 -0
  50. package/dist/types/src/components/ChessPanel.d.ts.map +1 -0
  51. package/dist/types/src/components/Chessboard.stories.d.ts +8 -0
  52. package/dist/types/src/components/Chessboard.stories.d.ts.map +1 -0
  53. package/dist/types/src/components/{Chess.d.ts → PlayerSelector.d.ts} +3 -4
  54. package/dist/types/src/components/PlayerSelector.d.ts.map +1 -0
  55. package/dist/types/src/components/index.d.ts +3 -3
  56. package/dist/types/src/components/index.d.ts.map +1 -1
  57. package/dist/types/tsconfig.tsbuildinfo +1 -1
  58. package/package.json +21 -24
  59. package/src/ChessPlugin.tsx +5 -13
  60. package/src/capabilities/intent-resolver.ts +10 -8
  61. package/src/capabilities/react-surface.tsx +3 -12
  62. package/src/components/ChessComponent.tsx +48 -0
  63. package/src/components/ChessContainer.tsx +14 -4
  64. package/src/components/ChessPanel.tsx +67 -0
  65. package/src/components/Chessboard.stories.tsx +39 -0
  66. package/src/components/{Chess.tsx → PlayerSelector.tsx} +2 -50
  67. package/src/components/index.ts +1 -2
  68. package/dist/lib/browser/ChessContainer-G736GS2V.mjs +0 -26
  69. package/dist/lib/browser/ChessContainer-G736GS2V.mjs.map +0 -7
  70. package/dist/lib/browser/chunk-JUAC2NNR.mjs +0 -548
  71. package/dist/lib/browser/chunk-JUAC2NNR.mjs.map +0 -7
  72. package/dist/lib/browser/chunk-LAYER2WV.mjs +0 -8
  73. package/dist/lib/browser/chunk-LAYER2WV.mjs.map +0 -7
  74. package/dist/lib/browser/intent-resolver-UZRNSQFI.mjs.map +0 -7
  75. package/dist/lib/browser/react-surface-EP4LXPH7.mjs.map +0 -7
  76. package/dist/lib/node/ChessContainer-P4BZ62FN.cjs.map +0 -7
  77. package/dist/lib/node/chunk-6F6WTM5L.cjs.map +0 -7
  78. package/dist/lib/node/chunk-HPYER4GF.cjs +0 -574
  79. package/dist/lib/node/chunk-HPYER4GF.cjs.map +0 -7
  80. package/dist/lib/node/intent-resolver-AENA6D5K.cjs.map +0 -7
  81. package/dist/lib/node/react-surface-JMOSMAIC.cjs.map +0 -7
  82. package/dist/lib/node-esm/ChessContainer-2LFJ6RHB.mjs +0 -27
  83. package/dist/lib/node-esm/ChessContainer-2LFJ6RHB.mjs.map +0 -7
  84. package/dist/lib/node-esm/chunk-OMGVSBVI.mjs +0 -550
  85. package/dist/lib/node-esm/chunk-OMGVSBVI.mjs.map +0 -7
  86. package/dist/lib/node-esm/chunk-QXDXLFXD.mjs.map +0 -7
  87. package/dist/lib/node-esm/intent-resolver-T7NNHOYR.mjs.map +0 -7
  88. package/dist/lib/node-esm/react-surface-ENB7VY45.mjs.map +0 -7
  89. package/dist/types/src/components/Chess.d.ts.map +0 -1
  90. package/dist/types/src/components/Chessboard/Chessboard.d.ts +0 -37
  91. package/dist/types/src/components/Chessboard/Chessboard.d.ts.map +0 -1
  92. package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts +0 -24
  93. package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts.map +0 -1
  94. package/dist/types/src/components/Chessboard/index.d.ts +0 -2
  95. package/dist/types/src/components/Chessboard/index.d.ts.map +0 -1
  96. package/dist/types/src/components/Chessboard/pieces/custom.d.ts +0 -3
  97. package/dist/types/src/components/Chessboard/pieces/custom.d.ts.map +0 -1
  98. package/dist/types/src/components/Chessboard/pieces/index.d.ts +0 -4
  99. package/dist/types/src/components/Chessboard/pieces/index.d.ts.map +0 -1
  100. package/dist/types/src/components/Chessboard/pieces/phosphor.d.ts +0 -3
  101. package/dist/types/src/components/Chessboard/pieces/phosphor.d.ts.map +0 -1
  102. package/dist/types/src/components/Chessboard/pieces/riohacha.d.ts +0 -3
  103. package/dist/types/src/components/Chessboard/pieces/riohacha.d.ts.map +0 -1
  104. package/src/components/Chessboard/Chessboard.stories.tsx +0 -56
  105. package/src/components/Chessboard/Chessboard.tsx +0 -182
  106. package/src/components/Chessboard/index.ts +0 -5
  107. package/src/components/Chessboard/pieces/custom.tsx +0 -82
  108. package/src/components/Chessboard/pieces/index.ts +0 -7
  109. package/src/components/Chessboard/pieces/phosphor.tsx +0 -71
  110. package/src/components/Chessboard/pieces/riohacha.tsx +0 -166
@@ -0,0 +1,11 @@
1
+ import { type Color } from 'chess.js';
2
+ import { type FC } from 'react';
3
+ import { type ThemedClassName } from '@dxos/react-ui';
4
+ import { type ChessModel } from '@dxos/react-ui-gameboard';
5
+ export type ChessPanelProps = ThemedClassName<{
6
+ model: ChessModel;
7
+ orientation?: Color;
8
+ onFlip?: () => void;
9
+ }>;
10
+ export declare const ChessPanel: FC<ChessPanelProps>;
11
+ //# sourceMappingURL=ChessPanel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChessPanel.d.ts","sourceRoot":"","sources":["../../../../src/components/ChessPanel.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,UAAU,CAAC;AACtC,OAAc,EAAE,KAAK,EAAE,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAG3D,MAAM,MAAM,eAAe,GAAG,eAAe,CAAC;IAC5C,KAAK,EAAE,UAAU,CAAC;IAClB,WAAW,CAAC,EAAE,KAAK,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC,CAAC;AAEH,eAAO,MAAM,UAAU,EAAE,EAAE,CAAC,eAAe,CAgD1C,CAAC"}
@@ -0,0 +1,8 @@
1
+ import '@dxos-theme';
2
+ import { type Meta, type StoryObj } from '@storybook/react';
3
+ import { Chessboard } from '@dxos/react-ui-gameboard';
4
+ declare const meta: Meta<typeof Chessboard>;
5
+ type Story = StoryObj<typeof Chessboard>;
6
+ export default meta;
7
+ export declare const Default: Story;
8
+ //# sourceMappingURL=Chessboard.stories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Chessboard.stories.d.ts","sourceRoot":"","sources":["../../../../src/components/Chessboard.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAErB,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAG5D,OAAO,EAAS,UAAU,EAAc,MAAM,0BAA0B,CAAC;AAkBzE,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,UAAU,CAKjC,CAAC;AAEF,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,UAAU,CAAC,CAAC;AAEzC,eAAe,IAAI,CAAC;AAEpB,eAAO,MAAM,OAAO,EAAE,KAAU,CAAC"}
@@ -1,9 +1,8 @@
1
1
  import React from 'react';
2
2
  import { type Space } from '@dxos/react-client/echo';
3
3
  import { type ChessType } from '../types';
4
- export declare const Chess: ({ space, game, playerSelector }: {
4
+ export declare const PlayerSelector: ({ space, game }: {
5
5
  space: Space;
6
6
  game: ChessType;
7
- playerSelector?: boolean;
8
- }) => React.JSX.Element | null;
9
- //# sourceMappingURL=Chess.d.ts.map
7
+ }) => React.JSX.Element;
8
+ //# sourceMappingURL=PlayerSelector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlayerSelector.d.ts","sourceRoot":"","sources":["../../../../src/components/PlayerSelector.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAc,KAAK,KAAK,EAAoB,MAAM,yBAAyB,CAAC;AAInF,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,eAAO,MAAM,cAAc,oBAAqB;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,SAAS,CAAA;CAAE,sBAuBhF,CAAC"}
@@ -1,6 +1,6 @@
1
- export * from './Chess';
2
- export * from './Chessboard';
3
- export declare const ChessContainer: import("react").LazyExoticComponent<({ game, role }: Pick<import("react").ComponentProps<typeof import("./Chess").Chess>, "game"> & {
1
+ export * from './ChessComponent';
2
+ export declare const ChessContainer: import("react").LazyExoticComponent<({ game }: {
3
+ game: import("../types").ChessType;
4
4
  role?: string;
5
5
  }) => import("react").JSX.Element | null>;
6
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/index.ts"],"names":[],"mappings":"AAMA,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAE7B,eAAO,MAAM,cAAc;QACiG,CAAC;yCADzD,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/index.ts"],"names":[],"mappings":"AAMA,cAAc,kBAAkB,CAAC;AAEjC,eAAO,MAAM,cAAc;;QAC2K,CAAC;yCADnI,CAAC"}
@@ -1 +1 @@
1
- {"version":"5.7.2"}
1
+ {"version":"5.7.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/plugin-chess",
3
- "version": "0.7.5-labs.5f04cf6",
3
+ "version": "0.7.5-labs.e27f9b9",
4
4
  "description": "Chess for new plugin",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -35,42 +35,39 @@
35
35
  "@effect/schema": "^0.75.5",
36
36
  "@preact/signals-core": "^1.6.0",
37
37
  "chess.js": "^1.0.0",
38
- "react-chessboard": "^4.7.2",
39
- "react-dnd-html5-backend": "^16.0.1",
40
- "react-resize-detector": "^11.0.1",
41
- "@dxos/app-framework": "0.7.5-labs.5f04cf6",
42
- "@dxos/artifact": "0.7.5-labs.5f04cf6",
43
- "@dxos/assistant": "0.7.5-labs.5f04cf6",
44
- "@dxos/echo-schema": "0.7.5-labs.5f04cf6",
45
- "@dxos/display-name": "0.7.5-labs.5f04cf6",
46
- "@dxos/async": "0.7.5-labs.5f04cf6",
47
- "@dxos/invariant": "0.7.5-labs.5f04cf6",
48
- "@dxos/live-object": "0.7.5-labs.5f04cf6",
49
- "@dxos/plugin-client": "0.7.5-labs.5f04cf6",
50
- "@dxos/plugin-graph": "0.7.5-labs.5f04cf6",
51
- "@dxos/plugin-space": "0.7.5-labs.5f04cf6",
52
- "@dxos/react-ui-stack": "0.7.5-labs.5f04cf6",
53
- "@dxos/react-client": "0.7.5-labs.5f04cf6"
38
+ "effect": "^3.12.3",
39
+ "@dxos/artifact": "0.7.5-labs.e27f9b9",
40
+ "@dxos/app-framework": "0.7.5-labs.e27f9b9",
41
+ "@dxos/assistant": "0.7.5-labs.e27f9b9",
42
+ "@dxos/echo-schema": "0.7.5-labs.e27f9b9",
43
+ "@dxos/display-name": "0.7.5-labs.e27f9b9",
44
+ "@dxos/async": "0.7.5-labs.e27f9b9",
45
+ "@dxos/invariant": "0.7.5-labs.e27f9b9",
46
+ "@dxos/live-object": "0.7.5-labs.e27f9b9",
47
+ "@dxos/plugin-graph": "0.7.5-labs.e27f9b9",
48
+ "@dxos/plugin-space": "0.7.5-labs.e27f9b9",
49
+ "@dxos/plugin-client": "0.7.5-labs.e27f9b9",
50
+ "@dxos/react-client": "0.7.5-labs.e27f9b9",
51
+ "@dxos/react-ui-stack": "0.7.5-labs.e27f9b9",
52
+ "@dxos/react-ui-gameboard": "0.7.5-labs.e27f9b9"
54
53
  },
55
54
  "devDependencies": {
56
55
  "@phosphor-icons/react": "^2.1.5",
57
56
  "@types/react": "~18.2.0",
58
57
  "@types/react-dom": "~18.2.0",
59
- "effect": "^3.12.3",
60
58
  "react": "~18.2.0",
61
59
  "react-dom": "~18.2.0",
62
60
  "vite": "5.4.7",
63
- "@dxos/react-ui-theme": "0.7.5-labs.5f04cf6",
64
- "@dxos/storybook-utils": "0.7.5-labs.5f04cf6",
65
- "@dxos/react-ui": "0.7.5-labs.5f04cf6"
61
+ "@dxos/react-ui": "0.7.5-labs.e27f9b9",
62
+ "@dxos/react-ui-theme": "0.7.5-labs.e27f9b9",
63
+ "@dxos/storybook-utils": "0.7.5-labs.e27f9b9"
66
64
  },
67
65
  "peerDependencies": {
68
66
  "@phosphor-icons/react": "^2.1.5",
69
- "effect": "^3.12.3",
70
67
  "react": "~18.2.0",
71
68
  "react-dom": "~18.2.0",
72
- "@dxos/react-ui": "0.7.5-labs.5f04cf6",
73
- "@dxos/react-ui-theme": "0.7.5-labs.5f04cf6"
69
+ "@dxos/react-ui": "0.7.5-labs.e27f9b9",
70
+ "@dxos/react-ui-theme": "0.7.5-labs.e27f9b9"
74
71
  },
75
72
  "publishConfig": {
76
73
  "access": "public"
@@ -2,15 +2,7 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import {
6
- Capabilities,
7
- contributes,
8
- createIntent,
9
- defineModule,
10
- definePlugin,
11
- Events,
12
- oneOf,
13
- } from '@dxos/app-framework';
5
+ import { Capabilities, contributes, createIntent, defineModule, definePlugin, Events } from '@dxos/app-framework';
14
6
  import { ClientCapabilities, ClientEvents } from '@dxos/plugin-client';
15
7
 
16
8
  import { Artifact, IntentResolver, ReactSurface } from './capabilities';
@@ -27,7 +19,7 @@ export const ChessPlugin = () =>
27
19
  }),
28
20
  defineModule({
29
21
  id: `${meta.id}/module/metadata`,
30
- activatesOn: oneOf(Events.Startup, Events.SetupAppGraph),
22
+ activatesOn: Events.SetupMetadata,
31
23
  activate: () =>
32
24
  contributes(Capabilities.Metadata, {
33
25
  id: ChessType.typename,
@@ -40,17 +32,17 @@ export const ChessPlugin = () =>
40
32
  }),
41
33
  defineModule({
42
34
  id: `${meta.id}/module/schema`,
43
- activatesOn: ClientEvents.SetupClient,
35
+ activatesOn: ClientEvents.SetupSchema,
44
36
  activate: () => contributes(ClientCapabilities.Schema, [ChessType]),
45
37
  }),
46
38
  defineModule({
47
39
  id: `${meta.id}/module/react-surface`,
48
- activatesOn: Events.Startup,
40
+ activatesOn: Events.SetupSurfaces,
49
41
  activate: ReactSurface,
50
42
  }),
51
43
  defineModule({
52
44
  id: `${meta.id}/module/intent-resolver`,
53
- activatesOn: Events.Startup,
45
+ activatesOn: Events.SetupIntents,
54
46
  activate: IntentResolver,
55
47
  }),
56
48
  defineModule({
@@ -12,13 +12,15 @@ import { ChessAction, ChessType } from '../types';
12
12
  export default () =>
13
13
  contributes(
14
14
  Capabilities.IntentResolver,
15
- createResolver(ChessAction.Create, ({ name, fen }) => {
16
- const pgn = fen ? new Chess(fen).pgn() : undefined;
17
-
18
- return {
19
- data: {
20
- object: create(ChessType, { name, fen, pgn }),
21
- },
22
- };
15
+ createResolver({
16
+ intent: ChessAction.Create,
17
+ resolve: ({ name, fen }) => {
18
+ const pgn = fen ? new Chess(fen).pgn() : undefined;
19
+ return {
20
+ data: {
21
+ object: create(ChessType, { name, fen, pgn }),
22
+ },
23
+ };
24
+ },
23
25
  }),
24
26
  );
@@ -2,13 +2,13 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Chess } from 'chess.js';
6
5
  import React from 'react';
7
6
 
8
7
  import { Capabilities, contributes, createSurface } from '@dxos/app-framework';
9
8
  import { isInstanceOf } from '@dxos/echo-schema';
10
9
 
11
- import { Chessboard, ChessContainer } from '../components';
10
+ import { ChessContainer } from '../components';
11
+ import { ChessComponent } from '../components/ChessComponent';
12
12
  import { CHESS_PLUGIN } from '../meta';
13
13
  import { ChessType, isObject } from '../types';
14
14
 
@@ -24,15 +24,6 @@ export default () =>
24
24
  id: 'plugin-chess',
25
25
  role: 'canvas-node',
26
26
  filter: (data): data is any => isInstanceOf(ChessType, data),
27
- component: ({ data }) => (
28
- <Chessboard
29
- model={{ chess: new Chess(data.fen) }}
30
- onUpdate={(move) => {
31
- const board = new Chess(data.fen);
32
- board.move(move);
33
- data.value = board.fen();
34
- }}
35
- />
36
- ),
27
+ component: ({ data }) => <ChessComponent game={data} />,
37
28
  }),
38
29
  ]);
@@ -0,0 +1,48 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { Chess } from 'chess.js';
6
+ import React, { useCallback, useEffect, useMemo } from 'react';
7
+
8
+ import { getSpace } from '@dxos/react-client/echo';
9
+ import { ChessModel, Board, Chessboard, type BoardRootProps } from '@dxos/react-ui-gameboard';
10
+
11
+ import { type ChessType } from '../types';
12
+
13
+ export const ChessComponent = ({ game }: { game: ChessType }) => {
14
+ const model = useMemo(() => new ChessModel(), []);
15
+ useEffect(() => {
16
+ if (!model || game.pgn !== model?.game.pgn()) {
17
+ const chess = new Chess();
18
+ if (game.pgn) {
19
+ chess.loadPgn(game.pgn);
20
+ }
21
+
22
+ model.initialize(chess.fen());
23
+ }
24
+ }, [game.pgn]);
25
+
26
+ const space = getSpace(game);
27
+ if (!space) {
28
+ return null;
29
+ }
30
+
31
+ const handleDrop = useCallback<NonNullable<BoardRootProps['onDrop']>>(
32
+ (move) => {
33
+ if (model.makeMove(move)) {
34
+ game.pgn = model.game.pgn();
35
+ return true;
36
+ }
37
+
38
+ return false;
39
+ },
40
+ [model],
41
+ );
42
+
43
+ return (
44
+ <Board.Root model={model} onDrop={handleDrop}>
45
+ <Chessboard />
46
+ </Board.Root>
47
+ );
48
+ };
@@ -2,14 +2,16 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import React, { type ComponentProps } from 'react';
5
+ import React from 'react';
6
6
 
7
7
  import { getSpace } from '@dxos/react-client/echo';
8
8
  import { StackItem } from '@dxos/react-ui-stack';
9
9
 
10
- import { Chess } from './Chess';
10
+ import { ChessComponent } from './ChessComponent';
11
+ import { PlayerSelector } from './PlayerSelector';
12
+ import { type ChessType } from '../types';
11
13
 
12
- const ChessContainer = ({ game, role }: Pick<ComponentProps<typeof Chess>, 'game'> & { role?: string }) => {
14
+ const ChessContainer = ({ game }: { game: ChessType; role?: string }) => {
13
15
  const space = getSpace(game);
14
16
  if (!space) {
15
17
  return null;
@@ -17,7 +19,15 @@ const ChessContainer = ({ game, role }: Pick<ComponentProps<typeof Chess>, 'game
17
19
 
18
20
  return (
19
21
  <StackItem.Content toolbar={false}>
20
- <Chess game={game} space={space} playerSelector={role === 'article'} />
22
+ <div role='none' className='grid grid-rows-[60px_1fr_60px] grow overflow-hidden'>
23
+ <div />
24
+
25
+ <div className='flex m-4 overflow-hidden'>
26
+ <ChessComponent game={game} />
27
+ </div>
28
+
29
+ <PlayerSelector space={space} game={game} />
30
+ </div>
21
31
  </StackItem.Content>
22
32
  );
23
33
  };
@@ -0,0 +1,67 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { ArrowURightDown, Circle } from '@phosphor-icons/react';
6
+ import { type Color } from 'chess.js';
7
+ import React, { type FC } from 'react';
8
+
9
+ import { type ThemedClassName } from '@dxos/react-ui';
10
+ import { type ChessModel } from '@dxos/react-ui-gameboard';
11
+ import { getSize, mx } from '@dxos/react-ui-theme';
12
+
13
+ export type ChessPanelProps = ThemedClassName<{
14
+ model: ChessModel;
15
+ orientation?: Color;
16
+ onFlip?: () => void;
17
+ }>;
18
+
19
+ export const ChessPanel: FC<ChessPanelProps> = ({ classNames, model, orientation = 'w', onFlip }) => {
20
+ const game = model.game;
21
+ const history = game.history();
22
+ const label = game.isGameOver()
23
+ ? game.isCheckmate()
24
+ ? 'CHECKMATE'
25
+ : game.isStalemate()
26
+ ? 'STALEMATE'
27
+ : 'DRAW'
28
+ : game.isCheck()
29
+ ? 'CHECK'
30
+ : history.length
31
+ ? `Move ${history.length}`
32
+ : '';
33
+
34
+ const Player = ({ color }: { color: Color }) => {
35
+ const turn = color === game.turn();
36
+
37
+ return (
38
+ <div className='flex items-center'>
39
+ <Circle
40
+ className={mx(getSize(4), turn && (game.isCheckmate() ? 'text-red-500' : 'text-green-500'))}
41
+ weight={turn ? 'fill' : 'thin'}
42
+ />
43
+ </div>
44
+ );
45
+ };
46
+
47
+ return (
48
+ <div className={mx('flex flex-col', classNames)}>
49
+ <div className='flex items-center justify-between pl-2 pr-2 border-b' style={{ height: 32 }}>
50
+ <Player color={orientation === 'w' ? 'b' : 'w'} />
51
+ {onFlip && (
52
+ <button onClick={onFlip}>
53
+ <ArrowURightDown weight='thin' className={getSize(6)} />
54
+ </button>
55
+ )}
56
+ </div>
57
+
58
+ <div className='flex flex-col justify-center pl-2 font-thin' style={{ height: 40 }}>
59
+ {label}
60
+ </div>
61
+
62
+ <div className='flex items-center justify-between pl-2 pr-2 border-t' style={{ height: 32 }}>
63
+ <Player color={orientation} />
64
+ </div>
65
+ </div>
66
+ );
67
+ };
@@ -0,0 +1,39 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import '@dxos-theme';
6
+
7
+ import { type Meta, type StoryObj } from '@storybook/react';
8
+ import React, { useMemo } from 'react';
9
+
10
+ import { Board, Chessboard, ChessModel } from '@dxos/react-ui-gameboard';
11
+ import { withLayout, withTheme } from '@dxos/storybook-utils';
12
+
13
+ import { ChessPanel } from './ChessPanel';
14
+
15
+ const Render = () => {
16
+ const model = useMemo(() => new ChessModel(), []);
17
+
18
+ return (
19
+ <div className='flex grow mx-8 gap-8 items-center overflow-hidden'>
20
+ <Board.Root model={model} onDrop={(move) => model.makeMove(move)}>
21
+ <Chessboard />
22
+ </Board.Root>
23
+ <ChessPanel model={model} classNames='w-[200px]' />
24
+ </div>
25
+ );
26
+ };
27
+
28
+ const meta: Meta<typeof Chessboard> = {
29
+ title: 'plugins/plugin-chess/Chessboard',
30
+ component: Chessboard,
31
+ render: Render,
32
+ decorators: [withTheme, withLayout({ fullscreen: true })],
33
+ };
34
+
35
+ type Story = StoryObj<typeof Chessboard>;
36
+
37
+ export default meta;
38
+
39
+ export const Default: Story = {};
@@ -3,64 +3,16 @@
3
3
  //
4
4
 
5
5
  import { CrownCross } from '@phosphor-icons/react';
6
- import { Chess as ChessJs } from 'chess.js';
7
- import React, { useEffect, useState } from 'react';
6
+ import React from 'react';
8
7
 
9
8
  import { generateName } from '@dxos/display-name';
10
- import { invariant } from '@dxos/invariant';
11
9
  import { useMembers, type Space, type SpaceMember } from '@dxos/react-client/echo';
12
10
  import { Input, Select, useThemeContext } from '@dxos/react-ui';
13
11
  import { getSize, mx } from '@dxos/react-ui-theme';
14
12
 
15
- import { Chessboard, type ChessModel, type ChessMove } from './Chessboard';
16
13
  import { type ChessType } from '../types';
17
14
 
18
- const useChessModel = (game: ChessType) => {
19
- const [model, setModel] = useState<ChessModel>();
20
-
21
- useEffect(() => {
22
- if (!model || game.pgn !== model?.chess.pgn()) {
23
- const chess = new ChessJs(game.pgn ? undefined : game.fen);
24
- if (game.pgn) {
25
- chess.loadPgn(game.pgn);
26
- }
27
-
28
- setModel({ chess });
29
- }
30
- }, [game.pgn]);
31
-
32
- const handleUpdate = (move: ChessMove) => {
33
- invariant(model);
34
- if (model.chess.move(move)) {
35
- game.pgn = model.chess.pgn();
36
- game.fen = model.chess.fen();
37
- setModel({ ...model });
38
- }
39
- };
40
-
41
- return { model, handleUpdate };
42
- };
43
-
44
- export const Chess = ({ space, game, playerSelector }: { space: Space; game: ChessType; playerSelector?: boolean }) => {
45
- const { model, handleUpdate } = useChessModel(game);
46
- if (!model) {
47
- return null;
48
- }
49
-
50
- return (
51
- <div role='none' className='grid grid-rows-[60px_1fr_60px] grow overflow-hidden'>
52
- <div />
53
- <div className='flex grow justify-center overflow-hidden'>
54
- <div className='flex grow max-w-[600px] items-center overflow-hidden'>
55
- <Chessboard model={model} onUpdate={handleUpdate} />
56
- </div>
57
- </div>
58
- {playerSelector && <PlayerSelector game={game} space={space} />}
59
- </div>
60
- );
61
- };
62
-
63
- const PlayerSelector = ({ game, space }: { game: ChessType; space: Space }) => {
15
+ export const PlayerSelector = ({ space, game }: { space: Space; game: ChessType }) => {
64
16
  const members = useMembers(space.key);
65
17
 
66
18
  return (
@@ -4,7 +4,6 @@
4
4
 
5
5
  import { lazy } from 'react';
6
6
 
7
- export * from './Chess';
8
- export * from './Chessboard';
7
+ export * from './ChessComponent';
9
8
 
10
9
  export const ChessContainer = lazy(() => import('./ChessContainer'));
@@ -1,26 +0,0 @@
1
- import {
2
- Chess
3
- } from "./chunk-JUAC2NNR.mjs";
4
-
5
- // packages/plugins/plugin-chess/src/components/ChessContainer.tsx
6
- import React from "react";
7
- import { getSpace } from "@dxos/react-client/echo";
8
- import { StackItem } from "@dxos/react-ui-stack";
9
- var ChessContainer = ({ game, role }) => {
10
- const space = getSpace(game);
11
- if (!space) {
12
- return null;
13
- }
14
- return /* @__PURE__ */ React.createElement(StackItem.Content, {
15
- toolbar: false
16
- }, /* @__PURE__ */ React.createElement(Chess, {
17
- game,
18
- space,
19
- playerSelector: role === "article"
20
- }));
21
- };
22
- var ChessContainer_default = ChessContainer;
23
- export {
24
- ChessContainer_default as default
25
- };
26
- //# sourceMappingURL=ChessContainer-G736GS2V.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/ChessContainer.tsx"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { type ComponentProps } from 'react';\n\nimport { getSpace } from '@dxos/react-client/echo';\nimport { StackItem } from '@dxos/react-ui-stack';\n\nimport { Chess } from './Chess';\n\nconst ChessContainer = ({ game, role }: Pick<ComponentProps<typeof Chess>, 'game'> & { role?: string }) => {\n const space = getSpace(game);\n if (!space) {\n return null;\n }\n\n return (\n <StackItem.Content toolbar={false}>\n <Chess game={game} space={space} playerSelector={role === 'article'} />\n </StackItem.Content>\n );\n};\n\nexport default ChessContainer;\n"],
5
- "mappings": ";;;;;AAIA,OAAOA,WAAoC;AAE3C,SAASC,gBAAgB;AACzB,SAASC,iBAAiB;AAI1B,IAAMC,iBAAiB,CAAC,EAAEC,MAAMC,KAAI,MAAkE;AACpG,QAAMC,QAAQC,SAASH,IAAAA;AACvB,MAAI,CAACE,OAAO;AACV,WAAO;EACT;AAEA,SACE,sBAAA,cAACE,UAAUC,SAAO;IAACC,SAAS;KAC1B,sBAAA,cAACC,OAAAA;IAAMP;IAAYE;IAAcM,gBAAgBP,SAAS;;AAGhE;AAEA,IAAA,yBAAeF;",
6
- "names": ["React", "getSpace", "StackItem", "ChessContainer", "game", "role", "space", "getSpace", "StackItem", "Content", "toolbar", "Chess", "playerSelector"]
7
- }