@hadoku/ui-shell 0.1.36 → 0.1.37

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.
@@ -13,27 +13,32 @@ import { useCallback } from 'react';
13
13
  /** The frame `el` is drawn in: the app's own, or the embed's. */
14
14
  const frameOf = (el) => el.closest('.cardtable-chrome');
15
15
  /**
16
- * Mark the page frame with `name`=`value` for as long as `el` is drawn. Several marking it at once (a
17
- * screen redrawn into a new element before the old one goes) each hold it; it goes with the last.
16
+ * Mark the page frame with `name`=`value` for as long as `el` is drawn. Holders stack per
17
+ * attribute, in the order they took it: the frame always shows the LAST one still holding, and a
18
+ * holder that unmounts falls back to whichever is still underneath it — not just to nothing. A
19
+ * screen nested inside another's frame (the lobby's sideboard step holding `'match'` over the
20
+ * room's own `'fit'`) relies on this: it can give the attribute back to the one it covered.
18
21
  */
19
22
  function hold(el, name, value) {
20
23
  const frame = frameOf(el);
21
24
  if (frame === null)
22
25
  return () => undefined;
23
- const holders = HELD.get(frame) ?? new Map();
24
- HELD.set(frame, holders);
25
- const key = `${name}=${value}`;
26
- holders.set(key, (holders.get(key) ?? 0) + 1);
26
+ const stacks = HELD.get(frame) ?? new Map();
27
+ HELD.set(frame, stacks);
28
+ const stack = stacks.get(name) ?? [];
29
+ stacks.set(name, stack);
30
+ const entry = { value };
31
+ stack.push(entry);
27
32
  frame.setAttribute(name, value);
28
33
  return () => {
29
- const left = (holders.get(key) ?? 1) - 1;
30
- if (left > 0)
31
- holders.set(key, left);
32
- else {
33
- holders.delete(key);
34
- if (frame.getAttribute(name) === value)
35
- frame.removeAttribute(name);
36
- }
34
+ const at = stack.indexOf(entry);
35
+ if (at >= 0)
36
+ stack.splice(at, 1);
37
+ const top = stack[stack.length - 1];
38
+ if (top !== undefined)
39
+ frame.setAttribute(name, top.value);
40
+ else
41
+ frame.removeAttribute(name);
37
42
  };
38
43
  }
39
44
  const HELD = new WeakMap();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/ui-shell",
3
- "version": "0.1.36",
4
- "gitHead": "0042b4a6b48122971a996d7f469677d4b0e105ea",
3
+ "version": "0.1.37",
4
+ "gitHead": "f7fa1adf56787f42a175c5ddd4e290f0d1355068",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "description": "The parts of a game's UI any game keeps: chrome, trim, room shell, embed mount, theme and settings frame, UI scale, usage counting, the sound mixer, motion and generic components. One appId parameterizes its storage keys, events and chat prefix. MIT; imports only react, react-dom and @wolffm/*.",