@dxos/react-ui-gameboard 0.8.4-main.5acf9ea → 0.8.4-main.5ea62a8

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 (65) hide show
  1. package/dist/lib/browser/index.mjs +407 -322
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +407 -322
  5. package/dist/lib/node-esm/index.mjs.map +4 -4
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/components/Chessboard/Chessboard.d.ts.map +1 -0
  8. package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts +22 -0
  9. package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts.map +1 -0
  10. package/dist/types/src/{Chessboard → components/Chessboard}/chess.d.ts +27 -10
  11. package/dist/types/src/components/Chessboard/chess.d.ts.map +1 -0
  12. package/dist/types/src/components/Chessboard/chess.test.d.ts +2 -0
  13. package/dist/types/src/components/Chessboard/chess.test.d.ts.map +1 -0
  14. package/dist/types/src/components/Chessboard/index.d.ts.map +1 -0
  15. package/dist/types/src/components/Gameboard/Gameboard.d.ts +38 -0
  16. package/dist/types/src/components/Gameboard/Gameboard.d.ts.map +1 -0
  17. package/dist/types/src/{Gameboard → components/Gameboard}/Piece.d.ts +3 -2
  18. package/dist/types/src/components/Gameboard/Piece.d.ts.map +1 -0
  19. package/dist/types/src/components/Gameboard/Square.d.ts.map +1 -0
  20. package/dist/types/src/components/Gameboard/index.d.ts +4 -0
  21. package/dist/types/src/components/Gameboard/index.d.ts.map +1 -0
  22. package/dist/types/src/{Gameboard → components/Gameboard}/types.d.ts +2 -0
  23. package/dist/types/src/components/Gameboard/types.d.ts.map +1 -0
  24. package/dist/types/src/components/Gameboard/util.d.ts.map +1 -0
  25. package/dist/types/src/components/index.d.ts +3 -0
  26. package/dist/types/src/components/index.d.ts.map +1 -0
  27. package/dist/types/src/index.d.ts +1 -2
  28. package/dist/types/src/index.d.ts.map +1 -1
  29. package/dist/types/tsconfig.tsbuildinfo +1 -1
  30. package/package.json +16 -15
  31. package/src/{Chessboard → components/Chessboard}/Chessboard.stories.tsx +24 -23
  32. package/src/{Chessboard → components/Chessboard}/Chessboard.tsx +43 -41
  33. package/src/components/Chessboard/chess.test.ts +19 -0
  34. package/src/components/Chessboard/chess.ts +314 -0
  35. package/src/components/Gameboard/Gameboard.tsx +140 -0
  36. package/src/{Gameboard → components/Gameboard}/Piece.tsx +25 -22
  37. package/src/{Gameboard → components/Gameboard}/Square.tsx +4 -4
  38. package/src/{Gameboard → components/Gameboard}/index.ts +0 -3
  39. package/src/{Gameboard → components/Gameboard}/types.ts +3 -0
  40. package/src/components/index.ts +6 -0
  41. package/src/index.ts +1 -2
  42. package/dist/types/src/Chessboard/Chessboard.d.ts.map +0 -1
  43. package/dist/types/src/Chessboard/Chessboard.stories.d.ts +0 -16
  44. package/dist/types/src/Chessboard/Chessboard.stories.d.ts.map +0 -1
  45. package/dist/types/src/Chessboard/chess.d.ts.map +0 -1
  46. package/dist/types/src/Chessboard/index.d.ts.map +0 -1
  47. package/dist/types/src/Gameboard/Gameboard.d.ts +0 -23
  48. package/dist/types/src/Gameboard/Gameboard.d.ts.map +0 -1
  49. package/dist/types/src/Gameboard/Piece.d.ts.map +0 -1
  50. package/dist/types/src/Gameboard/Square.d.ts.map +0 -1
  51. package/dist/types/src/Gameboard/context.d.ts +0 -10
  52. package/dist/types/src/Gameboard/context.d.ts.map +0 -1
  53. package/dist/types/src/Gameboard/index.d.ts +0 -7
  54. package/dist/types/src/Gameboard/index.d.ts.map +0 -1
  55. package/dist/types/src/Gameboard/types.d.ts.map +0 -1
  56. package/dist/types/src/Gameboard/util.d.ts.map +0 -1
  57. package/src/Chessboard/chess.ts +0 -213
  58. package/src/Gameboard/Gameboard.tsx +0 -103
  59. package/src/Gameboard/context.ts +0 -22
  60. /package/dist/types/src/{Chessboard → components/Chessboard}/Chessboard.d.ts +0 -0
  61. /package/dist/types/src/{Chessboard → components/Chessboard}/index.d.ts +0 -0
  62. /package/dist/types/src/{Gameboard → components/Gameboard}/Square.d.ts +0 -0
  63. /package/dist/types/src/{Gameboard → components/Gameboard}/util.d.ts +0 -0
  64. /package/src/{Chessboard → components/Chessboard}/index.ts +0 -0
  65. /package/src/{Gameboard → components/Gameboard}/util.ts +0 -0
