@fungi.computer/tourtois 0.20.14 → 0.20.15

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.
Files changed (2) hide show
  1. package/dist/layers.js +60 -2
  2. package/package.json +6 -6
package/dist/layers.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { OverlayRoot } from "@fungi.computer/caps/components/overlay-root";
3
3
  import { MaosaicoLayers, useLayer } from "@fungi.computer/maosaico";
4
- import { createContext, useContext, useMemo } from "react";
4
+ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, } from "react";
5
5
  function OverlayContainers({ children, subscribeDismiss, }) {
6
6
  const popover = useLayer("popover");
7
7
  const dialog = useLayer("dialog");
@@ -18,8 +18,62 @@ const DismissContext = createContext(() => undefined);
18
18
  export function useDismissOverlays() {
19
19
  return useContext(DismissContext);
20
20
  }
21
+ const windows = '[data-maosaico-layer="windows"]';
22
+ /**
23
+ * Whether focus landing in an App's frame is the person's doing. A click in a
24
+ * frame is invisible to this document except as the pointer resting on the
25
+ * frame (this document sees it enter the frame element, then nothing) or on
26
+ * a window, and Tab leaves a key press behind. An App that focuses itself while it loads has
27
+ * neither, so it must not close a menu the person just opened. The menu keeps
28
+ * the keyboard too: focus goes back to where it was in this document.
29
+ */
30
+ function usePersonDrivenFocus() {
31
+ const overFrame = useRef(false);
32
+ const tabbed = useRef(false);
33
+ const heldFocus = useRef(null);
34
+ useEffect(() => {
35
+ const pointer = (event) => {
36
+ overFrame.current =
37
+ event.target instanceof Element &&
38
+ event.target.closest(`iframe, ${windows}`) !== null;
39
+ tabbed.current = false;
40
+ };
41
+ const key = (event) => {
42
+ tabbed.current = event.key === "Tab";
43
+ };
44
+ const focused = (event) => {
45
+ if (event.target instanceof HTMLElement &&
46
+ event.target.closest(`iframe, ${windows}`) === null)
47
+ heldFocus.current = event.target;
48
+ };
49
+ document.addEventListener("pointerover", pointer, true);
50
+ document.addEventListener("pointerdown", pointer, true);
51
+ document.addEventListener("keydown", key, true);
52
+ document.addEventListener("focusin", focused, true);
53
+ return () => {
54
+ document.removeEventListener("pointerover", pointer, true);
55
+ document.removeEventListener("pointerdown", pointer, true);
56
+ document.removeEventListener("keydown", key, true);
57
+ document.removeEventListener("focusin", focused, true);
58
+ };
59
+ }, []);
60
+ return useCallback(() => {
61
+ const person = overFrame.current || tabbed.current;
62
+ tabbed.current = false;
63
+ if (!person) {
64
+ const held = heldFocus.current;
65
+ const menuOpen = document.querySelector('[data-maosaico-layer="popover"] [data-open]') !== null;
66
+ if (menuOpen && held?.isConnected === true)
67
+ queueMicrotask(() => {
68
+ held.focus({ preventScroll: true });
69
+ });
70
+ }
71
+ return person;
72
+ }, []);
73
+ }
21
74
  /** Tourtois composes Caps portal destinations with Maosaico's ordered roots. */
22
75
  export function TourtoisLayers({ children }) {
76
+ const personDriven = usePersonDrivenFocus();
23
77
  const dismissal = useMemo(() => {
24
78
  const listeners = new Set();
25
79
  return {
@@ -35,5 +89,9 @@ export function TourtoisLayers({ children }) {
35
89
  },
36
90
  };
37
91
  }, []);
38
- return (_jsx(MaosaicoLayers, { onDismiss: dismissal.dismiss, children: _jsx(DismissContext.Provider, { value: dismissal.dismiss, children: _jsx(OverlayContainers, { subscribeDismiss: dismissal.subscribe, children: children }) }) }));
92
+ const onDismiss = useCallback(() => {
93
+ if (personDriven())
94
+ dismissal.dismiss();
95
+ }, [personDriven, dismissal]);
96
+ return (_jsx(MaosaicoLayers, { onDismiss: onDismiss, children: _jsx(DismissContext.Provider, { value: dismissal.dismiss, children: _jsx(OverlayContainers, { subscribeDismiss: dismissal.subscribe, children: children }) }) }));
39
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/tourtois",
3
- "version": "0.20.14",
3
+ "version": "0.20.15",
4
4
  "author": "Levi <levi@technomancy.dev>",
5
5
  "description": "Tourtois: the trusted desktop shell for Oyster and Fungi, with host-supplied Settings sections",
6
6
  "type": "module",
@@ -77,15 +77,15 @@
77
77
  "LICENSE"
78
78
  ],
79
79
  "dependencies": {
80
- "@fungi.computer/agar": "0.18.0",
80
+ "@fungi.computer/agar": "0.18.1",
81
81
  "@fungi.computer/cairn": "0.1.0",
82
82
  "@fungi.computer/caps": "0.11.7",
83
83
  "@fungi.computer/ear-tag": "0.1.0",
84
84
  "@fungi.computer/gills": "0.3.0",
85
85
  "@fungi.computer/maosaico": "0.1.2",
86
- "@fungi.computer/parakeet": "0.12.0",
86
+ "@fungi.computer/parakeet": "0.12.1",
87
87
  "@fungi.computer/puffball": "0.9.0",
88
- "@fungi.computer/shiitake": "0.18.2",
88
+ "@fungi.computer/shiitake": "0.18.3",
89
89
  "@fungi.computer/sigils": "0.3.2",
90
90
  "@fungi.computer/sprite": "0.2.2",
91
91
  "@fungi.computer/sprite-zdog": "0.3.2",
@@ -100,13 +100,13 @@
100
100
  "lucide-react": "0.460.0",
101
101
  "react-dom": "18.3.1",
102
102
  "zod": "4.4.3",
103
- "@fungi.computer/nacre": "0.6.6"
103
+ "@fungi.computer/nacre": "0.6.7"
104
104
  },
105
105
  "peerDependencies": {
106
106
  "react": "^18.3.1 || ^19.2.0"
107
107
  },
108
108
  "devDependencies": {
109
- "@fungi.computer/oyster": "0.32.0",
109
+ "@fungi.computer/oyster": "0.33.0",
110
110
  "@cloudflare/workers-types": "5.20260828.1",
111
111
  "@fungi.computer/forage": "0.3.9",
112
112
  "@fungi.computer/mycelium": "0.4.0",