@hadoku/game-ui 0.1.161 → 0.1.162
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/screens/route.d.ts
CHANGED
|
@@ -128,7 +128,9 @@ export declare function canonicalAddress(location: {
|
|
|
128
128
|
search: string;
|
|
129
129
|
hash: string;
|
|
130
130
|
}, base: string): string | null;
|
|
131
|
-
export declare const useRoute: () => Route, currentRoute: () => Route, routeInMemory: (start: Route) => () => void, canonicalizeAddress: () => void
|
|
131
|
+
export declare const useRoute: () => Route, currentRoute: () => Route, routeInMemory: (start: Route) => () => void, canonicalizeAddress: () => void,
|
|
132
|
+
/** Where this page was before the route it is on (`./router.ts`): a screen's way back. */
|
|
133
|
+
cameFrom: (skip?: ((route: Route) => boolean) | undefined) => Route | null;
|
|
132
134
|
/**
|
|
133
135
|
* Go somewhere: a history entry standalone (`replace` swaps the current one, for a screen that
|
|
134
136
|
* forwards on its own), the in-memory route embedded.
|
package/dist/screens/route.js
CHANGED
|
@@ -279,7 +279,9 @@ const router = createHashRouter({
|
|
|
279
279
|
});
|
|
280
280
|
export const { useRoute, currentRoute, routeInMemory,
|
|
281
281
|
/** Puts this page on its route's own address, before anything reads the route and after each move. */
|
|
282
|
-
canonicalize: canonicalizeAddress,
|
|
282
|
+
canonicalize: canonicalizeAddress,
|
|
283
|
+
/** Where this page was before the route it is on (`./router.ts`): a screen's way back. */
|
|
284
|
+
cameFrom, } = router;
|
|
283
285
|
/**
|
|
284
286
|
* Go somewhere: a history entry standalone (`replace` swaps the current one, for a screen that
|
|
285
287
|
* forwards on its own), the in-memory route embedded.
|
package/dist/screens/router.d.ts
CHANGED
|
@@ -44,6 +44,12 @@ export interface HashRouter<R> {
|
|
|
44
44
|
canonicalize(): void;
|
|
45
45
|
/** Whether the route is in memory now (an embed is mounted). */
|
|
46
46
|
inMemory(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* The newest route this page was on before the one it is on now, skipping any `skip` names:
|
|
49
|
+
* where a screen's way out goes back to. A route a screen forwarded away from (`replace`) is
|
|
50
|
+
* not one the page came from. Null when the page came from nowhere `skip` lets through.
|
|
51
|
+
*/
|
|
52
|
+
cameFrom(skip?: (route: R) => boolean): R | null;
|
|
47
53
|
/** Subscribes to route changes; returns the unsubscribe. */
|
|
48
54
|
subscribe(listener: () => void): () => void;
|
|
49
55
|
parse(hash: string): R;
|
package/dist/screens/router.js
CHANGED
|
@@ -35,6 +35,28 @@ export function createHashRouter({ parse, toHash, paths, base = bundlerBase }) {
|
|
|
35
35
|
for (const listener of [...listeners])
|
|
36
36
|
listener();
|
|
37
37
|
};
|
|
38
|
+
/** The routes this page has been on, as hashes, oldest first; the last is where it is now. */
|
|
39
|
+
const trail = [];
|
|
40
|
+
const TRAIL_MAX = 20;
|
|
41
|
+
/** The page is on `hash` now: a new place, or (`replace`) the same place under a new name. */
|
|
42
|
+
const arrived = (hash, replace) => {
|
|
43
|
+
if (trail.at(-1) === hash)
|
|
44
|
+
return;
|
|
45
|
+
if (replace && trail.length > 0)
|
|
46
|
+
trail[trail.length - 1] = hash;
|
|
47
|
+
else
|
|
48
|
+
trail.push(hash);
|
|
49
|
+
if (trail.length > TRAIL_MAX)
|
|
50
|
+
trail.shift();
|
|
51
|
+
};
|
|
52
|
+
const cameFrom = (skip = () => false) => {
|
|
53
|
+
for (let i = trail.length - 2; i >= 0; i--) {
|
|
54
|
+
const route = parse(trail[i]);
|
|
55
|
+
if (trail[i] !== trail.at(-1) && !skip(route))
|
|
56
|
+
return route;
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
};
|
|
38
60
|
const canonicalize = () => {
|
|
39
61
|
const location = globalThis.location;
|
|
40
62
|
if (paths?.canonical === undefined || location === undefined)
|
|
@@ -46,6 +68,7 @@ export function createHashRouter({ parse, toHash, paths, base = bundlerBase }) {
|
|
|
46
68
|
/** The address bar moved on its own (Back, Forward, a `#` link): correct it, then re-read it. */
|
|
47
69
|
const moved = () => {
|
|
48
70
|
canonicalize();
|
|
71
|
+
arrived(currentHash(), false);
|
|
49
72
|
notify();
|
|
50
73
|
};
|
|
51
74
|
// Subscribed to the window only while the address bar is ours and somebody is listening.
|
|
@@ -62,6 +85,8 @@ export function createHashRouter({ parse, toHash, paths, base = bundlerBase }) {
|
|
|
62
85
|
}
|
|
63
86
|
};
|
|
64
87
|
const subscribe = (listener) => {
|
|
88
|
+
if (trail.length === 0)
|
|
89
|
+
arrived(currentHash(), false);
|
|
65
90
|
listeners.add(listener);
|
|
66
91
|
syncWindow();
|
|
67
92
|
return () => {
|
|
@@ -85,6 +110,7 @@ export function createHashRouter({ parse, toHash, paths, base = bundlerBase }) {
|
|
|
85
110
|
return `${path}${location.search}${hash}`;
|
|
86
111
|
};
|
|
87
112
|
const navigate = (route, { replace = false } = {}) => {
|
|
113
|
+
arrived(currentHash(), false);
|
|
88
114
|
if (memory !== null)
|
|
89
115
|
memory.hash = toHash(route);
|
|
90
116
|
else {
|
|
@@ -98,6 +124,7 @@ export function createHashRouter({ parse, toHash, paths, base = bundlerBase }) {
|
|
|
98
124
|
globalThis.history.pushState(null, '', next);
|
|
99
125
|
}
|
|
100
126
|
}
|
|
127
|
+
arrived(currentHash(), replace);
|
|
101
128
|
notify();
|
|
102
129
|
};
|
|
103
130
|
const routeInMemory = (start) => {
|
|
@@ -125,6 +152,7 @@ export function createHashRouter({ parse, toHash, paths, base = bundlerBase }) {
|
|
|
125
152
|
navigate,
|
|
126
153
|
routeInMemory,
|
|
127
154
|
canonicalize,
|
|
155
|
+
cameFrom,
|
|
128
156
|
inMemory: () => memory !== null,
|
|
129
157
|
subscribe,
|
|
130
158
|
parse,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/game-ui",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.1.162",
|
|
4
|
+
"gitHead": "f4e92f118d1150aa86793fe34d82f5a3bf199a87",
|
|
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.
|
|
58
|
-
"@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.
|
|
57
|
+
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.166",
|
|
58
|
+
"@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.166",
|
|
59
59
|
"@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.2",
|
|
60
60
|
"@wolffm/rooms-client": "npm:@hadoku/rooms-client@^0.45.144",
|
|
61
61
|
"@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.144",
|