@@ -1,103 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
6
- import React, { type CSSProperties, forwardRef, type PropsWithChildren, useCallback, useEffect, useState } from 'react';
7
-
8
- import { log } from '@dxos/log';
9
- import { type ThemedClassName } from '@dxos/react-ui';
10
- import { mx } from '@dxos/react-ui-theme';
11
-
12
- import { GameboardContext, type GameboardContextType } from './context';
13
- import { type GameboardModel, isLocation, isPiece, type Move, type PieceRecord } from './types';
14
-
15
- type GameboardRootProps = PropsWithChildren<{
16
- model?: GameboardModel;
17
- onDrop?: (move: Move) => boolean;
18
- }>;
19
-
20
- /**
21
- * Generic board container.
22
- */
23
- const GameboardRoot = ({ children, model, onDrop }: GameboardRootProps) => {
24
- const [dragging, setDragging] = useState(false);
25
- const [promoting, setPromoting] = useState<PieceRecord | undefined>();
26
-
27
- // Handle promotion.
28
- const onPromotion = useCallback<GameboardContextType['onPromotion']>((move) => {
29
- log('onPromotion', { move });
30
- setPromoting(undefined);
31
- onDrop?.(move);
32
- }, []);
33
-
34
- useEffect(() => {
35
- if (!model) {
36
- return;
37
- }
38
-
39
- // TODO(burdon): Should target specific container.
40
- return monitorForElements({
41
- onDragStart: ({ source }) => {
42
- log('onDragStart', { source });
43
- setDragging(true);
44
- },
45
- onDrop: ({ source, location }) => {
46
- log('onDrop', { source, location });
47
- const target = location.current.dropTargets[0];
48
- if (!target) {
49
- return;
50
- }
51
-
52
- const targetLocation = target.data.location;
53
- const piece = source.data.piece;
54
- if (!isLocation(targetLocation) || !isPiece(piece)) {
55
- return;
56
- }
57
-
58
- const move: Move = { from: piece.location, to: targetLocation, piece: piece.type };
59
- if (model.canPromote?.(move)) {
60
- setPromoting({ ...piece, location: targetLocation });
61
- } else {
62
- onDrop?.(move);
63
- }
64
-
65
- setDragging(false);
66
- },
67
- });
68
- }, [model]);
69
-
70
- return (
71
- <GameboardContext.Provider value={{ model, dragging, promoting, onPromotion }}>
72
- {children}
73
- </GameboardContext.Provider>
74
- );
75
- };
76
-
77
- GameboardRoot.displayName = 'Gameboard.Root';
78
-
79
- type GameboardContentsProps = ThemedClassName<
80
- PropsWithChildren<{
81
- style?: CSSProperties;
82
- }>
83
- >;
84
-
85
- /**
86
- * Container centers the board.
87
- */
88
- const GameboardContent = forwardRef<HTMLDivElement, GameboardContentsProps>(
89
- ({ children, classNames, style }, forwardedRef) => {
90
- return (
91
- <div ref={forwardedRef} style={style} className='flex w-full h-full justify-center overflow-hidden'>
92
- <div className={mx('max-w-full max-h-full content-center aspect-square', classNames)}>{children}</div>
93
- </div>
94
- );
95
- },
96
- );
97
-
98
- export const Gameboard = {
99
- Root: GameboardRoot,
100
- Content: GameboardContent,
101
- };
102
-
103
- export type { GameboardRootProps, GameboardContentsProps };
@@ -1,22 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { createContext, useContext } from 'react';
6
-
7
- import { raise } from '@dxos/debug';
8
-
9
- import { type PieceRecord, type GameboardModel, type Move } from './types';
10
-
11
- export type GameboardContextType = {
12
- model?: GameboardModel;
13
- dragging?: boolean; // TODO(burdon): Change to PieceRecord.
14
- promoting?: PieceRecord;
15
- onPromotion: (move: Move) => void;
16
- };
17
-
18
- export const GameboardContext = createContext<GameboardContextType | undefined>(undefined);
19
-
20
- export const useBoardContext = () => {
21
- return useContext(GameboardContext) ?? raise(new Error('Missing BoardContext'));
22
- };
File without changes