@hadoku/game-ui 0.1.117 → 0.1.119

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.
@@ -19,6 +19,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
19
19
  */
20
20
  import { useLayoutEffect, useSyncExternalStore } from 'react';
21
21
  import { navigate } from "../screens/route.js";
22
+ import { leaveRoomThen } from "../rooms/screen/room-exit.js";
22
23
  import { CardtableSettings } from "../settings/Settings.js";
23
24
  import { PAGE_LINKS } from "./HeaderLinks.js";
24
25
  let holders = 0;
@@ -80,7 +81,8 @@ export function TopBar({ children }) {
80
81
  }
81
82
  /** What the chat toolbar carries for the page: the top bar's own Home, settings and links. */
82
83
  export const PAGE_TOOLBAR = {
83
- onHome: () => navigate({ kind: 'lobby' }),
84
+ // Leaves the room drawn, if any, as the top bar's own Home does (`rooms/screen/room-exit.tsx`).
85
+ onHome: () => void leaveRoomThen(() => navigate({ kind: 'lobby' })),
84
86
  settings: { section: _jsx(CardtableSettings, {}) },
85
87
  extra: PAGE_LINKS,
86
88
  };
@@ -39,6 +39,18 @@ export const EXTERNAL_GAMES = [
39
39
  embedSrc: '/bomberman/embed/bomberman-embed.js',
40
40
  seatRejoinGraceMs: 120_000,
41
41
  },
