@dasl/tile-loader 3.2.0 → 5.0.0

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.
@@ -0,0 +1,66 @@
1
+ // A tile's frame out of the tab order, for as long as something needs it
2
+ // out: a layer of the page's over the tile, which is where Tab stops then,
3
+ // or a tile that waits to be picked. More than one may need it out at once,
4
+ // and each lets go in its own time. Were each to note the frame's tabindex
5
+ // and put back what it found, one that let go after another had taken the
6
+ // frame out would put it back in under the other's layer, or one that took
7
+ // it out after another would leave it out for good. So they all go through
8
+ // here: the frame is out while anything holds it, and once the last lets go
9
+ // it is given back the tabindex its host gave it, or none if it had none.
10
+ // And a frame held out can be let in for a moment, for one Tab of the
11
+ // user's into it, which goes through here as well (see `letIn`).
12
+
13
+ interface Held {
14
+ own: string | null; // the host's tabindex, as it was at the first hold
15
+ holds: number;
16
+ open?: object; // the moment it is let in for, while it is (see `letIn`)
17
+ }
18
+ const held = new WeakMap<Element, Held>();
19
+
20
+ /**
21
+ * Takes `frame` out of the tab order until the function it returns is
22
+ * called. That puts it back only if nothing else holds it out by then; a
23
+ * second call does nothing.
24
+ */
25
+ export function holdOut (frame: Element): () => void {
26
+ let hold = held.get(frame);
27
+ if (!hold) {
28
+ hold = { own: frame.getAttribute('tabindex'), holds: 0 };
29
+ held.set(frame, hold);
30
+ }
31
+ const mine = hold;
32
+ mine.holds++;
33
+ // (Out, whatever let it in a moment ago: something needs it out now.)
34
+ mine.open = undefined;
35
+ frame.setAttribute('tabindex', '-1');
36
+ let done = false;
37
+ return () => {
38
+ if (done) return;
39
+ done = true;
40
+ if (--mine.holds > 0) return;
41
+ held.delete(frame);
42
+ if (mine.own === null) frame.removeAttribute('tabindex');
43
+ else frame.setAttribute('tabindex', mine.own);
44
+ };
45
+ }
46
+
47
+ /**
48
+ * Lets `frame`, which something holds out of the tab order, into it for a
49
+ * moment, until the function it returns is called or something takes it out
50
+ * again (a hold taken meanwhile): the user's next Tab can then take them into
51
+ * it, as a Tab into any frame in the tab order does. Then it is out, for as
52
+ * long as anything holds it, and as its host made it once nothing does. A
53
+ * frame nothing holds out is where its host put it, and is left so.
54
+ */
55
+ export function letIn (frame: Element): () => void {
56
+ const hold = held.get(frame);
57
+ if (!hold) return () => {};
58
+ const moment = {};
59
+ hold.open = moment;
60
+ frame.setAttribute('tabindex', '0');
61
+ return () => {
62
+ if (hold.open !== moment) return;
63
+ hold.open = undefined;
64
+ if (held.get(frame) === hold) frame.setAttribute('tabindex', '-1');
65
+ };
66
+ }
package/src/mount.ts CHANGED
@@ -19,7 +19,10 @@
19
19
  //
20
20
  // A tile that is put away is closed (Tile.close()): its frame goes, and the
21
21
  // origin it ran on is wiped. Shown again, it starts afresh, on another
22
- // origin. So this is for tiles whose state the host does not mean to keep.
22
+ // origin (or on the one its CID names, wiped). So this is for tiles whose
23
+ // state the host does not mean to keep, unless they run on an origin that is
24
+ // kept (a named one: see `tile.ephemeral`), where a tile shown again finds
25
+ // what it stored there.
23
26
  //
24
27
  // Starting a tile is the costly moment (its runtime spends the browser's
25
28
  // WebRTC budget first, where there is one), so tiles are also started a few