gigaboard 1.5.0 → 1.5.1

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.
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { CSSProperties, RefObject, ReactNode } from 'react';
2
+ import react, { CSSProperties, RefObject, ReactNode } from 'react';
3
3
  import { S as SquareIndex, u as BoardCell, v as BoardModel, x as BoardSnapshot, w as BoardModelOptions, P as PackedMove } from './board-model-BIVxSCWC.cjs';
4
4
  export { D as Color, E as EngineAdapter, W as NULL_MOVE_SAN, X as NULL_MOVE_SANS, Y as NULL_MOVE_UCI, Z as NULL_MOVE_WORD, a as PieceType, a1 as ZobristKey, a2 as createBoardModel, a8 as isNullMove, a9 as isNullMoveSan, aa as isNullMoveUci, ac as packMove, ae as unpackMove } from './board-model-BIVxSCWC.cjs';
5
5
  import { O as Orientation, T as Theme, P as PieceRenderer, C as ChessboardProps, A as AnimationOptions, R as ResolvedArrowPalette, U as UseChessGameOptions } from './types-Dox7oLof.cjs';
@@ -41,14 +41,20 @@ interface BoardEditorProps {
41
41
  focusedSquare?: SquareIndex;
42
42
  /** Square focus callback. */
43
43
  onSquareFocus?: (square: SquareIndex, cell: BoardCell, algebraic: string) => void;
44
+ /** Optional container element id. */
45
+ id?: string;
44
46
  /** Clear board callback. */
45
47
  onClear?: () => void;
46
48
  /** Set starting position callback. */
47
49
  onSetStartingPosition?: () => void;
48
50
  /** Toggle side to move callback. */
49
51
  onToggleSideToMove?: () => void;
52
+ /** Callback when editor receives container focus. */
53
+ onFocus?: (e: react.FocusEvent<HTMLDivElement>) => void;
54
+ /** Callback when editor loses container focus. */
55
+ onBlur?: (e: react.FocusEvent<HTMLDivElement>) => void;
50
56
  }
51
- declare function BoardEditor({ fen, onChange, onPieceChange, selectedPiece, onSelectPiece, orientation, theme, pieces, showCoordinates, style, className, ariaLabel, onAnnounce, getSquareAriaLabel, focusedSquare: propFocusedSquare, onSquareFocus, onClear, onSetStartingPosition, onToggleSideToMove, }: BoardEditorProps): react_jsx_runtime.JSX.Element;
57
+ declare function BoardEditor({ fen, onChange, onPieceChange, selectedPiece, onSelectPiece, orientation, theme, pieces, showCoordinates, style, className, ariaLabel, onAnnounce, getSquareAriaLabel, focusedSquare: propFocusedSquare, onSquareFocus, id, onClear, onSetStartingPosition, onToggleSideToMove, onFocus, onBlur, }: BoardEditorProps): react_jsx_runtime.JSX.Element;
52
58
 
53
59
  /**
54
60
  * Interactive chess board.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { CSSProperties, RefObject, ReactNode } from 'react';
2
+ import react, { CSSProperties, RefObject, ReactNode } from 'react';
3
3
  import { S as SquareIndex, u as BoardCell, v as BoardModel, x as BoardSnapshot, w as BoardModelOptions, P as PackedMove } from './board-model-BIVxSCWC.js';
4
4
  export { D as Color, E as EngineAdapter, W as NULL_MOVE_SAN, X as NULL_MOVE_SANS, Y as NULL_MOVE_UCI, Z as NULL_MOVE_WORD, a as PieceType, a1 as ZobristKey, a2 as createBoardModel, a8 as isNullMove, a9 as isNullMoveSan, aa as isNullMoveUci, ac as packMove, ae as unpackMove } from './board-model-BIVxSCWC.js';
5
5
  import { O as Orientation, T as Theme, P as PieceRenderer, C as ChessboardProps, A as AnimationOptions, R as ResolvedArrowPalette, U as UseChessGameOptions } from './types-4W8ULiE2.js';
@@ -41,14 +41,20 @@ interface BoardEditorProps {
41
41
  focusedSquare?: SquareIndex;
42
42
  /** Square focus callback. */
43
43
  onSquareFocus?: (square: SquareIndex, cell: BoardCell, algebraic: string) => void;
44
+ /** Optional container element id. */
45
+ id?: string;
44
46
  /** Clear board callback. */
45
47
  onClear?: () => void;
46
48
  /** Set starting position callback. */