42
+ // An outside author's game (Cozmiverse/crossover-cards), served friends-only from
43
+ // `/games/crossover-cards/` by hadoku_site's game-bundles.json row. Its rooms are friends-only
44
+ // too, whatever the app's floor: it carries other publishers' card data.
45
+ {
46
+ id: 'crossover-cards',
47
+ label: 'Crossover Cards',
48
+ seats: { min: 2, max: 4 },
49
+ runtime: 'relay',
50
+ embedSrc: '/games/crossover-cards/embed.js',
51
+ seatRejoinGraceMs: 120_000,
52
+ minTier: 'friend',
53
+ },
42
54
  {
43
55
  id: 'e2e-toy-relay',
44
56
  label: 'Toy Relay Game',
@@ -0,0 +1,9 @@
1
+ /* Leave, first in the room's head row, the same size as Close and Room settings beside it
2
+ (`.room-close`, Magic's own sheet). Colour and hover are `.ct-action`'s. */
3
+ .room-leave {
4
+ flex: none;
5
+ align-self: flex-start;
6
+ padding: 0.2rem 0.6rem;
7
+ font-size: 0.85em;
8
+ border-radius: var(--hdk-radius);
9
+ }
@@ -1,4 +1,7 @@
1
- import type { ReactNode, RefCallback } from 'react';
1
+ import { type ReactNode, type RefCallback } from 'react';
2
+ import { type LeaveRoom } from './room-exit.js';
3
+ import '../../components/Button.css';
4
+ import './RoomShell.css';
2
5
  export interface RoomShellProps {
3
6
  shellRef: RefCallback<HTMLElement>;
4
7
  /** `view.members.length` once the room record has one; the room screen's own `data-members`. */
@@ -10,6 +13,11 @@ export interface RoomShellProps {
10
13
  /** The room answered with a refusal rather than useful data: nothing more to wait for, so the
11
14
  * title falls back to "Room" instead of staying a skeleton. */
12
15
  settled: boolean;
16
+ /**
17
+ * The game's `/leave` for this room. Given, and the host has a way home (`RoomHomeProvider`), the
18
+ * head row draws Leave, and the page's top bar leaves through it too (`room-exit.tsx`).
19
+ */
20
+ leave?: LeaveRoom;
13
21
  /** Close, Settings, and whatever the game type's own settings panel wants beside them. */
14
22
  headerTools: ReactNode;
15
23
  streamed: boolean;
@@ -32,4 +40,4 @@ export interface RoomShellProps {
32
40
  /** The game type's own content: its setup, its game, in that order. */
33
41
  children: ReactNode;
34
42
  }
35
- export declare function RoomShell({ shellRef, dataMembers, roomTitle, titleAside, settled, headerTools, streamed, streamedSubLine, resolved, pending, pendingBody, streamedBody, locked, password, onPasswordChange, onPasswordSubmit, roomMissingMessage, children, }: RoomShellProps): import("react").JSX.Element;
43
+ export declare function RoomShell({ shellRef, dataMembers, roomTitle, titleAside, settled, leave, headerTools, streamed, streamedSubLine, resolved, pending, pendingBody, streamedBody, locked, password, onPasswordChange, onPasswordSubmit, roomMissingMessage, children, }: RoomShellProps): import("react").JSX.Element;
@@ -1,6 +1,28 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- export function RoomShell({ shellRef, dataMembers, roomTitle, titleAside, settled, headerTools, streamed, streamedSubLine, resolved, pending, pendingBody, streamedBody, locked, password, onPasswordChange, onPasswordSubmit, roomMissingMessage, children, }) {
3
- return (_jsxs("div", { ref: shellRef, className: "shell shell--fit", "data-testid": "constructed", "data-members": dataMembers, children: [_jsxs("header", { className: "shell__head", children: [roomTitle !== undefined ? (_jsx("h1", { className: "shell__title", "data-testid": "room-name", children: roomTitle })) : settled ? (_jsx("h1", { className: "shell__title", children: "Room" })) : (_jsx("span", { className: "skeleton skeleton--title" })), roomTitle !== undefined && titleAside, _jsx("div", { className: "shell__tools", children: headerTools }), resolved && streamed && streamedSubLine] }), _jsxs("main", { className: "lobby lobby--room", "aria-busy": pending ? 'true' : undefined, children: [pending && pendingBody, streamed && streamedBody, !streamed && resolved && (_jsxs(_Fragment, { children: [locked !== null && (_jsxs("form", { className: "lobby__locked ct-panel", "data-testid": "room-locked", onSubmit: (e) => {
2
+ /*
3
+ * The room screen's own chrome: the shell, the title, the header's tool row, the streamed/builtin
4
+ * split, the password gate, and the one message a room that could not be read gets. Every room
5
+ * has this, whatever it plays — a game type's own content is a slot (`children`), never something
6
+ * this file knows the shape of.
7
+ *
8
+ * Nothing here is Magic's: no deck, no mode, no table. What a game type puts in the header
9
+ * (Magic's own settings panel, say) arrives already built, as `headerTools`; what it puts in the
10
+ * room's body arrives as `children`, rendered only once `resolved` is true and the room is not
11
+ * streamed — a streamed room draws `streamedBody` instead, and neither draws until the room record
12
+ * has answered.
13
+ */
14
+ import { useState } from 'react';
15
+ import { leaveRoomThen, useRoomHome, useRoomLeave } from "./room-exit.js";
16
+ import '../../components/Button.css';
17
+ import './RoomShell.css';
18
+ export function RoomShell({ shellRef, dataMembers, roomTitle, titleAside, settled, leave, headerTools, streamed, streamedSubLine, resolved, pending, pendingBody, streamedBody, locked, password, onPasswordChange, onPasswordSubmit, roomMissingMessage, children, }) {
19
+ useRoomLeave(leave ?? null);
20
+ const home = useRoomHome();
21
+ const [leaving, setLeaving] = useState(false);
22
+ return (_jsxs("div", { ref: shellRef, className: "shell shell--fit", "data-testid": "constructed", "data-members": dataMembers, children: [_jsxs("header", { className: "shell__head", children: [roomTitle !== undefined ? (_jsx("h1", { className: "shell__title", "data-testid": "room-name", children: roomTitle })) : settled ? (_jsx("h1", { className: "shell__title", children: "Room" })) : (_jsx("span", { className: "skeleton skeleton--title" })), roomTitle !== undefined && titleAside, _jsxs("div", { className: "shell__tools", children: [leave !== undefined && home !== null && (_jsx("button", { type: "button", className: "room-leave ct-action", "data-testid": "room-leave", disabled: leaving, onClick: () => {
23
+ setLeaving(true);
24
+ void leaveRoomThen(home);
25
+ }, children: _jsx("span", { className: "ct-action__label", children: "Leave" }) })), headerTools] }), resolved && streamed && streamedSubLine] }), _jsxs("main", { className: "lobby lobby--room", "aria-busy": pending ? 'true' : undefined, children: [pending && pendingBody, streamed && streamedBody, !streamed && resolved && (_jsxs(_Fragment, { children: [locked !== null && (_jsxs("form", { className: "lobby__locked ct-panel", "data-testid": "room-locked", onSubmit: (e) => {
4
26
  e.preventDefault();
5
27
  onPasswordSubmit();
6
28
  }, children: [_jsx("p", { role: "alert", children: locked === 'need' ? 'This room needs a password.' : locked === 'wrong' ? 'Wrong password.' : 'Too many attempts.' }), _jsx("label", { htmlFor: "room-password", children: "Password" }), _jsx("input", { id: "room-password", "data-testid": "room-password", type: "password", autoComplete: "off", value: password, onChange: (e) => onPasswordChange(e.target.value) }), _jsx("button", { type: "submit", "data-testid": "room-password-submit", disabled: locked === 'rate-limited', children: "Join" })] })), locked === null && roomMissingMessage !== null && (_jsx("p", { className: "ct-error", role: "alert", "data-testid": "room-missing", children: roomMissingMessage })), children] }))] })] }));
@@ -0,0 +1,29 @@
1
+ import { type AnchorHTMLAttributes } from 'react';
2
+ /** Where the viewer goes once they have left. `null`: this host has no "home" to leave to. */
3
+ export type RoomHome = (() => void) | null;
4
+ /** The host's own way home, for every room shell below it. */
5
+ export declare const RoomHomeProvider: import("react").Provider<RoomHome>;
6
+ export declare function useRoomHome(): RoomHome;
7
+ /** The game's `/leave` for the room on screen; whatever it answers, the viewer goes home after. */
8
+ export type LeaveRoom = () => Promise<unknown>;
9
+ /**
10
+ * Registers how to leave the room drawn now, for as long as it is drawn. The latest `leave` is the
11
+ * one called, so a caller may pass a fresh closure every render.
12
+ */
13
+ export declare function useRoomLeave(leave: LeaveRoom | null): void;
14
+ /**
15
+ * Leave the room on screen, if there is one, then `home`. With no room drawn (the front page, a
16
+ * match, an embedded slot), `home` alone. `home` runs whatever the leave answered: a refusal (the
17
+ * room was closed under you, say) still leaves you where you asked to go, and a throw still goes
18
+ * home before it reaches the caller.
19
+ */
20
+ export declare function leaveRoomThen(home: () => void): Promise<void>;
21
+ /**
22
+ * The page's way home (a top bar's title, say), which leaves the room on screen on its way. A real
23
+ * anchor, so it is keyboard-reachable, announces itself as a link and middle-clicks to `href`;
24
+ * a plain press leaves, then goes where the host's `RoomHomeProvider` says. Under no provider it is
25
+ * an ordinary link to `href`.
26
+ */
27
+ export declare function RoomHomeLink({ href, ...anchor }: {
28
+ href: string;
29
+ } & Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href' | 'onClick'>): import("react").JSX.Element;
@@ -0,0 +1,78 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /*
3
+ * Leaving a room: the one way out of the room page, whichever control asks for it.
4
+ *
5
+ * The operator, 2026-11-24: *"leave buttons seem good … And make sure clicking the top bar works as
6
+ * well. I'd expect both to work."* Until then the top bar's title only navigated home: the player
7
+ * stayed a member of the room they walked out of, and the only thing that left was a match's
8
+ * result screen ("Main menu").
9
+ *
10
+ * Two halves, because the room and the way home belong to different owners:
11
+ *
12
+ * - **How to leave this room** is the game's: its own client's `/leave` (membership ends only by
13
+ * `/leave`, a close or the idle sweep; the leader's hand-over is the kit's). The room shell
14
+ * registers it while it is drawn (`useRoomLeave`), so a control outside the room's tree — the
15
+ * page's top bar — reaches it through `leaveRoomThen`.
16
+ * `RoomHomeLink` is that top bar's link, for any host that draws one.
17
+ * - **Where home is** is the host's (`RoomHomeProvider`). Standalone, the app's front page; inside
18
+ * another site's page, whatever that site says. A host that supplies none (a slot whose room is
19
+ * the host's own, like a watchparty room's game) gets no Leave button: the shell never assumes it
20
+ * owns the page or the URL.
21
+ */
22
+ import { createContext, useContext, useEffect, useRef } from 'react';
23
+ const RoomHomeContext = createContext(null);
24
+ /** The host's own way home, for every room shell below it. */
25
+ export const RoomHomeProvider = RoomHomeContext.Provider;
26
+ export function useRoomHome() {
27
+ return useContext(RoomHomeContext);
28
+ }
29
+ let current = null;
30
+ /**
31
+ * Registers how to leave the room drawn now, for as long as it is drawn. The latest `leave` is the
32
+ * one called, so a caller may pass a fresh closure every render.
33
+ */
34
+ export function useRoomLeave(leave) {
35
+ const latest = useRef(leave);
36
+ latest.current = leave;
37
+ const present = leave !== null;
38
+ useEffect(() => {
39
+ if (!present)
40
+ return;
41
+ const registered = () => (latest.current ?? (() => Promise.resolve()))();
42
+ current = registered;
43
+ return () => {
44
+ if (current === registered)
45
+ current = null;
46
+ };
47
+ }, [present]);
48
+ }
49
+ /**
50
+ * Leave the room on screen, if there is one, then `home`. With no room drawn (the front page, a
51
+ * match, an embedded slot), `home` alone. `home` runs whatever the leave answered: a refusal (the
52
+ * room was closed under you, say) still leaves you where you asked to go, and a throw still goes
53
+ * home before it reaches the caller.
54
+ */
55
+ export function leaveRoomThen(home) {
56
+ const leave = current;
57
+ current = null;
58
+ if (leave === null) {
59
+ home();
60
+ return Promise.resolve();
61
+ }
62
+ return leave().finally(home).then(() => undefined);
63
+ }
64
+ /**
65
+ * The page's way home (a top bar's title, say), which leaves the room on screen on its way. A real
66
+ * anchor, so it is keyboard-reachable, announces itself as a link and middle-clicks to `href`;
67
+ * a plain press leaves, then goes where the host's `RoomHomeProvider` says. Under no provider it is
68
+ * an ordinary link to `href`.
69
+ */
70
+ export function RoomHomeLink({ href, ...anchor }) {
71
+ const home = useRoomHome();
72
+ return (_jsx("a", { ...anchor, href: href, onClick: home === null
73
+ ? undefined
74
+ : (e) => {
75
+ e.preventDefault();
76
+ void leaveRoomThen(home);
77
+ } }));
78
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/game-ui",
3
- "version": "0.1.117",
4
- "gitHead": "d091b550be20cf5943acd5e4e372c0a6fd0d7eae",
3
+ "version": "0.1.119",
4
+ "gitHead": "abbba44ae6b98e0d26d5c6f525d83eabb74b9555",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "description": "The browser parts any hosted game shares, above ui-shell: the room shell and session, seats and looks, the room route, the front page's generic pieces (gate, polls, gallery, patch notes), the bundle slot and relay channel a game's client mounts in, settings and trim screens, the HTTP and socket helpers, and the generic components (modal, popover, avatar, action button, radio cards). Knows no game; Magic's UI (games/magic/ui) plugs in, composed by the site (apps/ui). MIT; imports only react, react-dom, socket.io-client, @wolffm/* and the platform packages.",
@@ -54,8 +54,8 @@
54
54
  "react-dom": "^19.2.8"
55
55
  },
56
56
  "dependencies": {
57
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.121",
58
- "@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.121",
57
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.123",
58
+ "@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.123",
59
59
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.0",
60
60
  "@wolffm/rooms-client": "npm:@hadoku/rooms-client@^0.45.134",
61
61
  "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.134",