@dreamboard-games/ui-sdk 0.0.41
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/LICENSE +89 -0
- package/NOTICE +1 -0
- package/README.md +154 -0
- package/dist/components/ActionButton.d.ts +13 -0
- package/dist/components/ActionButton.d.ts.map +1 -0
- package/dist/components/ActionButton.js +14 -0
- package/dist/components/ActionPanel.d.ts +33 -0
- package/dist/components/ActionPanel.d.ts.map +1 -0
- package/dist/components/ActionPanel.js +148 -0
- package/dist/components/Card.d.ts +29 -0
- package/dist/components/Card.d.ts.map +1 -0
- package/dist/components/Card.js +220 -0
- package/dist/components/ChromeSuppressionContext.d.ts +7 -0
- package/dist/components/ChromeSuppressionContext.d.ts.map +1 -0
- package/dist/components/ChromeSuppressionContext.js +34 -0
- package/dist/components/CostDisplay.d.ts +22 -0
- package/dist/components/CostDisplay.d.ts.map +1 -0
- package/dist/components/CostDisplay.js +41 -0
- package/dist/components/DiceRoller.d.ts +30 -0
- package/dist/components/DiceRoller.d.ts.map +1 -0
- package/dist/components/DiceRoller.js +319 -0
- package/dist/components/Drawer.d.ts +19 -0
- package/dist/components/Drawer.d.ts.map +1 -0
- package/dist/components/Drawer.js +55 -0
- package/dist/components/ErrorBoundary.d.ts +24 -0
- package/dist/components/ErrorBoundary.d.ts.map +1 -0
- package/dist/components/ErrorBoundary.js +37 -0
- package/dist/components/GameEndDisplay.d.ts +27 -0
- package/dist/components/GameEndDisplay.d.ts.map +1 -0
- package/dist/components/GameEndDisplay.js +185 -0
- package/dist/components/GameSkeleton.d.ts +12 -0
- package/dist/components/GameSkeleton.d.ts.map +1 -0
- package/dist/components/GameSkeleton.js +54 -0
- package/dist/components/Hand.d.ts +99 -0
- package/dist/components/Hand.d.ts.map +1 -0
- package/dist/components/Hand.js +162 -0
- package/dist/components/HandDock.d.ts +35 -0
- package/dist/components/HandDock.d.ts.map +1 -0
- package/dist/components/HandDock.js +124 -0
- package/dist/components/InteractionForm.d.ts +50 -0
- package/dist/components/InteractionForm.d.ts.map +1 -0
- package/dist/components/InteractionForm.js +402 -0
- package/dist/components/MoreActions.d.ts +49 -0
- package/dist/components/MoreActions.d.ts.map +1 -0
- package/dist/components/MoreActions.js +64 -0
- package/dist/components/PhaseIndicator.d.ts +35 -0
- package/dist/components/PhaseIndicator.d.ts.map +1 -0
- package/dist/components/PhaseIndicator.js +212 -0
- package/dist/components/PlayArea.d.ts +28 -0
- package/dist/components/PlayArea.d.ts.map +1 -0
- package/dist/components/PlayArea.js +48 -0
- package/dist/components/PluginRuntime.d.ts +37 -0
- package/dist/components/PluginRuntime.d.ts.map +1 -0
- package/dist/components/PluginRuntime.js +47 -0
- package/dist/components/PrimaryActionButton.d.ts +98 -0
- package/dist/components/PrimaryActionButton.d.ts.map +1 -0
- package/dist/components/PrimaryActionButton.js +183 -0
- package/dist/components/PrimaryButton.d.ts +20 -0
- package/dist/components/PrimaryButton.d.ts.map +1 -0
- package/dist/components/PrimaryButton.js +5 -0
- package/dist/components/PromptDialogHost.d.ts +15 -0
- package/dist/components/PromptDialogHost.d.ts.map +1 -0
- package/dist/components/PromptDialogHost.js +22 -0
- package/dist/components/ResourceCounter.d.ts +38 -0
- package/dist/components/ResourceCounter.d.ts.map +1 -0
- package/dist/components/ResourceCounter.js +118 -0
- package/dist/components/ThemedButton.d.ts +12 -0
- package/dist/components/ThemedButton.d.ts.map +1 -0
- package/dist/components/ThemedButton.js +38 -0
- package/dist/components/Toast.d.ts +35 -0
- package/dist/components/Toast.d.ts.map +1 -0
- package/dist/components/Toast.js +116 -0
- package/dist/components/board/HexGrid.d.ts +344 -0
- package/dist/components/board/HexGrid.d.ts.map +1 -0
- package/dist/components/board/HexGrid.js +340 -0
- package/dist/components/board/NetworkGraph.d.ts +100 -0
- package/dist/components/board/NetworkGraph.d.ts.map +1 -0
- package/dist/components/board/NetworkGraph.js +123 -0
- package/dist/components/board/SlotSystem.d.ts +71 -0
- package/dist/components/board/SlotSystem.d.ts.map +1 -0
- package/dist/components/board/SlotSystem.js +87 -0
- package/dist/components/board/SquareGrid.d.ts +188 -0
- package/dist/components/board/SquareGrid.d.ts.map +1 -0
- package/dist/components/board/SquareGrid.js +328 -0
- package/dist/components/board/TrackBoard.d.ts +113 -0
- package/dist/components/board/TrackBoard.d.ts.map +1 -0
- package/dist/components/board/TrackBoard.js +135 -0
- package/dist/components/board/ZoneMap.d.ts +88 -0
- package/dist/components/board/ZoneMap.d.ts.map +1 -0
- package/dist/components/board/ZoneMap.js +133 -0
- package/dist/components/board/hex-board-view.d.ts +69 -0
- package/dist/components/board/hex-board-view.d.ts.map +1 -0
- package/dist/components/board/hex-board-view.js +60 -0
- package/dist/components/board/index.d.ts +23 -0
- package/dist/components/board/index.d.ts.map +1 -0
- package/dist/components/board/index.js +40 -0
- package/dist/components/board/interaction-accessibility.d.ts +5 -0
- package/dist/components/board/interaction-accessibility.d.ts.map +1 -0
- package/dist/components/board/interaction-accessibility.js +13 -0
- package/dist/components/board/target-layer.d.ts +13 -0
- package/dist/components/board/target-layer.d.ts.map +1 -0
- package/dist/components/board/target-layer.js +10 -0
- package/dist/components/card-render-content.type-test.d.ts +2 -0
- package/dist/components/card-render-content.type-test.d.ts.map +1 -0
- package/dist/components/card-render-content.type-test.js +1 -0
- package/dist/components/index.d.ts +34 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +35 -0
- package/dist/components/interaction-dialog-behavior.d.ts +15 -0
- package/dist/components/interaction-dialog-behavior.d.ts.map +1 -0
- package/dist/components/interaction-dialog-behavior.js +9 -0
- package/dist/components/surfaces/BlockerSurface.d.ts +27 -0
- package/dist/components/surfaces/BlockerSurface.d.ts.map +1 -0
- package/dist/components/surfaces/BlockerSurface.js +38 -0
- package/dist/components/surfaces/BoardSurface.d.ts +77 -0
- package/dist/components/surfaces/BoardSurface.d.ts.map +1 -0
- package/dist/components/surfaces/BoardSurface.js +180 -0
- package/dist/components/surfaces/ChromeSurface.d.ts +29 -0
- package/dist/components/surfaces/ChromeSurface.d.ts.map +1 -0
- package/dist/components/surfaces/ChromeSurface.js +34 -0
- package/dist/components/surfaces/ExhaustivenessAudit.d.ts +32 -0
- package/dist/components/surfaces/ExhaustivenessAudit.d.ts.map +1 -0
- package/dist/components/surfaces/ExhaustivenessAudit.js +65 -0
- package/dist/components/surfaces/InboxSurface.d.ts +40 -0
- package/dist/components/surfaces/InboxSurface.d.ts.map +1 -0
- package/dist/components/surfaces/InboxSurface.js +99 -0
- package/dist/components/surfaces/MarketSurface.d.ts +62 -0
- package/dist/components/surfaces/MarketSurface.d.ts.map +1 -0
- package/dist/components/surfaces/MarketSurface.js +242 -0
- package/dist/components/surfaces/PanelSurface.d.ts +111 -0
- package/dist/components/surfaces/PanelSurface.d.ts.map +1 -0
- package/dist/components/surfaces/PanelSurface.js +180 -0
- package/dist/components/surfaces/PlayerCardsSurface.d.ts +104 -0
- package/dist/components/surfaces/PlayerCardsSurface.d.ts.map +1 -0
- package/dist/components/surfaces/PlayerCardsSurface.js +178 -0
- package/dist/components/surfaces/internal/CardZoneFollowUpForm.d.ts +7 -0
- package/dist/components/surfaces/internal/CardZoneFollowUpForm.d.ts.map +1 -0
- package/dist/components/surfaces/internal/CardZoneFollowUpForm.js +9 -0
- package/dist/components/surfaces/internal/DefaultInteractionButton.d.ts +71 -0
- package/dist/components/surfaces/internal/DefaultInteractionButton.d.ts.map +1 -0
- package/dist/components/surfaces/internal/DefaultInteractionButton.js +82 -0
- package/dist/components/surfaces/internal/useCardZoneInteractions.d.ts +21 -0
- package/dist/components/surfaces/internal/useCardZoneInteractions.d.ts.map +1 -0
- package/dist/components/surfaces/internal/useCardZoneInteractions.js +202 -0
- package/dist/components/surfaces/types.d.ts +59 -0
- package/dist/components/surfaces/types.d.ts.map +1 -0
- package/dist/components/surfaces/types.js +1 -0
- package/dist/context/ClientParamSchemaContext.d.ts +21 -0
- package/dist/context/ClientParamSchemaContext.d.ts.map +1 -0
- package/dist/context/ClientParamSchemaContext.js +12 -0
- package/dist/context/InteractionDraftContext.d.ts +69 -0
- package/dist/context/InteractionDraftContext.d.ts.map +1 -0
- package/dist/context/InteractionDraftContext.js +145 -0
- package/dist/context/PluginSessionContext.d.ts +33 -0
- package/dist/context/PluginSessionContext.d.ts.map +1 -0
- package/dist/context/PluginSessionContext.js +38 -0
- package/dist/context/PluginStateContext.d.ts +116 -0
- package/dist/context/PluginStateContext.d.ts.map +1 -0
- package/dist/context/PluginStateContext.js +186 -0
- package/dist/context/RuntimeContext.d.ts +49 -0
- package/dist/context/RuntimeContext.d.ts.map +1 -0
- package/dist/context/RuntimeContext.js +67 -0
- package/dist/defaults/components.d.ts +52 -0
- package/dist/defaults/components.d.ts.map +1 -0
- package/dist/defaults/components.js +159 -0
- package/dist/defaults/index.d.ts +2 -0
- package/dist/defaults/index.d.ts.map +1 -0
- package/dist/defaults/index.js +1 -0
- package/dist/errors/ValidationError.d.ts +10 -0
- package/dist/errors/ValidationError.d.ts.map +1 -0
- package/dist/errors/ValidationError.js +23 -0
- package/dist/helpers/cards.d.ts +3 -0
- package/dist/helpers/cards.d.ts.map +1 -0
- package/dist/helpers/cards.js +11 -0
- package/dist/helpers/track-board.d.ts +79 -0
- package/dist/helpers/track-board.d.ts.map +1 -0
- package/dist/helpers/track-board.js +56 -0
- package/dist/hooks/useActivePlayers.d.ts +16 -0
- package/dist/hooks/useActivePlayers.d.ts.map +1 -0
- package/dist/hooks/useActivePlayers.js +17 -0
- package/dist/hooks/useBoardInteractions.d.ts +110 -0
- package/dist/hooks/useBoardInteractions.d.ts.map +1 -0
- package/dist/hooks/useBoardInteractions.js +248 -0
- package/dist/hooks/useBoardTopology.d.ts +23 -0
- package/dist/hooks/useBoardTopology.d.ts.map +1 -0
- package/dist/hooks/useBoardTopology.js +128 -0
- package/dist/hooks/useCards.d.ts +3 -0
- package/dist/hooks/useCards.d.ts.map +1 -0
- package/dist/hooks/useCards.js +5 -0
- package/dist/hooks/useGameSelector.d.ts +13 -0
- package/dist/hooks/useGameSelector.d.ts.map +1 -0
- package/dist/hooks/useGameSelector.js +67 -0
- package/dist/hooks/useGameView.d.ts +6 -0
- package/dist/hooks/useGameView.d.ts.map +1 -0
- package/dist/hooks/useGameView.js +7 -0
- package/dist/hooks/useHandLayout.d.ts +120 -0
- package/dist/hooks/useHandLayout.d.ts.map +1 -0
- package/dist/hooks/useHandLayout.js +235 -0
- package/dist/hooks/useHexBoard.d.ts +19 -0
- package/dist/hooks/useHexBoard.d.ts.map +1 -0
- package/dist/hooks/useHexBoard.js +28 -0
- package/dist/hooks/useHexGrid.d.ts +56 -0
- package/dist/hooks/useHexGrid.d.ts.map +1 -0
- package/dist/hooks/useHexGrid.js +112 -0
- package/dist/hooks/useInteractionByKey.d.ts +29 -0
- package/dist/hooks/useInteractionByKey.d.ts.map +1 -0
- package/dist/hooks/useInteractionByKey.js +263 -0
- package/dist/hooks/useInteractionHandle.d.ts +103 -0
- package/dist/hooks/useInteractionHandle.d.ts.map +1 -0
- package/dist/hooks/useInteractionHandle.js +254 -0
- package/dist/hooks/useIsMobile.d.ts +7 -0
- package/dist/hooks/useIsMobile.d.ts.map +1 -0
- package/dist/hooks/useIsMobile.js +29 -0
- package/dist/hooks/useIsMyTurn.d.ts +6 -0
- package/dist/hooks/useIsMyTurn.d.ts.map +1 -0
- package/dist/hooks/useIsMyTurn.js +11 -0
- package/dist/hooks/useLobby.d.ts +28 -0
- package/dist/hooks/useLobby.d.ts.map +1 -0
- package/dist/hooks/useLobby.js +60 -0
- package/dist/hooks/useMe.d.ts +11 -0
- package/dist/hooks/useMe.d.ts.map +1 -0
- package/dist/hooks/useMe.js +32 -0
- package/dist/hooks/usePanZoom.d.ts +113 -0
- package/dist/hooks/usePanZoom.d.ts.map +1 -0
- package/dist/hooks/usePanZoom.js +165 -0
- package/dist/hooks/usePlayerInfo.d.ts +4 -0
- package/dist/hooks/usePlayerInfo.d.ts.map +1 -0
- package/dist/hooks/usePlayerInfo.js +21 -0
- package/dist/hooks/usePlayerTurnOrder.d.ts +15 -0
- package/dist/hooks/usePlayerTurnOrder.d.ts.map +1 -0
- package/dist/hooks/usePlayerTurnOrder.js +22 -0
- package/dist/hooks/usePluginRuntime.d.ts +45 -0
- package/dist/hooks/usePluginRuntime.d.ts.map +1 -0
- package/dist/hooks/usePluginRuntime.js +92 -0
- package/dist/hooks/useSeatInbox.d.ts +22 -0
- package/dist/hooks/useSeatInbox.d.ts.map +1 -0
- package/dist/hooks/useSeatInbox.js +43 -0
- package/dist/hooks/useSimultaneousPhase.d.ts +7 -0
- package/dist/hooks/useSimultaneousPhase.d.ts.map +1 -0
- package/dist/hooks/useSimultaneousPhase.js +8 -0
- package/dist/hooks/useSquareBoard.d.ts +21 -0
- package/dist/hooks/useSquareBoard.d.ts.map +1 -0
- package/dist/hooks/useSquareBoard.js +67 -0
- package/dist/hooks/useSquareGrid.d.ts +96 -0
- package/dist/hooks/useSquareGrid.d.ts.map +1 -0
- package/dist/hooks/useSquareGrid.js +152 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/internal/ui/alert.d.ts +8 -0
- package/dist/internal/ui/alert.d.ts.map +1 -0
- package/dist/internal/ui/alert.js +11 -0
- package/dist/internal/ui/button.d.ts +10 -0
- package/dist/internal/ui/button.d.ts.map +1 -0
- package/dist/internal/ui/button.js +21 -0
- package/dist/internal/ui/dialog.d.ts +16 -0
- package/dist/internal/ui/dialog.d.ts.map +1 -0
- package/dist/internal/ui/dialog.js +35 -0
- package/dist/internal/ui/input.d.ts +3 -0
- package/dist/internal/ui/input.d.ts.map +1 -0
- package/dist/internal/ui/input.js +5 -0
- package/dist/internal/ui/label.d.ts +4 -0
- package/dist/internal/ui/label.d.ts.map +1 -0
- package/dist/internal/ui/label.js +7 -0
- package/dist/internal/ui/select.d.ts +9 -0
- package/dist/internal/ui/select.d.ts.map +1 -0
- package/dist/internal/ui/select.js +23 -0
- package/dist/internal/ui/tooltip.d.ts +7 -0
- package/dist/internal/ui/tooltip.d.ts.map +1 -0
- package/dist/internal/ui/tooltip.js +16 -0
- package/dist/internal/ui/utils.d.ts +3 -0
- package/dist/internal/ui/utils.d.ts.map +1 -0
- package/dist/internal/ui/utils.js +4 -0
- package/dist/internal.d.ts +7 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +4 -0
- package/dist/plugin-styles.css +246 -0
- package/dist/primitives/board.d.ts +29 -0
- package/dist/primitives/board.d.ts.map +1 -0
- package/dist/primitives/board.js +163 -0
- package/dist/primitives/game-ui-provider.d.ts +12 -0
- package/dist/primitives/game-ui-provider.d.ts.map +1 -0
- package/dist/primitives/game-ui-provider.js +7 -0
- package/dist/primitives/index.d.ts +8 -0
- package/dist/primitives/index.d.ts.map +1 -0
- package/dist/primitives/index.js +7 -0
- package/dist/primitives/interaction.d.ts +52 -0
- package/dist/primitives/interaction.d.ts.map +1 -0
- package/dist/primitives/interaction.js +250 -0
- package/dist/primitives/phase.d.ts +15 -0
- package/dist/primitives/phase.d.ts.map +1 -0
- package/dist/primitives/phase.js +18 -0
- package/dist/primitives/player-roster.d.ts +64 -0
- package/dist/primitives/player-roster.d.ts.map +1 -0
- package/dist/primitives/player-roster.js +149 -0
- package/dist/primitives/primitive-props.d.ts +15 -0
- package/dist/primitives/primitive-props.d.ts.map +1 -0
- package/dist/primitives/primitive-props.js +39 -0
- package/dist/primitives/prompt.d.ts +44 -0
- package/dist/primitives/prompt.d.ts.map +1 -0
- package/dist/primitives/prompt.js +101 -0
- package/dist/primitives/zone.d.ts +31 -0
- package/dist/primitives/zone.d.ts.map +1 -0
- package/dist/primitives/zone.js +58 -0
- package/dist/reducer.d.ts +21 -0
- package/dist/reducer.d.ts.map +1 -0
- package/dist/reducer.js +14 -0
- package/dist/runtime/createPluginRuntimeAPI.d.ts +67 -0
- package/dist/runtime/createPluginRuntimeAPI.d.ts.map +1 -0
- package/dist/runtime/createPluginRuntimeAPI.js +419 -0
- package/dist/theme/ThemeProvider.d.ts +98 -0
- package/dist/theme/ThemeProvider.d.ts.map +1 -0
- package/dist/theme/ThemeProvider.js +148 -0
- package/dist/theme/board.d.ts +42 -0
- package/dist/theme/board.d.ts.map +1 -0
- package/dist/theme/board.js +34 -0
- package/dist/theme/css-vars.d.ts +31 -0
- package/dist/theme/css-vars.d.ts.map +1 -0
- package/dist/theme/css-vars.js +88 -0
- package/dist/theme/derive.d.ts +66 -0
- package/dist/theme/derive.d.ts.map +1 -0
- package/dist/theme/derive.js +161 -0
- package/dist/theme/index.d.ts +22 -0
- package/dist/theme/index.d.ts.map +1 -0
- package/dist/theme/index.js +20 -0
- package/dist/theme/presets/arcade.d.ts +10 -0
- package/dist/theme/presets/arcade.d.ts.map +1 -0
- package/dist/theme/presets/arcade.js +257 -0
- package/dist/theme/presets/studio.d.ts +10 -0
- package/dist/theme/presets/studio.d.ts.map +1 -0
- package/dist/theme/presets/studio.js +257 -0
- package/dist/theme/presets/tabletop.d.ts +15 -0
- package/dist/theme/presets/tabletop.d.ts.map +1 -0
- package/dist/theme/presets/tabletop.js +262 -0
- package/dist/theme/tokens.d.ts +345 -0
- package/dist/theme/tokens.d.ts.map +1 -0
- package/dist/theme/tokens.js +57 -0
- package/dist/types/player-state.d.ts +337 -0
- package/dist/types/player-state.d.ts.map +1 -0
- package/dist/types/player-state.js +1 -0
- package/dist/types/plugin-state.d.ts +324 -0
- package/dist/types/plugin-state.d.ts.map +1 -0
- package/dist/types/plugin-state.js +1 -0
- package/dist/types/reducer-state.d.ts +10 -0
- package/dist/types/reducer-state.d.ts.map +1 -0
- package/dist/types/reducer-state.js +1 -0
- package/dist/types/runtime-api.d.ts +99 -0
- package/dist/types/runtime-api.d.ts.map +1 -0
- package/dist/types/runtime-api.js +1 -0
- package/dist/types/tiled-board.d.ts +187 -0
- package/dist/types/tiled-board.d.ts.map +1 -0
- package/dist/types/tiled-board.js +226 -0
- package/dist/ui-contract.d.ts +78 -0
- package/dist/ui-contract.d.ts.map +1 -0
- package/dist/ui-contract.js +15 -0
- package/dist/ui-sdk.d.ts +3409 -0
- package/dist/utils/interaction-inputs.d.ts +22 -0
- package/dist/utils/interaction-inputs.d.ts.map +1 -0
- package/dist/utils/interaction-inputs.js +219 -0
- package/dist/utils/interaction-labels.d.ts +4 -0
- package/dist/utils/interaction-labels.d.ts.map +1 -0
- package/dist/utils/interaction-labels.js +18 -0
- package/dist/utils/interaction-status.d.ts +15 -0
- package/dist/utils/interaction-status.d.ts.map +1 -0
- package/dist/utils/interaction-status.js +31 -0
- package/package.json +101 -0
- package/src/components/ActionButton.tsx +48 -0
- package/src/components/ActionPanel.tsx +310 -0
- package/src/components/Card.tsx +385 -0
- package/src/components/ChromeSuppressionContext.tsx +70 -0
- package/src/components/CostDisplay.test.tsx +23 -0
- package/src/components/CostDisplay.tsx +145 -0
- package/src/components/DiceRoller.tsx +601 -0
- package/src/components/Drawer.tsx +179 -0
- package/src/components/ErrorBoundary.tsx +119 -0
- package/src/components/GameEndDisplay.test.tsx +19 -0
- package/src/components/GameEndDisplay.tsx +398 -0
- package/src/components/GameSkeleton.tsx +260 -0
- package/src/components/Hand.tsx +387 -0
- package/src/components/HandDock.tsx +257 -0
- package/src/components/InteractionForm.test.tsx +303 -0
- package/src/components/InteractionForm.tsx +1029 -0
- package/src/components/MoreActions.test.tsx +93 -0
- package/src/components/MoreActions.tsx +143 -0
- package/src/components/PhaseIndicator.tsx +341 -0
- package/src/components/PlayArea.tsx +125 -0
- package/src/components/PluginRuntime.tsx +92 -0
- package/src/components/PrimaryActionButton.test.tsx +138 -0
- package/src/components/PrimaryActionButton.tsx +351 -0
- package/src/components/PrimaryButton.tsx +44 -0
- package/src/components/PromptDialogHost.tsx +92 -0
- package/src/components/ResourceCounter.test.tsx +29 -0
- package/src/components/ResourceCounter.tsx +275 -0
- package/src/components/ThemedButton.tsx +78 -0
- package/src/components/Toast.tsx +251 -0
- package/src/components/__fixtures__/ActionButton.fixture.tsx +234 -0
- package/src/components/__fixtures__/ActionPanel.fixture.tsx +298 -0
- package/src/components/__fixtures__/Card.fixture.tsx +185 -0
- package/src/components/__fixtures__/CostDisplay.fixture.tsx +156 -0
- package/src/components/__fixtures__/DiceRoller.fixture.tsx +435 -0
- package/src/components/__fixtures__/Drawer.fixture.tsx +113 -0
- package/src/components/__fixtures__/ErrorBoundary.fixture.tsx +82 -0
- package/src/components/__fixtures__/GameEndDisplay.fixture.tsx +188 -0
- package/src/components/__fixtures__/GameSkeleton.fixture.tsx +46 -0
- package/src/components/__fixtures__/Hand.fixture.tsx +522 -0
- package/src/components/__fixtures__/HexGrid.fixture.tsx +1181 -0
- package/src/components/__fixtures__/NetworkGraph.fixture.tsx +599 -0
- package/src/components/__fixtures__/PhaseIndicator.fixture.tsx +181 -0
- package/src/components/__fixtures__/PlayArea.fixture.tsx +221 -0
- package/src/components/__fixtures__/ResourceCounter.fixture.tsx +227 -0
- package/src/components/__fixtures__/SlotSystem.fixture.tsx +824 -0
- package/src/components/__fixtures__/SquareGrid.fixture.tsx +764 -0
- package/src/components/__fixtures__/Toast.fixture.tsx +97 -0
- package/src/components/__fixtures__/TrackBoard.fixture.tsx +685 -0
- package/src/components/__fixtures__/ZoneMap.fixture.tsx +754 -0
- package/src/components/board/HexGrid.tsx +1294 -0
- package/src/components/board/NetworkGraph.tsx +476 -0
- package/src/components/board/SlotSystem.tsx +339 -0
- package/src/components/board/SquareGrid.tsx +1165 -0
- package/src/components/board/TrackBoard.tsx +496 -0
- package/src/components/board/ZoneMap.tsx +448 -0
- package/src/components/board/hex-board-view.test.tsx +114 -0
- package/src/components/board/hex-board-view.ts +123 -0
- package/src/components/board/index.ts +142 -0
- package/src/components/board/interaction-accessibility.ts +21 -0
- package/src/components/board/target-layer-grids.test.tsx +420 -0
- package/src/components/board/target-layer.ts +30 -0
- package/src/components/card-render-content.type-test.ts +27 -0
- package/src/components/index.ts +208 -0
- package/src/components/interaction-dialog-behavior.test.ts +23 -0
- package/src/components/interaction-dialog-behavior.ts +22 -0
- package/src/components/surfaces/BlockerSurface.test.tsx +158 -0
- package/src/components/surfaces/BlockerSurface.tsx +127 -0
- package/src/components/surfaces/BoardSurface.tsx +340 -0
- package/src/components/surfaces/ChromeSurface.tsx +123 -0
- package/src/components/surfaces/ExhaustivenessAudit.tsx +91 -0
- package/src/components/surfaces/InboxSurface.test.tsx +149 -0
- package/src/components/surfaces/InboxSurface.tsx +245 -0
- package/src/components/surfaces/MarketSurface.tsx +544 -0
- package/src/components/surfaces/PanelSurface.test.tsx +496 -0
- package/src/components/surfaces/PanelSurface.tsx +458 -0
- package/src/components/surfaces/PlayerCardsSurface.tsx +525 -0
- package/src/components/surfaces/internal/CardZoneFollowUpForm.tsx +35 -0
- package/src/components/surfaces/internal/DefaultInteractionButton.tsx +219 -0
- package/src/components/surfaces/internal/useCardZoneInteractions.ts +311 -0
- package/src/components/surfaces/types.ts +100 -0
- package/src/context/ClientParamSchemaContext.tsx +44 -0
- package/src/context/InteractionDraftContext.tsx +204 -0
- package/src/context/PluginSessionContext.tsx +47 -0
- package/src/context/PluginStateContext.tsx +254 -0
- package/src/context/RuntimeContext.tsx +96 -0
- package/src/defaults/components.tsx +442 -0
- package/src/defaults/defaults.test.tsx +230 -0
- package/src/defaults/index.ts +1 -0
- package/src/errors/ValidationError.ts +29 -0
- package/src/helpers/cards.ts +19 -0
- package/src/helpers/track-board.ts +211 -0
- package/src/hooks/useActivePlayers.ts +19 -0
- package/src/hooks/useBoardInteractions.test.tsx +622 -0
- package/src/hooks/useBoardInteractions.ts +434 -0
- package/src/hooks/useBoardTopology.ts +316 -0
- package/src/hooks/useCards.test.tsx +129 -0
- package/src/hooks/useCards.ts +10 -0
- package/src/hooks/useGameSelector.ts +105 -0
- package/src/hooks/useGameView.ts +9 -0
- package/src/hooks/useHandLayout.ts +349 -0
- package/src/hooks/useHexBoard.ts +74 -0
- package/src/hooks/useHexGrid.ts +185 -0
- package/src/hooks/useInteractionByKey.ts +349 -0
- package/src/hooks/useInteractionHandle.ts +437 -0
- package/src/hooks/useIsMobile.ts +35 -0
- package/src/hooks/useIsMyTurn.test.tsx +99 -0
- package/src/hooks/useIsMyTurn.ts +15 -0
- package/src/hooks/useLobby.ts +76 -0
- package/src/hooks/useMe.ts +48 -0
- package/src/hooks/usePanZoom.ts +278 -0
- package/src/hooks/usePlayerInfo.ts +28 -0
- package/src/hooks/usePlayerTurnOrder.ts +23 -0
- package/src/hooks/usePluginRuntime.test.tsx +102 -0
- package/src/hooks/usePluginRuntime.ts +130 -0
- package/src/hooks/useSeatInbox.ts +61 -0
- package/src/hooks/useSimultaneousPhase.ts +10 -0
- package/src/hooks/useSquareBoard.ts +124 -0
- package/src/hooks/useSquareGrid.ts +328 -0
- package/src/index.test.ts +474 -0
- package/src/index.ts +148 -0
- package/src/internal/ui/alert.tsx +51 -0
- package/src/internal/ui/button.tsx +58 -0
- package/src/internal/ui/dialog.tsx +134 -0
- package/src/internal/ui/input.tsx +21 -0
- package/src/internal/ui/label.tsx +21 -0
- package/src/internal/ui/select.tsx +129 -0
- package/src/internal/ui/tooltip.tsx +54 -0
- package/src/internal/ui/utils.ts +5 -0
- package/src/internal.ts +18 -0
- package/src/plugin-styles.css +246 -0
- package/src/primitives/board.test.tsx +139 -0
- package/src/primitives/board.tsx +267 -0
- package/src/primitives/game-ui-provider.tsx +35 -0
- package/src/primitives/index.ts +83 -0
- package/src/primitives/interaction.test.tsx +420 -0
- package/src/primitives/interaction.tsx +405 -0
- package/src/primitives/phase.test.tsx +82 -0
- package/src/primitives/phase.tsx +43 -0
- package/src/primitives/player-roster.test.tsx +168 -0
- package/src/primitives/player-roster.tsx +301 -0
- package/src/primitives/primitive-props.tsx +82 -0
- package/src/primitives/prompt.test.tsx +159 -0
- package/src/primitives/prompt.tsx +203 -0
- package/src/primitives/zone.tsx +113 -0
- package/src/reducer.ts +42 -0
- package/src/runtime/createPluginRuntimeAPI.ts +605 -0
- package/src/theme/ThemeProvider.test.tsx +36 -0
- package/src/theme/ThemeProvider.tsx +252 -0
- package/src/theme/board.ts +61 -0
- package/src/theme/css-vars.ts +105 -0
- package/src/theme/derive.ts +240 -0
- package/src/theme/index.ts +61 -0
- package/src/theme/presets/arcade.ts +261 -0
- package/src/theme/presets/studio.ts +261 -0
- package/src/theme/presets/tabletop.ts +266 -0
- package/src/theme/theme.test.ts +258 -0
- package/src/theme/tokens.ts +392 -0
- package/src/types/player-state.ts +445 -0
- package/src/types/plugin-state.ts +407 -0
- package/src/types/reducer-state.ts +24 -0
- package/src/types/runtime-api.ts +114 -0
- package/src/types/tiled-board.ts +785 -0
- package/src/ui-contract.ts +168 -0
- package/src/utils/interaction-inputs.test.ts +109 -0
- package/src/utils/interaction-inputs.ts +331 -0
- package/src/utils/interaction-labels.ts +23 -0
- package/src/utils/interaction-status.ts +59 -0
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
useContext,
|
|
4
|
+
useMemo,
|
|
5
|
+
type ButtonHTMLAttributes,
|
|
6
|
+
type HTMLAttributes,
|
|
7
|
+
type InputHTMLAttributes,
|
|
8
|
+
type ReactNode,
|
|
9
|
+
} from "react";
|
|
10
|
+
import { useInteractionHandle } from "../hooks/useInteractionHandle.js";
|
|
11
|
+
import { useInteractionUiStore } from "../context/InteractionDraftContext.js";
|
|
12
|
+
import { usePluginState } from "../context/PluginStateContext.js";
|
|
13
|
+
import type { InteractionInputKey, InteractionKey } from "../ui-contract.js";
|
|
14
|
+
import type { InteractionDescriptor } from "../types/plugin-state.js";
|
|
15
|
+
import {
|
|
16
|
+
inputByKey,
|
|
17
|
+
isManyTargetSelectable,
|
|
18
|
+
toggleManyValue,
|
|
19
|
+
} from "../utils/interaction-inputs.js";
|
|
20
|
+
import { interactionLabel } from "../utils/interaction-labels.js";
|
|
21
|
+
import {
|
|
22
|
+
composeEventHandlers,
|
|
23
|
+
renderPrimitive,
|
|
24
|
+
type PrimitiveCommonProps,
|
|
25
|
+
} from "./primitive-props.js";
|
|
26
|
+
import { useZoneCardContext } from "./zone.js";
|
|
27
|
+
|
|
28
|
+
interface InteractionContextValue {
|
|
29
|
+
interaction: string;
|
|
30
|
+
descriptor: InteractionDescriptor | null;
|
|
31
|
+
handle: ReturnType<typeof useInteractionHandle> | null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const InteractionContext = createContext<InteractionContextValue | null>(null);
|
|
35
|
+
|
|
36
|
+
function humanizeInteraction(value: string): string {
|
|
37
|
+
const parts = value.split(".");
|
|
38
|
+
const leaf = parts[parts.length - 1] ?? value;
|
|
39
|
+
return leaf
|
|
40
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
|
41
|
+
.replace(/[-_]+/g, " ")
|
|
42
|
+
.replace(/\s+/g, " ")
|
|
43
|
+
.trim()
|
|
44
|
+
.replace(/^./, (first: string) => first.toUpperCase());
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function useInteractionPrimitiveContext(): InteractionContextValue {
|
|
48
|
+
const value = useContext(InteractionContext);
|
|
49
|
+
if (!value) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
"Interaction primitives must be rendered inside <Interaction.Root>.",
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function useInteractionDescriptor(interaction: string) {
|
|
58
|
+
return usePluginState((state) =>
|
|
59
|
+
state.gameplay.availableInteractions.find(
|
|
60
|
+
(descriptor) =>
|
|
61
|
+
descriptor.interactionKey === interaction ||
|
|
62
|
+
descriptor.interactionId === interaction,
|
|
63
|
+
),
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface InteractionRootProps<
|
|
68
|
+
Interaction extends string = InteractionKey,
|
|
69
|
+
> {
|
|
70
|
+
interaction: Interaction;
|
|
71
|
+
children: ReactNode;
|
|
72
|
+
unavailable?: "render" | "hide";
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function ResolvedInteractionRoot({
|
|
76
|
+
interaction,
|
|
77
|
+
descriptor,
|
|
78
|
+
children,
|
|
79
|
+
}: {
|
|
80
|
+
interaction: string;
|
|
81
|
+
descriptor: InteractionDescriptor;
|
|
82
|
+
children: ReactNode;
|
|
83
|
+
}) {
|
|
84
|
+
const handle = useInteractionHandle(descriptor);
|
|
85
|
+
const value = useMemo<InteractionContextValue>(
|
|
86
|
+
() => ({ interaction, descriptor, handle }),
|
|
87
|
+
[descriptor, handle, interaction],
|
|
88
|
+
);
|
|
89
|
+
return (
|
|
90
|
+
<InteractionContext.Provider value={value}>
|
|
91
|
+
{children}
|
|
92
|
+
</InteractionContext.Provider>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function InteractionRoot<Interaction extends string = InteractionKey>({
|
|
97
|
+
interaction,
|
|
98
|
+
children,
|
|
99
|
+
unavailable = "render",
|
|
100
|
+
}: InteractionRootProps<Interaction>) {
|
|
101
|
+
const descriptor = useInteractionDescriptor(interaction);
|
|
102
|
+
if (!descriptor) {
|
|
103
|
+
if (unavailable === "hide") return null;
|
|
104
|
+
return (
|
|
105
|
+
<InteractionContext.Provider
|
|
106
|
+
value={{
|
|
107
|
+
interaction,
|
|
108
|
+
descriptor: null,
|
|
109
|
+
handle: null,
|
|
110
|
+
}}
|
|
111
|
+
>
|
|
112
|
+
{children}
|
|
113
|
+
</InteractionContext.Provider>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
if (!descriptor.available && unavailable === "hide") {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
return (
|
|
120
|
+
<ResolvedInteractionRoot interaction={interaction} descriptor={descriptor}>
|
|
121
|
+
{children}
|
|
122
|
+
</ResolvedInteractionRoot>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export type InteractionPartProps = PrimitiveCommonProps &
|
|
127
|
+
HTMLAttributes<HTMLElement>;
|
|
128
|
+
|
|
129
|
+
export function InteractionLabel({ children, ...props }: InteractionPartProps) {
|
|
130
|
+
const { descriptor, interaction } = useInteractionPrimitiveContext();
|
|
131
|
+
return renderPrimitive("span", {
|
|
132
|
+
...props,
|
|
133
|
+
"data-dreamboard-interaction-label": "",
|
|
134
|
+
children:
|
|
135
|
+
children ??
|
|
136
|
+
(descriptor
|
|
137
|
+
? interactionLabel(descriptor)
|
|
138
|
+
: humanizeInteraction(interaction)),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function InteractionDescription({
|
|
143
|
+
children,
|
|
144
|
+
...props
|
|
145
|
+
}: InteractionPartProps) {
|
|
146
|
+
const content = children;
|
|
147
|
+
if (!content) return null;
|
|
148
|
+
return renderPrimitive("span", {
|
|
149
|
+
...props,
|
|
150
|
+
"data-dreamboard-interaction-description": "",
|
|
151
|
+
children: content,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function InteractionUnavailableMessage({
|
|
156
|
+
children,
|
|
157
|
+
...props
|
|
158
|
+
}: InteractionPartProps) {
|
|
159
|
+
const { descriptor, handle } = useInteractionPrimitiveContext();
|
|
160
|
+
const reason =
|
|
161
|
+
children ?? handle?.unavailableReason ?? descriptor?.unavailableReason;
|
|
162
|
+
if (!reason) return null;
|
|
163
|
+
return renderPrimitive("span", {
|
|
164
|
+
...props,
|
|
165
|
+
"data-dreamboard-interaction-unavailable": "",
|
|
166
|
+
children: reason,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function InteractionValidationMessage({
|
|
171
|
+
children,
|
|
172
|
+
...props
|
|
173
|
+
}: InteractionPartProps) {
|
|
174
|
+
const { handle } = useInteractionPrimitiveContext();
|
|
175
|
+
const validation = handle?.validateDraft();
|
|
176
|
+
const message =
|
|
177
|
+
children ??
|
|
178
|
+
validation?.formErrors[0] ??
|
|
179
|
+
Object.values(validation?.fieldErrors ?? {})[0]?.[0] ??
|
|
180
|
+
(validation?.missing[0]
|
|
181
|
+
? `${String(validation.missing[0])} is required.`
|
|
182
|
+
: null);
|
|
183
|
+
if (!message) return null;
|
|
184
|
+
return renderPrimitive("span", {
|
|
185
|
+
...props,
|
|
186
|
+
"data-dreamboard-interaction-validation": "",
|
|
187
|
+
children: message,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export type InteractionTriggerProps = PrimitiveCommonProps &
|
|
192
|
+
ButtonHTMLAttributes<HTMLButtonElement>;
|
|
193
|
+
|
|
194
|
+
export function InteractionTrigger({
|
|
195
|
+
disabled,
|
|
196
|
+
onClick,
|
|
197
|
+
...props
|
|
198
|
+
}: InteractionTriggerProps) {
|
|
199
|
+
const { descriptor, handle } = useInteractionPrimitiveContext();
|
|
200
|
+
const isDisabled = disabled === true || !descriptor?.available;
|
|
201
|
+
return renderPrimitive("button", {
|
|
202
|
+
type: "button",
|
|
203
|
+
...props,
|
|
204
|
+
disabled: isDisabled,
|
|
205
|
+
"aria-disabled": isDisabled,
|
|
206
|
+
"data-dreamboard-interaction-trigger": "",
|
|
207
|
+
"data-interaction-id": descriptor?.interactionId,
|
|
208
|
+
"data-interaction-key": descriptor?.interactionKey,
|
|
209
|
+
"data-available": descriptor?.available ?? false,
|
|
210
|
+
"data-disabled": isDisabled || undefined,
|
|
211
|
+
"data-state": handle?.isArmed ? "armed" : "idle",
|
|
212
|
+
onClick: composeEventHandlers(onClick, () => {
|
|
213
|
+
handle?.arm();
|
|
214
|
+
}),
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export type InteractionSubmitProps = PrimitiveCommonProps &
|
|
219
|
+
ButtonHTMLAttributes<HTMLButtonElement>;
|
|
220
|
+
|
|
221
|
+
export function InteractionSubmit({
|
|
222
|
+
disabled,
|
|
223
|
+
onClick,
|
|
224
|
+
...props
|
|
225
|
+
}: InteractionSubmitProps) {
|
|
226
|
+
const { descriptor, handle } = useInteractionPrimitiveContext();
|
|
227
|
+
const isSubmitting = handle?.status === "submitting";
|
|
228
|
+
const isDisabled =
|
|
229
|
+
disabled === true ||
|
|
230
|
+
!descriptor?.available ||
|
|
231
|
+
!handle?.isReady ||
|
|
232
|
+
isSubmitting;
|
|
233
|
+
return renderPrimitive("button", {
|
|
234
|
+
type: "button",
|
|
235
|
+
...props,
|
|
236
|
+
disabled: isDisabled,
|
|
237
|
+
"aria-disabled": isDisabled,
|
|
238
|
+
"data-dreamboard-interaction-submit": "",
|
|
239
|
+
"data-interaction-id": descriptor?.interactionId,
|
|
240
|
+
"data-interaction-key": descriptor?.interactionKey,
|
|
241
|
+
"data-available": descriptor?.available ?? false,
|
|
242
|
+
"data-disabled": isDisabled || undefined,
|
|
243
|
+
"data-ready": handle?.isReady ?? false,
|
|
244
|
+
"data-submitting": isSubmitting || undefined,
|
|
245
|
+
"data-state": handle?.status ?? "unavailable",
|
|
246
|
+
onClick: composeEventHandlers(onClick, () => {
|
|
247
|
+
void handle?.submitDraft();
|
|
248
|
+
}),
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export type InteractionInputProps = PrimitiveCommonProps &
|
|
253
|
+
Omit<InputHTMLAttributes<HTMLInputElement>, "name"> & {
|
|
254
|
+
name: string;
|
|
255
|
+
parse?: (value: string) => unknown;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
export function InteractionInput({
|
|
259
|
+
name,
|
|
260
|
+
parse,
|
|
261
|
+
onChange,
|
|
262
|
+
disabled,
|
|
263
|
+
...props
|
|
264
|
+
}: InteractionInputProps) {
|
|
265
|
+
const { descriptor, handle } = useInteractionPrimitiveContext();
|
|
266
|
+
const value = handle?.draft[name];
|
|
267
|
+
const isDisabled = disabled === true || !descriptor?.available;
|
|
268
|
+
return renderPrimitive("input", {
|
|
269
|
+
...props,
|
|
270
|
+
name,
|
|
271
|
+
disabled: isDisabled,
|
|
272
|
+
"aria-disabled": isDisabled,
|
|
273
|
+
"data-dreamboard-interaction-input": "",
|
|
274
|
+
"data-input-name": name,
|
|
275
|
+
"data-disabled": isDisabled || undefined,
|
|
276
|
+
"data-selected": value !== undefined || undefined,
|
|
277
|
+
onChange: composeEventHandlers(onChange, (event) => {
|
|
278
|
+
const target = event.currentTarget;
|
|
279
|
+
handle?.setInput(name, parse ? parse(target.value) : target.value);
|
|
280
|
+
}),
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export type InteractionCardInputProps<
|
|
285
|
+
Input extends string = InteractionInputKey,
|
|
286
|
+
> = PrimitiveCommonProps &
|
|
287
|
+
ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
288
|
+
input: Input;
|
|
289
|
+
value?: string;
|
|
290
|
+
card?: string;
|
|
291
|
+
selected?: boolean;
|
|
292
|
+
onSelectedChange?: (selected: boolean) => void;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
export function InteractionCardInput<
|
|
296
|
+
Input extends string = InteractionInputKey,
|
|
297
|
+
>({
|
|
298
|
+
input,
|
|
299
|
+
value,
|
|
300
|
+
card,
|
|
301
|
+
selected,
|
|
302
|
+
onSelectedChange,
|
|
303
|
+
onClick,
|
|
304
|
+
disabled,
|
|
305
|
+
children,
|
|
306
|
+
...props
|
|
307
|
+
}: InteractionCardInputProps<Input>) {
|
|
308
|
+
const { descriptor, handle } = useInteractionPrimitiveContext();
|
|
309
|
+
const store = useInteractionUiStore();
|
|
310
|
+
const zoneCard = useZoneCardContext();
|
|
311
|
+
const cardId = value ?? card ?? zoneCard?.cardId;
|
|
312
|
+
const cardDescriptor = usePluginState((state) => {
|
|
313
|
+
if (!cardId || !zoneCard) return undefined;
|
|
314
|
+
return state.gameplay.zones[zoneCard.zone]?.playableByCardId[cardId]?.find(
|
|
315
|
+
(candidate) =>
|
|
316
|
+
candidate.interactionKey === descriptor?.interactionKey &&
|
|
317
|
+
candidate.inputs.some((candidateInput) => candidateInput.key === input),
|
|
318
|
+
);
|
|
319
|
+
});
|
|
320
|
+
const inputDescriptor = descriptor
|
|
321
|
+
? inputByKey(descriptor, input)
|
|
322
|
+
: undefined;
|
|
323
|
+
const liveDraft = descriptor ? store.getDraft(descriptor.interactionKey) : {};
|
|
324
|
+
const currentValue =
|
|
325
|
+
liveDraft[input] ?? handle?.draft[input] ?? handle?.values[input];
|
|
326
|
+
const selection = inputDescriptor?.domain.selection;
|
|
327
|
+
const selectedByDraft =
|
|
328
|
+
selection?.mode === "many"
|
|
329
|
+
? Array.isArray(currentValue) &&
|
|
330
|
+
currentValue.map((item) => String(item)).includes(String(cardId))
|
|
331
|
+
: currentValue !== undefined &&
|
|
332
|
+
cardId !== undefined &&
|
|
333
|
+
String(currentValue) === String(cardId);
|
|
334
|
+
const isSelected = selected ?? selectedByDraft;
|
|
335
|
+
const eligibleTargets =
|
|
336
|
+
inputDescriptor?.domain.type === "target"
|
|
337
|
+
? inputDescriptor.domain.eligibleTargets
|
|
338
|
+
: undefined;
|
|
339
|
+
const isCardInput =
|
|
340
|
+
inputDescriptor?.domain.type === "target" &&
|
|
341
|
+
inputDescriptor.domain.targetKind === "card";
|
|
342
|
+
const isEligible =
|
|
343
|
+
cardId !== undefined &&
|
|
344
|
+
isCardInput &&
|
|
345
|
+
(eligibleTargets === undefined || eligibleTargets.includes(cardId));
|
|
346
|
+
const isSelectable =
|
|
347
|
+
cardId !== undefined &&
|
|
348
|
+
inputDescriptor !== undefined &&
|
|
349
|
+
isManyTargetSelectable(inputDescriptor, currentValue, cardId);
|
|
350
|
+
const isCandidateAvailable = cardDescriptor?.available ?? true;
|
|
351
|
+
const validation = handle?.validateDraft();
|
|
352
|
+
const fieldErrors = validation?.fieldErrors[input] ?? [];
|
|
353
|
+
const isInvalid = fieldErrors.length > 0;
|
|
354
|
+
const isDisabled =
|
|
355
|
+
disabled === true ||
|
|
356
|
+
!descriptor?.available ||
|
|
357
|
+
!cardId ||
|
|
358
|
+
!isEligible ||
|
|
359
|
+
!handle;
|
|
360
|
+
|
|
361
|
+
return renderPrimitive("button", {
|
|
362
|
+
type: "button",
|
|
363
|
+
...props,
|
|
364
|
+
children,
|
|
365
|
+
disabled: isDisabled,
|
|
366
|
+
"aria-disabled": isDisabled,
|
|
367
|
+
"aria-pressed": isSelected,
|
|
368
|
+
"data-dreamboard-interaction-card-input": "",
|
|
369
|
+
"data-input-name": input,
|
|
370
|
+
"data-card-id": cardId,
|
|
371
|
+
"data-zone": zoneCard?.zone,
|
|
372
|
+
"data-selected": isSelected || undefined,
|
|
373
|
+
"data-eligible": isEligible,
|
|
374
|
+
"data-selectable": isSelectable,
|
|
375
|
+
"data-card-available": isCandidateAvailable,
|
|
376
|
+
"data-invalid": isInvalid || undefined,
|
|
377
|
+
"data-disabled": isDisabled || undefined,
|
|
378
|
+
"data-missing-resource": cardId ? undefined : true,
|
|
379
|
+
onClick: composeEventHandlers(onClick, () => {
|
|
380
|
+
if (isDisabled || !cardId || !handle || !inputDescriptor) return;
|
|
381
|
+
const nextValue =
|
|
382
|
+
selection?.mode === "many"
|
|
383
|
+
? toggleManyValue(currentValue, cardId, selection)
|
|
384
|
+
: cardId;
|
|
385
|
+
handle.setInput(input, nextValue);
|
|
386
|
+
onSelectedChange?.(
|
|
387
|
+
selection?.mode === "many"
|
|
388
|
+
? Array.isArray(nextValue) && nextValue.includes(cardId)
|
|
389
|
+
: true,
|
|
390
|
+
);
|
|
391
|
+
}),
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
export const Interaction = {
|
|
396
|
+
Root: InteractionRoot,
|
|
397
|
+
Trigger: InteractionTrigger,
|
|
398
|
+
Label: InteractionLabel,
|
|
399
|
+
Description: InteractionDescription,
|
|
400
|
+
UnavailableMessage: InteractionUnavailableMessage,
|
|
401
|
+
ValidationMessage: InteractionValidationMessage,
|
|
402
|
+
Input: InteractionInput,
|
|
403
|
+
CardInput: InteractionCardInput,
|
|
404
|
+
Submit: InteractionSubmit,
|
|
405
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { renderToString } from "react-dom/server";
|
|
3
|
+
import type { PluginStateSnapshot } from "../types/plugin-state.js";
|
|
4
|
+
import type { PluginSessionState, RuntimeAPI } from "../types/runtime-api.js";
|
|
5
|
+
import { GameUIProvider } from "./game-ui-provider.js";
|
|
6
|
+
import { Phase } from "./phase.js";
|
|
7
|
+
|
|
8
|
+
function createSessionState(): PluginSessionState {
|
|
9
|
+
return {
|
|
10
|
+
status: "ready",
|
|
11
|
+
sessionId: "session-1",
|
|
12
|
+
controllablePlayerIds: ["player-1"],
|
|
13
|
+
controllingPlayerId: "player-1",
|
|
14
|
+
userId: "user-1",
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function createSnapshot(currentPhase: string | null): PluginStateSnapshot {
|
|
19
|
+
return {
|
|
20
|
+
view: {},
|
|
21
|
+
gameplay: {
|
|
22
|
+
currentPhase,
|
|
23
|
+
currentStage: null,
|
|
24
|
+
activePlayers: ["player-1"],
|
|
25
|
+
zones: {},
|
|
26
|
+
availableInteractions: [],
|
|
27
|
+
},
|
|
28
|
+
lobby: null,
|
|
29
|
+
notifications: [],
|
|
30
|
+
session: createSessionState(),
|
|
31
|
+
history: null,
|
|
32
|
+
syncId: 1,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function createRuntime(snapshot: PluginStateSnapshot): RuntimeAPI {
|
|
37
|
+
return {
|
|
38
|
+
validateInteraction: async () => ({ valid: true }),
|
|
39
|
+
submitInteraction: async () => undefined,
|
|
40
|
+
getSessionState: () => snapshot.session,
|
|
41
|
+
disconnect: () => undefined,
|
|
42
|
+
getSnapshot: () => snapshot,
|
|
43
|
+
subscribeToState: () => () => undefined,
|
|
44
|
+
} as RuntimeAPI;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
test("Phase.Switch renders the route for the current gameplay phase", () => {
|
|
48
|
+
const runtime = createRuntime(createSnapshot("play"));
|
|
49
|
+
|
|
50
|
+
const html = renderToString(
|
|
51
|
+
<GameUIProvider runtime={runtime}>
|
|
52
|
+
<Phase.Switch
|
|
53
|
+
routes={{
|
|
54
|
+
setup: () => <span>Setup</span>,
|
|
55
|
+
play: () => <span>Play</span>,
|
|
56
|
+
}}
|
|
57
|
+
/>
|
|
58
|
+
</GameUIProvider>,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
expect(html).toContain("Play");
|
|
62
|
+
expect(html).not.toContain("Setup");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("Phase.Switch renders fallback for missing or unknown phases", () => {
|
|
66
|
+
const runtime = createRuntime(createSnapshot("unknown"));
|
|
67
|
+
|
|
68
|
+
const html = renderToString(
|
|
69
|
+
<GameUIProvider runtime={runtime}>
|
|
70
|
+
<Phase.Switch
|
|
71
|
+
routes={{
|
|
72
|
+
setup: () => <span>Setup</span>,
|
|
73
|
+
play: () => <span>Play</span>,
|
|
74
|
+
}}
|
|
75
|
+
fallback={(phase) => <span>Fallback {phase}</span>}
|
|
76
|
+
/>
|
|
77
|
+
</GameUIProvider>,
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
expect(html).toContain("Fallback");
|
|
81
|
+
expect(html).toContain("unknown");
|
|
82
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
|
+
import { usePluginState } from "../context/PluginStateContext.js";
|
|
3
|
+
import type { PhaseKey } from "../ui-contract.js";
|
|
4
|
+
|
|
5
|
+
export type PhaseRouteMap<Phase extends string = PhaseKey> = {
|
|
6
|
+
readonly [Key in Phase]: () => ReactNode;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type PhaseFallback = ReactNode | ((phase: string | null) => ReactNode);
|
|
10
|
+
|
|
11
|
+
export interface PhaseSwitchProps<Phase extends string = PhaseKey> {
|
|
12
|
+
routes: PhaseRouteMap<Phase>;
|
|
13
|
+
fallback?: PhaseFallback;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function hasRoute<Phase extends string>(
|
|
17
|
+
routes: PhaseRouteMap<Phase>,
|
|
18
|
+
phase: string,
|
|
19
|
+
): phase is Phase {
|
|
20
|
+
return Object.prototype.hasOwnProperty.call(routes, phase);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function renderFallback(
|
|
24
|
+
fallback: PhaseFallback | undefined,
|
|
25
|
+
phase: string | null,
|
|
26
|
+
): ReactNode {
|
|
27
|
+
return typeof fallback === "function" ? fallback(phase) : (fallback ?? null);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function PhaseSwitch<Phase extends string = PhaseKey>({
|
|
31
|
+
routes,
|
|
32
|
+
fallback,
|
|
33
|
+
}: PhaseSwitchProps<Phase>): ReactElement | null {
|
|
34
|
+
const phase = usePluginState((state) => state.gameplay.currentPhase);
|
|
35
|
+
if (phase && hasRoute(routes, phase)) {
|
|
36
|
+
return <>{routes[phase]()}</>;
|
|
37
|
+
}
|
|
38
|
+
return <>{renderFallback(fallback, phase)}</>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const Phase = {
|
|
42
|
+
Switch: PhaseSwitch,
|
|
43
|
+
};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { renderToString } from "react-dom/server";
|
|
3
|
+
import type { PluginStateSnapshot } from "../types/plugin-state.js";
|
|
4
|
+
import type { RuntimeAPI, PluginSessionState } from "../types/runtime-api.js";
|
|
5
|
+
import { GameUIProvider } from "./game-ui-provider.js";
|
|
6
|
+
import { PlayerRoster } from "./player-roster.js";
|
|
7
|
+
|
|
8
|
+
function createSessionState(
|
|
9
|
+
overrides: Partial<PluginSessionState> = {},
|
|
10
|
+
): PluginSessionState {
|
|
11
|
+
return {
|
|
12
|
+
status: "ready",
|
|
13
|
+
sessionId: "session-1",
|
|
14
|
+
controllablePlayerIds: ["player-1", "player-2"],
|
|
15
|
+
controllingPlayerId: "player-1",
|
|
16
|
+
userId: "user-1",
|
|
17
|
+
...overrides,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function createSnapshot(
|
|
22
|
+
session = createSessionState(),
|
|
23
|
+
seats: NonNullable<PluginStateSnapshot["lobby"]>["seats"] = [
|
|
24
|
+
{
|
|
25
|
+
playerId: "player-1",
|
|
26
|
+
displayName: "Ada",
|
|
27
|
+
playerColor: "#d04848",
|
|
28
|
+
isHost: true,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
playerId: "player-2",
|
|
32
|
+
displayName: "Grace",
|
|
33
|
+
playerColor: "#2d5da1",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
playerId: "player-3",
|
|
37
|
+
displayName: "Linus",
|
|
38
|
+
playerColor: "#1f7d3e",
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
): PluginStateSnapshot {
|
|
42
|
+
return {
|
|
43
|
+
view: {},
|
|
44
|
+
gameplay: {
|
|
45
|
+
currentPhase: "playing",
|
|
46
|
+
currentStage: null,
|
|
47
|
+
activePlayers: ["player-2"],
|
|
48
|
+
zones: {},
|
|
49
|
+
availableInteractions: [],
|
|
50
|
+
},
|
|
51
|
+
lobby: {
|
|
52
|
+
hostUserId: "user-1",
|
|
53
|
+
canStart: true,
|
|
54
|
+
seats,
|
|
55
|
+
},
|
|
56
|
+
notifications: [],
|
|
57
|
+
session,
|
|
58
|
+
history: null,
|
|
59
|
+
syncId: 1,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function createRuntime(snapshot: PluginStateSnapshot): RuntimeAPI {
|
|
64
|
+
return {
|
|
65
|
+
validateInteraction: async () => ({ valid: true }),
|
|
66
|
+
submitInteraction: async () => undefined,
|
|
67
|
+
getSessionState: () => snapshot.session,
|
|
68
|
+
disconnect: () => undefined,
|
|
69
|
+
getSnapshot: () => snapshot,
|
|
70
|
+
subscribeToState: () => () => undefined,
|
|
71
|
+
switchPlayer: () => undefined,
|
|
72
|
+
} as RuntimeAPI;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
test("PlayerRoster renders turn-order entries with projected state", () => {
|
|
76
|
+
const runtime = createRuntime(createSnapshot());
|
|
77
|
+
|
|
78
|
+
const html = renderToString(
|
|
79
|
+
<GameUIProvider runtime={runtime}>
|
|
80
|
+
<PlayerRoster.Root
|
|
81
|
+
score={(playerId) => (playerId === "player-2" ? 7 : 0)}
|
|
82
|
+
scoreLabel="VP"
|
|
83
|
+
badges={(playerId) => [
|
|
84
|
+
playerId === "player-2"
|
|
85
|
+
? { key: "leader", label: "Leader", tooltip: "Current leader" }
|
|
86
|
+
: null,
|
|
87
|
+
]}
|
|
88
|
+
>
|
|
89
|
+
<PlayerRoster.List>
|
|
90
|
+
{(player) => (
|
|
91
|
+
<PlayerRoster.SwitchButton key={player.playerId} player={player}>
|
|
92
|
+
<PlayerRoster.Name player={player} />
|
|
93
|
+
<PlayerRoster.Score player={player} />
|
|
94
|
+
<PlayerRoster.Badges player={player} />
|
|
95
|
+
</PlayerRoster.SwitchButton>
|
|
96
|
+
)}
|
|
97
|
+
</PlayerRoster.List>
|
|
98
|
+
</PlayerRoster.Root>
|
|
99
|
+
</GameUIProvider>,
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
expect(html).toContain('data-dreamboard-player-roster-list=""');
|
|
103
|
+
expect(html).toContain('data-player-id="player-1"');
|
|
104
|
+
expect(html).toContain('data-current="true"');
|
|
105
|
+
expect(html).toContain('data-player-id="player-2"');
|
|
106
|
+
expect(html).toContain('data-active="true"');
|
|
107
|
+
expect(html).toContain('data-switchable="true"');
|
|
108
|
+
expect(html).toContain("Ada");
|
|
109
|
+
expect(html).toContain("Grace");
|
|
110
|
+
expect(html).toContain("7 VP");
|
|
111
|
+
expect(html).toContain("Leader");
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test("PlayerRoster supports self-first ordering, filters, empty state, and asChild", () => {
|
|
115
|
+
const runtime = createRuntime(
|
|
116
|
+
createSnapshot(
|
|
117
|
+
createSessionState({
|
|
118
|
+
controllablePlayerIds: ["player-2"],
|
|
119
|
+
controllingPlayerId: "player-2",
|
|
120
|
+
}),
|
|
121
|
+
),
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
const selfFirstHtml = renderToString(
|
|
125
|
+
<GameUIProvider runtime={runtime}>
|
|
126
|
+
<PlayerRoster.Root order="self-first">
|
|
127
|
+
<PlayerRoster.List>
|
|
128
|
+
{(player) => <span key={player.playerId}>{player.name}</span>}
|
|
129
|
+
</PlayerRoster.List>
|
|
130
|
+
</PlayerRoster.Root>
|
|
131
|
+
</GameUIProvider>,
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
expect(selfFirstHtml.indexOf("Grace")).toBeLessThan(
|
|
135
|
+
selfFirstHtml.indexOf("Ada"),
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
const opponentsHtml = renderToString(
|
|
139
|
+
<GameUIProvider runtime={runtime}>
|
|
140
|
+
<PlayerRoster.Root include="opponents">
|
|
141
|
+
<PlayerRoster.List>
|
|
142
|
+
{(player) => (
|
|
143
|
+
<PlayerRoster.SwitchButton player={player} asChild>
|
|
144
|
+
<button className="author-row">{player.name}</button>
|
|
145
|
+
</PlayerRoster.SwitchButton>
|
|
146
|
+
)}
|
|
147
|
+
</PlayerRoster.List>
|
|
148
|
+
</PlayerRoster.Root>
|
|
149
|
+
</GameUIProvider>,
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
expect(opponentsHtml).not.toContain("Grace");
|
|
153
|
+
expect(opponentsHtml).toContain('class="author-row"');
|
|
154
|
+
expect(opponentsHtml).toContain('data-dreamboard-player-roster-switch=""');
|
|
155
|
+
expect(opponentsHtml).toContain('disabled=""');
|
|
156
|
+
|
|
157
|
+
const emptyRuntime = createRuntime(createSnapshot(createSessionState(), []));
|
|
158
|
+
const emptyHtml = renderToString(
|
|
159
|
+
<GameUIProvider runtime={emptyRuntime}>
|
|
160
|
+
<PlayerRoster.Root>
|
|
161
|
+
<PlayerRoster.Empty>No players</PlayerRoster.Empty>
|
|
162
|
+
<PlayerRoster.List />
|
|
163
|
+
</PlayerRoster.Root>
|
|
164
|
+
</GameUIProvider>,
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
expect(emptyHtml).toContain("No players");
|
|
168
|
+
});
|