47
49
  onSetStartingPosition?: () => void;
48
50
  /** Toggle side to move callback. */
49
51
  onToggleSideToMove?: () => void;
52
+ /** Callback when editor receives container focus. */
53
+ onFocus?: (e: react.FocusEvent<HTMLDivElement>) => void;
54
+ /** Callback when editor loses container focus. */
55
+ onBlur?: (e: react.FocusEvent<HTMLDivElement>) => void;
50
56
  }
51
- declare function BoardEditor({ fen, onChange, onPieceChange, selectedPiece, onSelectPiece, orientation, theme, pieces, showCoordinates, style, className, ariaLabel, onAnnounce, getSquareAriaLabel, focusedSquare: propFocusedSquare, onSquareFocus, onClear, onSetStartingPosition, onToggleSideToMove, }: BoardEditorProps): react_jsx_runtime.JSX.Element;
57
+ declare function BoardEditor({ fen, onChange, onPieceChange, selectedPiece, onSelectPiece, orientation, theme, pieces, showCoordinates, style, className, ariaLabel, onAnnounce, getSquareAriaLabel, focusedSquare: propFocusedSquare, onSquareFocus, id, onClear, onSetStartingPosition, onToggleSideToMove, onFocus, onBlur, }: BoardEditorProps): react_jsx_runtime.JSX.Element;
52
58
 
53
59
  /**
54
60
  * Interactive chess board.
package/dist/index.js CHANGED
@@ -346,9 +346,12 @@ function BoardEditor({
346
346
  getSquareAriaLabel,
347
347
  focusedSquare: propFocusedSquare,
348
348
  onSquareFocus,
349
+ id,
349
350
  onClear,
350
351
  onSetStartingPosition,
351
- onToggleSideToMove
352
+ onToggleSideToMove,
353
+ onFocus,
354
+ onBlur
352
355
  }) {
353
356
  const containerRef = useRef(null);
354
357
  const liveRegionRef = useRef(null);
@@ -634,6 +637,7 @@ function BoardEditor({
634
637
  "div",
635
638
  {
636
639
  ref: containerRef,
640
+ id,
637
641
  role: "application",
638
642
  tabIndex: 0,
639
643
  "aria-label": ariaLabel,
@@ -644,8 +648,14 @@ function BoardEditor({
644
648
  setHasKeyboardFocus(true);
645
649
  announceSquare(focusedSquare);
646
650
  }
651
+ onFocus?.(e);
652
+ },
653
+ onBlur: (e) => {
654
+ if (e.target === e.currentTarget) {
655
+ setHasKeyboardFocus(false);
656
+ }
657
+ onBlur?.(e);
647
658
  },
648
- onBlur: () => setHasKeyboardFocus(false),
649
659
  onPointerDown: handlePointerDown,
650
660
  onPointerMove: handlePointerMove,
651
661
  onPointerUp: handlePointerUp,
@@ -727,6 +737,39 @@ function BoardEditor({
727
737
  })
728
738
  }
729
739
  ),
740
+ hasKeyboardFocus && /* @__PURE__ */ jsx(
741
+ "div",
742
+ {
743
+ "aria-hidden": "true",
744
+ style: {
745
+ position: "absolute",
746
+ inset: 0,
747
+ display: "grid",
748
+ gridTemplateColumns: "repeat(8, 1fr)",
749
+ gridTemplateRows: "repeat(8, 1fr)",
750
+ pointerEvents: "none",
751
+ zIndex: 10
752
+ },
753
+ children: (() => {
754
+ const { col, row } = gridCoord(focusedSquare, orientation);
755
+ return /* @__PURE__ */ jsx(
756
+ "div",
757
+ {
758
+ "data-gb-editor-focus-square": algebraicOf2(focusedSquare),
759
+ style: {
760
+ gridColumnStart: col,
761
+ gridRowStart: row,
762
+ outline: "3px solid var(--gb-editor-sq-focus, #f59e0b)",
763
+ outlineOffset: "-3px",
764
+ boxShadow: "inset 0 0 0 1.5px rgba(0, 0, 0, 0.75), 0 0 8px rgba(245, 158, 11, 0.7)",
765
+ borderRadius: "2px",
766
+ pointerEvents: "none"
767
+ }
768
+ }
769
+ );
770
+ })()
771
+ }
772
+ ),
730
773
  dragging && containerRef.current ? /* @__PURE__ */ jsx(
731
774
  "div",
732
775
  {