From f6139d20080d5ed0fe345d8276091f51dcef68b7 Mon Sep 17 00:00:00 2001 From: Werner Stein Date: Thu, 19 Nov 2026 10:38:54 +0000 Subject: [PATCH 1/9] refactor(view3d): share the CUBE group and move history of the toolbar The CUBE group (Scramble, Random State, Undo, Reset) and the move history move from the existing presentation into cubeToolbarSections.tsx with unchanged markup, so the PuzlWerk main view can show the same parts. Component tests render them without a DOM. Co-Authored-By: Claude Sonnet 5.5 --- src/client/view3d/cubeToolbarSections.tsx | 105 ++++++++++++++++ src/client/view3d/cubeView3DPresentation.tsx | 86 +++---------- test/cubeToolbarSections.test.ts | 126 +++++++++++++++++++ test/support/vnodeTree.ts | 49 ++++++++ 4 files changed, 298 insertions(+), 68 deletions(-) create mode 100644 src/client/view3d/cubeToolbarSections.tsx create mode 100644 test/cubeToolbarSections.test.ts create mode 100644 test/support/vnodeTree.ts diff --git a/src/client/view3d/cubeToolbarSections.tsx b/src/client/view3d/cubeToolbarSections.tsx new file mode 100644 index 00000000..ad06f054 --- /dev/null +++ b/src/client/view3d/cubeToolbarSections.tsx @@ -0,0 +1,105 @@ +// Parts of the 3D toolbar that the existing view and the PuzlWerk main view show alike: the CUBE group +// (scramble, random state, undo, reset) and the move history. Classes and markup are the toolbar's. +import { CUBELAB_MOVES_ID, cubeLabMovesJson } from '../cubeLabFingerprint' +import { formatCubeTurn, type CubeTurn } from './cubeView3DState' + +// Undo needs a completed move and no turn in progress. +export const undoDisabled = (moves: CubeTurn[], isTurning: boolean): boolean => + moves.length === 0 || isTurning + +// Reset is off only while the cube is the initial one and nothing was turned. +export const resetDisabled = (isInitial: boolean, moves: CubeTurn[]): boolean => + isInitial && moves.length === 0 + +export const moveHistoryText = (moves: CubeTurn[], size: number): string => + moves.length + ? moves.map((move) => formatCubeTurn(move, size)).join(' ') + : 'None' + +export interface CubeActionsSectionProps { + isScrambling: boolean + onToggleScramble: () => void + onRandomState: () => void + onUndo: () => void + onReset: () => void + undoDisabled: boolean + resetDisabled: boolean + // Whether a drag turns a layer; off, scrambling and a random state are unavailable. + allowLayerMoves?: boolean +} + +export function CubeActionsSection({ + isScrambling, + onToggleScramble, + onRandomState, + onUndo, + onReset, + undoDisabled: undoOff, + resetDisabled: resetOff, + allowLayerMoves = true, +}: CubeActionsSectionProps) { + return ( +
+ Cube: +
+ + + + +
+
+ ) +} + +export interface MoveHistoryProps { + moves: CubeTurn[] + size: number +} + +// The move list the user reads, and the block CubeLab reads (escaped JSON, so no "<" ends the element). +export function MoveHistory({ moves, size }: MoveHistoryProps) { + return ( + <> +
+ Moves: {moveHistoryText(moves, size)} +
+