@hozo/behaviors 0.1.0 → 0.2.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # @hozo/behaviors
2
+
3
+ ## 0.2.0
4
+
5
+ - Add headless `usePresence` with `PresenceBinding` / `PresenceState` for shared exit lifecycles.
6
+ - Let FocusScope place its first focus into a panel mounted after the scope.
7
+ - Support application injection of the optional Android accessibility-focus mover; keep absence of the native module a supported fallback.
8
+
9
+ See the [Hozo release notes and migration steps](https://github.com/iray-tno/hozo/blob/main/CHANGELOG.md#020) for cross-package changes and measured boundaries.
@@ -0,0 +1,23 @@
1
+ import type { ComponentRef } from 'react';
2
+ import { type View } from 'react-native';
3
+ export type HozoFocusTarget = ComponentRef<typeof View>;
4
+ export type HozoFocusMover = (view: HozoFocusTarget) => void;
5
+ /**
6
+ * Hand over a better way to move accessibility focus, or `undefined` to stop.
7
+ *
8
+ * Idempotent and last-wins. Registering twice is a sign of two roots, which an
9
+ * application can legitimately have -- a test harness mounting its own -- and
10
+ * neither a throw nor a warning would help it.
11
+ */
12
+ export declare function setAccessibilityFocusMover(mover: HozoFocusMover | undefined | null): void;
13
+ /** Whether something has been registered. Read by diagnostics, not by behaviour. */
14
+ export declare function hasAccessibilityFocusMover(): boolean;
15
+ /**
16
+ * Put accessibility focus on `view`.
17
+ *
18
+ * Read at call time rather than captured, because registration happens during the
19
+ * application's startup and a module that captured the default at load would
20
+ * never see it.
21
+ */
22
+ export declare function moveAccessibilityFocus(view: HozoFocusTarget): void;
23
+ //# sourceMappingURL=accessibility-focus.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accessibility-focus.native.d.ts","sourceRoot":"","sources":["../src/accessibility-focus.native.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AACzC,OAAO,EAAqB,KAAK,IAAI,EAAE,MAAM,cAAc,CAAA;AAE3D,MAAM,MAAM,eAAe,GAAG,YAAY,CAAC,OAAO,IAAI,CAAC,CAAA;AACvD,MAAM,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,CAAA;AAsD5D;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,GAAG,IAAI,GAAG,IAAI,CAEzF;AAED,oFAAoF;AACpF,wBAAgB,0BAA0B,IAAI,OAAO,CAEpD;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAMlE"}
@@ -0,0 +1,81 @@
1
+ import { AccessibilityInfo } from 'react-native';
2
+ /**
3
+ * Moving accessibility focus, with `@hozo/native` able to take over.
4
+ *
5
+ * ## Registered, not resolved, and that is a correction
6
+ *
7
+ * `docs/decisions/006-shipping-native-code.md` says the capability is reached
8
+ * "through a resolved provider, never imported", pointing at
9
+ * `packages/engine/src/safe-area.native.ts:50`, which does
10
+ * `try { require('react-native-safe-area-context') } catch {}`. That shape does
11
+ * not transfer here, and the reason is Metro rather than taste.
12
+ *
13
+ * Metro resolves `require` at bundle time. A literal `require` of a package that
14
+ * is not installed is a **build failure**, `try`/`catch` or not -- the catch runs
15
+ * at runtime and the bundler never gets there. Safe areas get away with it
16
+ * because that module is only in the graph when the compiler emitted a safe-area
17
+ * class: a project that writes none never imports it. This module is in the graph
18
+ * of every application that renders a `Dialog`, so a `require` here would make an
19
+ * optional package mandatory, and would break every existing app on upgrade.
20
+ *
21
+ * So the application hands the capability in, in two lines next to wherever it
22
+ * registers its root component:
23
+ *
24
+ * ```ts
25
+ * import { setAccessibilityFocusMover } from '@hozo/behaviors/native'
26
+ * import { moveAccessibilityFocus } from '@hozo/native'
27
+ *
28
+ * setAccessibilityFocusMover(moveAccessibilityFocus)
29
+ * ```
30
+ *
31
+ * `moveAccessibilityFocus` is `undefined` on iOS and when the native module is
32
+ * not in the binary, and the setter accepts that and keeps the default -- so the
33
+ * call needs no condition around it.
34
+ *
35
+ * ## The default is what this library has always done
36
+ *
37
+ * `AccessibilityInfo.sendAccessibilityEvent(view, 'focus')`, which works about
38
+ * half the time on Android (#484). An application that registers nothing is
39
+ * exactly as well off as it was, which is the third part of the decision's gate
40
+ * and the reason the capability was admitted at all.
41
+ *
42
+ * ## Why this is in `@hozo/behaviors/native`
43
+ *
44
+ * It has one consumer today -- `Dialog` -- and the first draft of this lived in
45
+ * `@hozo/patterns` for that reason. Registration moved it: a module holding one
46
+ * mutable binding costs nothing to load, where a provider resolution would have
47
+ * run a `require` in every package that imported it, and the application doing
48
+ * the registering should not have to reach into a widget package to do it.
49
+ * `@hozo/behaviors/native` is the entry point that already exists for API with no
50
+ * Web counterpart.
51
+ */
52
+ let registered;
53
+ /**
54
+ * Hand over a better way to move accessibility focus, or `undefined` to stop.
55
+ *
56
+ * Idempotent and last-wins. Registering twice is a sign of two roots, which an
57
+ * application can legitimately have -- a test harness mounting its own -- and
58
+ * neither a throw nor a warning would help it.
59
+ */
60
+ export function setAccessibilityFocusMover(mover) {
61
+ registered = mover ?? undefined;
62
+ }
63
+ /** Whether something has been registered. Read by diagnostics, not by behaviour. */
64
+ export function hasAccessibilityFocusMover() {
65
+ return registered !== undefined;
66
+ }
67
+ /**
68
+ * Put accessibility focus on `view`.
69
+ *
70
+ * Read at call time rather than captured, because registration happens during the
71
+ * application's startup and a module that captured the default at load would
72
+ * never see it.
73
+ */
74
+ export function moveAccessibilityFocus(view) {
75
+ if (registered) {
76
+ registered(view);
77
+ return;
78
+ }
79
+ AccessibilityInfo.sendAccessibilityEvent(view, 'focus');
80
+ }
81
+ //# sourceMappingURL=accessibility-focus.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accessibility-focus.native.js","sourceRoot":"","sources":["../src/accessibility-focus.native.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAa,MAAM,cAAc,CAAA;AAK3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,IAAI,UAAsC,CAAA;AAE1C;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CAAC,KAAwC;IACjF,UAAU,GAAG,KAAK,IAAI,SAAS,CAAA;AACjC,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,0BAA0B;IACxC,OAAO,UAAU,KAAK,SAAS,CAAA;AACjC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAAqB;IAC1D,IAAI,UAAU,EAAE,CAAC;QACf,UAAU,CAAC,IAAI,CAAC,CAAA;QAChB,OAAM;IACR,CAAC;IACD,iBAAiB,CAAC,sBAAsB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;AACzD,CAAC"}
@@ -20,6 +20,14 @@ export interface FocusScopeProps {
20
20
  trapped?: boolean;
21
21
  autoFocus?: boolean;
22
22
  restoreFocus?: boolean;
23
+ /**
24
+ * Whether the scope holds focus. Turning it false does what unmounting
25
+ * does -- the trap is released and focus goes back to the opener -- for
26
+ * an overlay that stays mounted while it animates out (decision 007).
27
+ * Focus left inside a panel that is fading away would be on something
28
+ * nobody can use, and on nothing once the panel goes.
29
+ */
30
+ active?: boolean;
23
31
  className?: string;
24
32
  style?: CSSProperties;
25
33
  }
@@ -27,5 +35,5 @@ export interface FocusScopeProps {
27
35
  * Universal `<FocusScope>` component for Web.
28
36
  * Traps Tab key navigation, moves initial focus, and safely restores focus on unmount.
29
37
  */
30
- export declare function FocusScope({ children, trapped, autoFocus, restoreFocus, className, style, }: FocusScopeProps): import("react").JSX.Element;
38
+ export declare function FocusScope({ children, trapped, autoFocus, restoreFocus, active, className, style, }: FocusScopeProps): import("react").JSX.Element;
31
39
  //# sourceMappingURL=focus-scope.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"focus-scope.d.ts","sourceRoot":"","sources":["../src/focus-scope.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KA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e;IAC9B,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,aAAa,CAAA;CACtB;AAaD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,EACzB,QAAQ,EACR,OAAc,EACd,SAAgB,EAChB,YAAmB,EACnB,MAAa,EACb,SAAS,EACT,KAAK,GACN,EAAE,eAAe,+BAmHjB"}
@@ -21,16 +21,25 @@ export function shouldRestoreFocus(opener) {
21
21
  return opener?.focusable === true;
22
22
  }
23
23
  const FOCUSABLE_SELECTOR = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
24
+ /**
25
+ * How long to keep trying to move focus in: ten tries a frame's length
26
+ * apart. A container hidden until it is measured shows by the first or
27
+ * second; ten is a bound, not a guess at a delay.
28
+ */
29
+ const INITIAL_FOCUS_ATTEMPTS = 10;
30
+ const INITIAL_FOCUS_INTERVAL_MS = 16;
24
31
  /**
25
32
  * Universal `<FocusScope>` component for Web.
26
33
  * Traps Tab key navigation, moves initial focus, and safely restores focus on unmount.
27
34
  */
28
- export function FocusScope({ children, trapped = true, autoFocus = true, restoreFocus = true, className, style, }) {
35
+ export function FocusScope({ children, trapped = true, autoFocus = true, restoreFocus = true, active = true, className, style, }) {
29
36
  const containerRef = useRef(null);
30
37
  const openerRef = useRef(null);
31
38
  useEffect(() => {
32
39
  if (typeof document === 'undefined')
33
40
  return;
41
+ if (!active)
42
+ return;
34
43
  // Capture the trigger element that opened this scope
35
44
  if (restoreFocus && document.activeElement instanceof HTMLElement) {
36
45
  openerRef.current = document.activeElement;
@@ -38,21 +47,43 @@ export function FocusScope({ children, trapped = true, autoFocus = true, restore
38
47
  const container = containerRef.current;
39
48
  if (!container)
40
49
  return;
41
- if (autoFocus) {
50
+ // Where focus goes on the way in: the first candidate, or the container
51
+ // itself (tabIndex="-1") so a screen reader still announces the role and
52
+ // name.
53
+ const initialTarget = () => {
42
54
  const focusables = Array.from(container.querySelectorAll(FOCUSABLE_SELECTOR)).filter((el) => el.offsetParent !== null || el.getClientRects().length > 0);
43
55
  const candidates = focusables.map((el) => ({
44
56
  autofocus: el.hasAttribute('autofocus'),
45
57
  focusable: !el.hasAttribute('disabled') && el.tabIndex !== -1,
46
58
  }));
47
59
  const targetIdx = initialFocusIndex(candidates);
48
- if (targetIdx !== null && focusables[targetIdx]) {
49
- focusables[targetIdx].focus();
50
- }
51
- else {
52
- // Fallback: focus container itself (tabIndex="-1") so screen readers announce dialog role/label
53
- container.focus();
54
- }
55
- }
60
+ return (targetIdx !== null && focusables[targetIdx]) || container;
61
+ };
62
+ // `focus()` on an element that cannot take focus yet does nothing, and
63
+ // says nothing. `FloatingPositioner` is the case that found it: it draws
64
+ // its content `visibility: hidden` until it has measured, in an effect
65
+ // that runs after this one, so a popover's first focus landed on nothing
66
+ // and stayed on the trigger. Trying again shortly after covers that and
67
+ // any container like it -- but only while focus is still where the scope
68
+ // found it, so a person who has moved on is not pulled back. A timer
69
+ // rather than an animation frame: `focus()` resolves style itself, so it
70
+ // needs the positioner to have rendered, not the page to have painted --
71
+ // and frames do not run at all in a tab that is not being drawn.
72
+ let retry;
73
+ const moveIn = (attempt) => {
74
+ const target = initialTarget();
75
+ target.focus();
76
+ if (document.activeElement === target || attempt >= INITIAL_FOCUS_ATTEMPTS)
77
+ return;
78
+ const stillWaiting = document.activeElement === openerRef.current ||
79
+ document.activeElement === document.body ||
80
+ document.activeElement === null;
81
+ if (!stillWaiting)
82
+ return;
83
+ retry = setTimeout(() => moveIn(attempt + 1), INITIAL_FOCUS_INTERVAL_MS);
84
+ };
85
+ if (autoFocus)
86
+ moveIn(0);
56
87
  const handleKeyDown = (event) => {
57
88
  if (!trapped || event.key !== 'Tab')
58
89
  return;
@@ -79,6 +110,7 @@ export function FocusScope({ children, trapped = true, autoFocus = true, restore
79
110
  };
80
111
  container.addEventListener('keydown', handleKeyDown);
81
112
  return () => {
113
+ clearTimeout(retry);
82
114
  container.removeEventListener('keydown', handleKeyDown);
83
115
  if (restoreFocus) {
84
116
  const opener = openerRef.current;
@@ -90,7 +122,7 @@ export function FocusScope({ children, trapped = true, autoFocus = true, restore
90
122
  }
91
123
  }
92
124
  };
93
- }, [trapped, autoFocus, restoreFocus]);
125
+ }, [trapped, autoFocus, restoreFocus, active]);
94
126
  return (_jsx("div", { ref: containerRef, tabIndex: -1, className: className, style: { outline: 'none', ...style }, children: children }));
95
127
  }
96
128
  //# sourceMappingURL=focus-scope.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"focus-scope.js","sourceRoot":"","sources":["../src/focus-scope.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAsC,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAO7E;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAqC;IACrE,MAAM,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,SAAS,CAAC,CAAA;IACzE,IAAI,SAAS,KAAK,CAAC,CAAC;QAAE,OAAO,SAAS,CAAA;IACtC,MAAM,KAAK,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IACtD,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAA;AACpC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAyC;IAC1E,OAAO,MAAM,EAAE,SAAS,KAAK,IAAI,CAAA;AACnC,CAAC;AAWD,MAAM,kBA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GAAG,EAAE;YACV,YAAY,CAAC,KAAK,CAAC,CAAA;YACnB,SAAS,CAAC,mBAAmB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;YACvD,IAAI,YAAY,EAAE,CAAC;gBACjB,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAA;gBAChC,IACE,MAAM;oBACN,kBAAkB,CAAC;wBACjB,SAAS,EAAE,MAAM,CAAC,WAAW,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC;qBAClE,CAAC,EACF,CAAC;oBACD,MAAM,CAAC,KAAK,EAAE,CAAA;gBAChB,CAAC;YACH,CAAC;QACH,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC,CAAA;IAE9C,OAAO,CACL,cACE,GAAG,EAAE,YAAY,EACjB,QAAQ,EAAE,CAAC,CAAC,EACZ,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,YAEnC,QAAQ,GACL,CACP,CAAA;AACH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export { computeSafePolygon, type DelayGroupConfig, DelayGroupMachine, isPointIn
6
6
  export { type ContentProps, TooltipGroupProvider, type TooltipGroupProviderProps, type TriggerProps, type UseHoverTriggerOptions, type UseHoverTriggerReturn, useHoverTrigger, useTooltipGroup, } from './hover-trigger.tsx';
7
7
  export { LiveRegion, type LiveRegionMode, type LiveRegionProps, useAnnounce, } from './live-region.tsx';
8
8
  export { Portal, PortalHost, type PortalProps, PortalProvider, } from './portal.tsx';
9
+ export { type PresenceBinding, type PresenceState, usePresence, } from './presence.ts';
9
10
  export { nextIndex, type Orientation, RovingFocusGroup, type RovingFocusGroupProps, type RovingKey, type RovingOptions, tabStops, useRovingItem, } from './roving-focus.tsx';
10
11
  export { hozoTextChildren } from './text-child.ts';
11
12
  export { isTypeaheadKey, nextSearch, searchIndex, TYPEAHEAD_TIMEOUT_MS, type TypeaheadOptions, useTypeahead, } from './typeahead.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,KAAK,qBAAqB,GAC3B,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACL,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAC3B,eAAe,EACf,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,cAAc,EACd,KAAK,IAAI,EACT,KAAK,QAAQ,GACd,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,KAAK,0BAA0B,EAC/B,mBAAmB,GACpB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EACL,KAAK,cAAc,EACnB,UAAU,EACV,KAAK,eAAe,EACpB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,kBAAkB,EAClB,KAAK,gBAAgB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,KAAK,EACV,KAAK,OAAO,GACb,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACL,KAAK,YAAY,EACjB,oBAAoB,EACpB,KAAK,yBAAyB,EAC9B,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,eAAe,EACf,eAAe,GAChB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACL,UAAU,EACV,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,WAAW,GACZ,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,MAAM,EACN,UAAU,EACV,KAAK,WAAW,EAChB,cAAc,GACf,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,SAAS,EACT,KAAK,WAAW,EAChB,gBAAgB,EAChB,KAAK,qBAAqB,EAC1B,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,QAAQ,EACR,aAAa,GACd,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EACL,cAAc,EACd,UAAU,EACV,WAAW,EACX,oBAAoB,EACpB,KAAK,gBAAgB,EACrB,YAAY,GACb,MAAM,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,KAAK,qBAAqB,GAC3B,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACL,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAC3B,eAAe,EACf,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,cAAc,EACd,KAAK,IAAI,EACT,KAAK,QAAQ,GACd,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,KAAK,0BAA0B,EAC/B,mBAAmB,GACpB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EACL,KAAK,cAAc,EACnB,UAAU,EACV,KAAK,eAAe,EACpB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,kBAAkB,EAClB,KAAK,gBAAgB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,KAAK,EACV,KAAK,OAAO,GACb,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACL,KAAK,YAAY,EACjB,oBAAoB,EACpB,KAAK,yBAAyB,EAC9B,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,eAAe,EACf,eAAe,GAChB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACL,UAAU,EACV,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,WAAW,GACZ,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,MAAM,EACN,UAAU,EACV,KAAK,WAAW,EAChB,cAAc,GACf,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,WAAW,GACZ,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,SAAS,EACT,KAAK,WAAW,EAChB,gBAAgB,EAChB,KAAK,qBAAqB,EAC1B,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,QAAQ,EACR,aAAa,GACd,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EACL,cAAc,EACd,UAAU,EACV,WAAW,EACX,oBAAoB,EACpB,KAAK,gBAAgB,EACrB,YAAY,GACb,MAAM,gBAAgB,CAAA"}
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ export { computeSafePolygon, DelayGroupMachine, isPointInPolygon, } from './hove
6
6
  export { TooltipGroupProvider, useHoverTrigger, useTooltipGroup, } from './hover-trigger.js';
7
7
  export { LiveRegion, useAnnounce, } from './live-region.js';
8
8
  export { Portal, PortalHost, PortalProvider, } from './portal.js';
9
+ export { usePresence, } from './presence.js';
9
10
  export { nextIndex, RovingFocusGroup, tabStops, useRovingItem, } from './roving-focus.js';
10
11
  export { hozoTextChildren } from './text-child.js';
11
12
  export { isTypeaheadKey, nextSearch, searchIndex, TYPEAHEAD_TIMEOUT_MS, useTypeahead, } from './typeahead.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,GAEjB,MAAM,wBAAyB,CAAA;AAChC,OAAO,EAIL,eAAe,EAGf,cAAc,GAGf,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,kBAAkB,EAGlB,mBAAmB,GACpB,MAAM,0BAA2B,CAAA;AAClC,OAAO,EAEL,UAAU,EAEV,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,kBAAmB,CAAA;AAC1B,OA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,QAAQ,EACR,aAAa,GACd,MAAM,mBAAoB,CAAA;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EACL,cAAc,EACd,UAAU,EACV,WAAW,EACX,oBAAoB,EAEpB,YAAY,GACb,MAAM,gBAAgB,CAAA"}
@@ -6,6 +6,7 @@ export { computeSafePolygon, type DelayGroupConfig, DelayGroupMachine, isPointIn
6
6
  export { type NativeContentProps as ContentProps, type NativeTriggerProps as TriggerProps, TooltipGroupProvider, type TooltipGroupProviderProps, type UseHoverTriggerOptions, type UseHoverTriggerReturn, useHoverTrigger, useTooltipGroup, } from './hover-trigger.native.tsx';
7
7
  export { LiveRegion, type LiveRegionMode, type LiveRegionProps, useAnnounce, } from './live-region.native.tsx';
8
8
  export { Portal, PortalHost, type PortalProps, PortalProvider, } from './portal.native.tsx';
9
+ export { type PresenceBinding, type PresenceState, usePresence } from './presence.native.ts';
9
10
  export { nextIndex, type Orientation, RovingFocusGroup, type RovingFocusGroupProps, type RovingKey, type RovingOptions, tabStops, useRovingItem, } from './roving-focus.native.tsx';
10
11
  export { hozoTextChildren } from './text-child.native.tsx';
11
12
  export { isTypeaheadKey, nextSearch, searchIndex, TYPEAHEAD_TIMEOUT_MS, type TypeaheadOptions, useTypeahead, } from './typeahead.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.native.d.ts","sourceRoot":"","sources":["../src/index.native.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,KAAK,qBAAqB,GAC3B,MAAM,gCAAgC,CAAA;AACvC,OAAO,EACL,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAC3B,eAAe,EACf,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,cAAc,EACd,KAAK,IAAI,EACT,KAAK,QAAQ,GACd,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,KAAK,0BAA0B,EAC/B,mBAAmB,GACpB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EACL,KAAK,cAAc,EACnB,UAAU,EACV,KAAK,eAAe,EACpB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACL,kBAAkB,EAClB,KAAK,gBAAgB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,KAAK,EACV,KAAK,OAAO,GACb,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACL,KAAK,kBAAkB,IAAI,YAAY,EACvC,KAAK,kBAAkB,IAAI,YAAY,EACvC,oBAAoB,EACpB,KAAK,yBAAyB,EAC9B,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,eAAe,EACf,eAAe,GAChB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACL,UAAU,EACV,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,WAAW,GACZ,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACL,MAAM,EACN,UAAU,EACV,KAAK,WAAW,EAChB,cAAc,GACf,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACL,SAAS,EACT,KAAK,WAAW,EAChB,gBAAgB,EAChB,KAAK,qBAAqB,EAC1B,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,QAAQ,EACR,aAAa,GACd,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EACL,cAAc,EACd,UAAU,EACV,WAAW,EACX,oBAAoB,EACpB,KAAK,gBAAgB,EACrB,YAAY,GACb,MAAM,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.native.d.ts","sourceRoot":"","sources":["../src/index.native.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,KAAK,qBAAqB,GAC3B,MAAM,gCAAgC,CAAA;AACvC,OAAO,EACL,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAC3B,eAAe,EACf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EACrB,YAAY,GACb,MAAM,gBAAgB,CAAA"}
@@ -6,6 +6,7 @@ export { computeSafePolygon, DelayGroupMachine, isPointInPolygon, } from './hove
6
6
  export { TooltipGroupProvider, useHoverTrigger, useTooltipGroup, } from './hover-trigger.native.js';
7
7
  export { LiveRegion, useAnnounce, } from './live-region.native.js';
8
8
  export { Portal, PortalHost, PortalProvider, } from './portal.native.js';
9
+ export { usePresence } from './presence.native.js';
9
10
  export { nextIndex, RovingFocusGroup, tabStops, useRovingItem, } from './roving-focus.native.js';
10
11
  export { hozoTextChildren } from './text-child.native.js';
11
12
  export { isTypeaheadKey, nextSearch, searchIndex, TYPEAHEAD_TIMEOUT_MS, useTypeahead, } from './typeahead.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.native.js","sourceRoot":"","sources":["../src/index.native.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,GAEjB,MAAM,+BAAgC,CAAA;AACvC,OAAO,EAIL,eAAe,EAGf,cAAc,GAGf,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,kBAAkB,EAGlB,mBAAmB,GACpB,MAAM,iCAAkC,CAAA;AACzC,OAAO,EAEL,UAAU,EAEV,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,yBAA0B,CAAA;AACjC,OAAO,EACL,kBAAkB,EAElB,iBAAiB,EACjB,gBAAgB,GAGjB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAGL,oBAAoB,EAIpB,eAAe,EACf,eAAe,GAChB,MAAM,2BAA4B,CAAA;AACnC,OAAO,EACL,UAAU,EAGV,WAAW,GACZ,MAAM,yBAA0B,CAAA;AACjC,OAAO,EACL,MAAM,EACN,UAAU,EAEV,cAAc,GACf,MAAM,oBAAqB,CAAA;AAC5B,OAAO,EACL,SAAS,EAET,gBAAgB,EAIhB,QAAQ,EACR,aAAa,GACd,MAAM,0BAA2B,CAAA;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAyB,CAAA;AAC1D,OAAO,EACL,cAAc,EACd,UAAU,EACV,WAAW,EACX,oBAAoB,EAEpB,YAAY,GACb,MAAM,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.native.js","sourceRoot":"","sources":["../src/index.native.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,GAEjB,MAAM,+BAAgC,CAAA;AACvC,OAAO,EAIL,eAAe,EAGf,cAAc,GAGf,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,kBAAkB,EAGlB,mBAAmB,GACpB,MAAM,iCAAkC,CAAA;AACzC,OAAO,EAEL,UAAU,EAEV,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,yBAA0B,CAAA;AACjC,OAAO,EACL,kBAAkB,EAElB,iBAAiB,EACjB,gBAAgB,GAGjB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAGL,oBAAoB,EAIpB,eAAe,EACf,eAAe,GAChB,MAAM,2BAA4B,CAAA;AACnC,OAAO,EACL,UAAU,EAGV,WAAW,GACZ,MAAM,yBAA0B,CAAA;AACjC,OAAO,EACL,MAAM,EACN,UAAU,EAEV,cAAc,GACf,MAAM,oBAAqB,CAAA;AAC5B,OAAO,EAA4C,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAC5F,OAAO,EACL,SAAS,EAET,gBAAgB,EAIhB,QAAQ,EACR,aAAa,GACd,MAAM,0BAA2B,CAAA;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAyB,CAAA;AAC1D,OAAO,EACL,cAAc,EACd,UAAU,EACV,WAAW,EACX,oBAAoB,EAEpB,YAAY,GACb,MAAM,gBAAgB,CAAA"}
package/dist/native.d.ts CHANGED
@@ -1,5 +1,7 @@
1
+ export { type HozoFocusMover, type HozoFocusTarget, hasAccessibilityFocusMover, moveAccessibilityFocus, setAccessibilityFocusMover, } from './accessibility-focus.native.ts';
1
2
  export type { Placement } from './floating-geometry.ts';
2
3
  export { FloatingPositioner, type FloatingPositionerProps, type UseFloatingPositionOptions, useFloatingPosition, } from './floating-positioner.native.tsx';
3
4
  export { type NativeContentProps, type NativeTriggerProps, type UseHoverTriggerOptions, type UseHoverTriggerReturn, useHoverTrigger, } from './hover-trigger.native.tsx';
4
5
  export { Portal, PortalHost, type PortalProps, PortalProvider } from './portal.native.tsx';
6
+ export { type PresenceBinding, type PresenceState, usePresence } from './presence.native.ts';
5
7
  //# sourceMappingURL=native.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AACvD,OAAO,EACL,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,KAAK,0BAA0B,EAC/B,mBAAmB,GACpB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,eAAe,GAChB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,WAAW,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA"}
1
+ {"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,0BAA0B,EAC1B,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,iCAAiC,CAAA;AACxC,YAAY,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AACvD,OAAO,EACL,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,KAAK,0BAA0B,EAC/B,mBAAmB,GACpB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,eAAe,GAChB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,WAAW,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAC1F,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,aAAa,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA"}
package/dist/native.js CHANGED
@@ -1,4 +1,6 @@
1
+ export { hasAccessibilityFocusMover, moveAccessibilityFocus, setAccessibilityFocusMover, } from './accessibility-focus.native.js';
1
2
  export { FloatingPositioner, useFloatingPosition, } from './floating-positioner.native.js';
2
3
  export { useHoverTrigger, } from './hover-trigger.native.js';
3
4
  export { Portal, PortalHost, PortalProvider } from './portal.native.js';
5
+ export { usePresence } from './presence.native.js';
4
6
  //# sourceMappingURL=native.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"native.js","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAGlB,mBAAmB,GACpB,MAAM,iCAAkC,CAAA;AACzC,OAAO,EAKL,eAAe,GAChB,MAAM,2BAA4B,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAoB,cAAc,EAAE,MAAM,oBAAqB,CAAA"}
1
+ {"version":3,"file":"native.js","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,0BAA0B,EAC1B,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,iCAAiC,CAAA;AAExC,OAAO,EACL,kBAAkB,EAGlB,mBAAmB,GACpB,MAAM,iCAAkC,CAAA;AACzC,OAAO,EAKL,eAAe,GAChB,MAAM,2BAA4B,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAoB,cAAc,EAAE,MAAM,oBAAqB,CAAA;AAC1F,OAAO,EAA4C,WAAW,EAAE,MAAM,sBAAsB,CAAA"}
@@ -0,0 +1,19 @@
1
+ export type PresenceState = 'open' | 'closed';
2
+ export interface PresenceBinding {
3
+ /** Whether to render the element at all. */
4
+ mounted: boolean;
5
+ /** For the element's `data-state`. */
6
+ state: PresenceState;
7
+ /** The element whose transition is the exit. */
8
+ ref: (node: Element | null) => void;
9
+ onTransitionEnd: (event: {
10
+ target: EventTarget;
11
+ currentTarget: EventTarget;
12
+ }) => void;
13
+ onAnimationEnd: (event: {
14
+ target: EventTarget;
15
+ currentTarget: EventTarget;
16
+ }) => void;
17
+ }
18
+ export declare function usePresence(show: boolean): PresenceBinding;
19
+ //# sourceMappingURL=presence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presence.d.ts","sourceRoot":"","sources":["../src/presence.ts"],"names":[],"mappings":"AAiBA,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,QAAQ,CAAA;AAE7C,MAAM,WAAW,eAAe;IAC9B,4CAA4C;IAC5C,OAAO,EAAE,OAAO,CAAA;IAChB,sCAAsC;IACtC,KAAK,EAAE,aAAa,CAAA;IACpB,gDAAgD;IAChD,GAAG,EAAE,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,KAAK,IAAI,CAAA;IACnC,eAAe,EAAE,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,WAAW,CAAC;QAAC,aAAa,EAAE,WAAW,CAAA;KAAE,KAAK,IAAI,CAAA;IACrF,cAAc,EAAE,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,WAAW,CAAC;QAAC,aAAa,EAAE,WAAW,CAAA;KAAE,KAAK,IAAI,CAAA;CACrF;AAgCD,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,eAAe,CAyD1D"}
@@ -0,0 +1,96 @@
1
+ // Keeping an element mounted while it animates out, on the Web
2
+ // (decision 007, slice 2).
3
+ //
4
+ // React removes an element the moment it stops being rendered, so nothing
5
+ // can animate after that. This holds on to it after `show` turns false,
6
+ // reports `state: 'closed'` for the caller to put on the element as
7
+ // `data-state`, and lets it go when the element's transition or animation
8
+ // ends. The exit itself is CSS -- a `data-[state=closed]:` class and a
9
+ // `transition-*` one -- so it costs no script beyond this.
10
+ //
11
+ // A hook rather than only a component because Hozo's overlays cannot wrap
12
+ // their panel in one: the panel sits inside a positioner, a dismiss layer
13
+ // and a focus scope, and it is the panel that leaves. `Presence` in
14
+ // `@hozo/primitives` is this hook around one child.
15
+ import { useCallback, useEffect, useRef, useState } from 'react';
16
+ /** How long past the computed end to wait for an event that never fires. */
17
+ const GRACE_MS = 100;
18
+ /** The longest `duration + delay` across a comma-separated pair of lists. */
19
+ function longest(durations, delays) {
20
+ const ms = (value) => {
21
+ const number = Number.parseFloat(value);
22
+ if (Number.isNaN(number))
23
+ return 0;
24
+ return value.trim().endsWith('ms') ? number : number * 1000;
25
+ };
26
+ const d = durations.split(',');
27
+ const l = delays.split(',');
28
+ // CSS repeats the shorter list to the length of the longer one.
29
+ const length = Math.max(d.length, l.length);
30
+ let out = 0;
31
+ for (let i = 0; i < length; i++) {
32
+ out = Math.max(out, ms(d[i % d.length] ?? '0s') + ms(l[i % l.length] ?? '0s'));
33
+ }
34
+ return out;
35
+ }
36
+ /** How long the element's exit runs, from its computed style. */
37
+ function exitDuration(element) {
38
+ const style = getComputedStyle(element);
39
+ return Math.max(longest(style.transitionDuration, style.transitionDelay), style.animationName === 'none' ? 0 : longest(style.animationDuration, style.animationDelay));
40
+ }
41
+ export function usePresence(show) {
42
+ const [mounted, setMounted] = useState(show);
43
+ // Set during render rather than in an effect, so an element that is shown
44
+ // again appears in the same commit instead of one frame late.
45
+ if (show && !mounted)
46
+ setMounted(true);
47
+ const element = useRef(null);
48
+ const ending = useRef(null);
49
+ const finish = useCallback(() => {
50
+ if (ending.current)
51
+ clearTimeout(ending.current.timer);
52
+ ending.current = null;
53
+ setMounted(false);
54
+ }, []);
55
+ useEffect(() => {
56
+ if (show || !mounted)
57
+ return;
58
+ // Read after the commit that set `data-state="closed"`, so the
59
+ // computed style is the one the element is leaving with -- including
60
+ // `motion-reduce:transition-none`, which makes this zero.
61
+ const target = element.current;
62
+ const duration = target ? exitDuration(target) : 0;
63
+ if (duration === 0) {
64
+ finish();
65
+ return;
66
+ }
67
+ const at = performance.now() + duration;
68
+ ending.current = { at, timer: setTimeout(finish, duration + GRACE_MS) };
69
+ return () => {
70
+ if (ending.current)
71
+ clearTimeout(ending.current.timer);
72
+ ending.current = null;
73
+ };
74
+ }, [show, mounted, finish]);
75
+ // `transitionend` fires once per property, and the properties may end
76
+ // at different times. Only the one that ends last finishes the exit.
77
+ const onEnd = useCallback((event) => {
78
+ if (event.target !== event.currentTarget)
79
+ return;
80
+ const pending = ending.current;
81
+ if (!pending || performance.now() < pending.at - 20)
82
+ return;
83
+ finish();
84
+ }, [finish]);
85
+ const ref = useCallback((node) => {
86
+ element.current = node;
87
+ }, []);
88
+ return {
89
+ mounted,
90
+ state: show ? 'open' : 'closed',
91
+ ref,
92
+ onTransitionEnd: onEnd,
93
+ onAnimationEnd: onEnd,
94
+ };
95
+ }
96
+ //# sourceMappingURL=presence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presence.js","sourceRoot":"","sources":["../src/presence.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,2BAA2B;AAC3B,EAAE;AACF,0EAA0E;AAC1E,wEAAwE;AACxE,oEAAoE;AACpE,0EAA0E;AAC1E,uEAAuE;AACvE,2DAA2D;AAC3D,EAAE;AACF,0EAA0E;AAC1E,0EAA0E;AAC1E,oEAAoE;AACpE,oDAAoD;AAEpD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAehE,4EAA4E;AAC5E,MAAM,QAAQ,GAAG,GAAG,CAAA;AAEpB,6EAA6E;AAC7E,SAAS,OAAO,CAAC,SAAiB,EAAE,MAAc;IAChD,MAAM,EAAE,GAAG,CAAC,KAAa,EAAE,EAAE;QAC3B,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;QACvC,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;YAAE,OAAO,CAAC,CAAA;QAClC,OAAO,KAAK,CAAC,IAAI,EA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AE,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAA;IAE3B,sEAAsE;IACtE,qEAAqE;IACrE,MAAM,KAAK,GAAG,WAAW,CACvB,CAAC,KAA0D,EAAE,EAAE;QAC7D,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,aAAa;YAAE,OAAM;QAChD,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAA;QAC9B,IAAI,CAAC,OAAO,IAAI,WAAW,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,EAAE,GAAG,EAAE;YAAE,OAAM;QAC3D,MAAM,EAAE,CAAA;IACV,CAAC,EACD,CAAC,MAAM,CAAC,CACT,CAAA;IAED,MAAM,GAAG,GAAG,WAAW,CAAC,CAAC,IAAoB,EAAE,EAAE;QAC/C,OAAO,CAAC,OAAO,GAAG,IAAI,CAAA;IACxB,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO;QACL,OAAO;QACP,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ;QAC/B,GAAG;QACH,eAAe,EAAE,KAAK;QACtB,cAAc,EAAE,KAAK;KACtB,CAAA;AACH,CAAC"}
@@ -0,0 +1,10 @@
1
+ export type PresenceState = 'open' | 'closed';
2
+ export interface PresenceBinding {
3
+ /** Whether to render the element at all. */
4
+ mounted: boolean;
5
+ state: PresenceState;
6
+ /** Ends the exit. Ignored once the element is shown again. */
7
+ done: () => void;
8
+ }
9
+ export declare function usePresence(show: boolean): PresenceBinding;
10
+ //# sourceMappingURL=presence.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presence.native.d.ts","sourceRoot":"","sources":["../src/presence.native.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,QAAQ,CAAA;AAE7C,MAAM,WAAW,eAAe;IAC9B,4CAA4C;IAC5C,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,aAAa,CAAA;IACpB,8DAA8D;IAC9D,IAAI,EAAE,MAAM,IAAI,CAAA;CACjB;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,eAAe,CAO1D"}
@@ -0,0 +1,18 @@
1
+ // Keeping an element mounted while it animates out, on React Native
2
+ // (decision 007, slice 2). The Web half is `./presence.ts`.
3
+ //
4
+ // There is no computed style to read an exit's length from here, so the
5
+ // caller says when it is over: it runs its own `Animated` exit while
6
+ // `state` is `'closed'` and calls `done` from the completion callback.
7
+ import { useCallback, useState } from 'react';
8
+ export function usePresence(show) {
9
+ const [mounted, setMounted] = useState(show);
10
+ if (show && !mounted)
11
+ setMounted(true);
12
+ const done = useCallback(() => {
13
+ if (!show)
14
+ setMounted(false);
15
+ }, [show]);
16
+ return { mounted, state: show ? 'open' : 'closed', done };
17
+ }
18
+ //# sourceMappingURL=presence.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presence.native.js","sourceRoot":"","sources":["../src/presence.native.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,4DAA4D;AAC5D,EAAE;AACF,wEAAwE;AACxE,qEAAqE;AACrE,uEAAuE;AAEvE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAY7C,MAAM,UAAU,WAAW,CAAC,IAAa;IACvC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;IAC5C,IAAI,IAAI,IAAI,CAAC,OAAO;QAAE,UAAU,CAAC,IAAI,CAAC,CAAA;IACtC,MAAM,IAAI,GAAG,WAAW,CAAC,GAAG,EAAE;QAC5B,IAAI,CAAC,IAAI;YAAE,UAAU,CAAC,KAAK,CAAC,CAAA;IAC9B,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;IACV,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAA;AAC3D,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hozo/behaviors",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Universal runtime behaviors substrate (LiveRegion, Portal, DismissableLayer, FocusScope, RovingFocus, FloatingPositioner) for Hozo.",
5
5
  "keywords": [
6
6
  "react-native",
@@ -43,6 +43,7 @@
43
43
  "./package.json": "./package.json"
44
44
  },
45
45
  "files": [
46
+ "CHANGELOG.md",
46
47
  "dist",
47
48
  "src",
48
49
  "!src/**/*.test.ts",
@@ -0,0 +1,88 @@
1
+ import type { ComponentRef } from 'react'
2
+ import { AccessibilityInfo, type View } from 'react-native'
3
+
4
+ export type HozoFocusTarget = ComponentRef<typeof View>
5
+ export type HozoFocusMover = (view: HozoFocusTarget) => void
6
+
7
+ /**
8
+ * Moving accessibility focus, with `@hozo/native` able to take over.
9
+ *
10
+ * ## Registered, not resolved, and that is a correction
11
+ *
12
+ * `docs/decisions/006-shipping-native-code.md` says the capability is reached
13
+ * "through a resolved provider, never imported", pointing at
14
+ * `packages/engine/src/safe-area.native.ts:50`, which does
15
+ * `try { require('react-native-safe-area-context') } catch {}`. That shape does
16
+ * not transfer here, and the reason is Metro rather than taste.
17
+ *
18
+ * Metro resolves `require` at bundle time. A literal `require` of a package that
19
+ * is not installed is a **build failure**, `try`/`catch` or not -- the catch runs
20
+ * at runtime and the bundler never gets there. Safe areas get away with it
21
+ * because that module is only in the graph when the compiler emitted a safe-area
22
+ * class: a project that writes none never imports it. This module is in the graph
23
+ * of every application that renders a `Dialog`, so a `require` here would make an
24
+ * optional package mandatory, and would break every existing app on upgrade.
25
+ *
26
+ * So the application hands the capability in, in two lines next to wherever it
27
+ * registers its root component:
28
+ *
29
+ * ```ts
30
+ * import { setAccessibilityFocusMover } from '@hozo/behaviors/native'
31
+ * import { moveAccessibilityFocus } from '@hozo/native'
32
+ *
33
+ * setAccessibilityFocusMover(moveAccessibilityFocus)
34
+ * ```
35
+ *
36
+ * `moveAccessibilityFocus` is `undefined` on iOS and when the native module is
37
+ * not in the binary, and the setter accepts that and keeps the default -- so the
38
+ * call needs no condition around it.
39
+ *
40
+ * ## The default is what this library has always done
41
+ *
42
+ * `AccessibilityInfo.sendAccessibilityEvent(view, 'focus')`, which works about
43
+ * half the time on Android (#484). An application that registers nothing is
44
+ * exactly as well off as it was, which is the third part of the decision's gate
45
+ * and the reason the capability was admitted at all.
46
+ *
47
+ * ## Why this is in `@hozo/behaviors/native`
48
+ *
49
+ * It has one consumer today -- `Dialog` -- and the first draft of this lived in
50
+ * `@hozo/patterns` for that reason. Registration moved it: a module holding one
51
+ * mutable binding costs nothing to load, where a provider resolution would have
52
+ * run a `require` in every package that imported it, and the application doing
53
+ * the registering should not have to reach into a widget package to do it.
54
+ * `@hozo/behaviors/native` is the entry point that already exists for API with no
55
+ * Web counterpart.
56
+ */
57
+ let registered: HozoFocusMover | undefined
58
+
59
+ /**
60
+ * Hand over a better way to move accessibility focus, or `undefined` to stop.
61
+ *
62
+ * Idempotent and last-wins. Registering twice is a sign of two roots, which an
63
+ * application can legitimately have -- a test harness mounting its own -- and
64
+ * neither a throw nor a warning would help it.
65
+ */
66
+ export function setAccessibilityFocusMover(mover: HozoFocusMover | undefined | null): void {
67
+ registered = mover ?? undefined
68
+ }
69
+
70
+ /** Whether something has been registered. Read by diagnostics, not by behaviour. */
71
+ export function hasAccessibilityFocusMover(): boolean {
72
+ return registered !== undefined
73
+ }
74
+
75
+ /**
76
+ * Put accessibility focus on `view`.
77
+ *
78
+ * Read at call time rather than captured, because registration happens during the
79
+ * application's startup and a module that captured the default at load would
80
+ * never see it.
81
+ */
82
+ export function moveAccessibilityFocus(view: HozoFocusTarget): void {
83
+ if (registered) {
84
+ registered(view)
85
+ return
86
+ }
87
+ AccessibilityInfo.sendAccessibilityEvent(view, 'focus')
88
+ }
@@ -31,6 +31,14 @@ export interface FocusScopeProps {
31
31
  trapped?: boolean
32
32
  autoFocus?: boolean
33
33
  restoreFocus?: boolean
34
+ /**
35
+ * Whether the scope holds focus. Turning it false does what unmounting
36
+ * does -- the trap is released and focus goes back to the opener -- for
37
+ * an overlay that stays mounted while it animates out (decision 007).
38
+ * Focus left inside a panel that is fading away would be on something
39
+ * nobody can use, and on nothing once the panel goes.
40
+ */
41
+ active?: boolean
34
42
  className?: string
35
43
  style?: CSSProperties
36
44
  }
@@ -38,6 +46,14 @@ export interface FocusScopeProps {
38
46
  const FOCUSABLE_SELECTOR =
39
47
  'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'
40
48
 
49
+ /**
50
+ * How long to keep trying to move focus in: ten tries a frame's length
51
+ * apart. A container hidden until it is measured shows by the first or
52
+ * second; ten is a bound, not a guess at a delay.
53
+ */
54
+ const INITIAL_FOCUS_ATTEMPTS = 10
55
+ const INITIAL_FOCUS_INTERVAL_MS = 16
56
+
41
57
  /**
42
58
  * Universal `<FocusScope>` component for Web.
43
59
  * Traps Tab key navigation, moves initial focus, and safely restores focus on unmount.
@@ -47,6 +63,7 @@ export function FocusScope({
47
63
  trapped = true,
48
64
  autoFocus = true,
49
65
  restoreFocus = true,
66
+ active = true,
50
67
  className,
51
68
  style,
52
69
  }: FocusScopeProps) {
@@ -55,6 +72,7 @@ export function FocusScope({
55
72
 
56
73
  useEffect(() => {
57
74
  if (typeof document === 'undefined') return
75
+ if (!active) return
58
76
 
59
77
  // Capture the trigger element that opened this scope
60
78
  if (restoreFocus && document.activeElement instanceof HTMLElement) {
@@ -64,7 +82,10 @@ export function FocusScope({
64
82
  const container = containerRef.current
65
83
  if (!container) return
66
84
 
67
- if (autoFocus) {
85
+ // Where focus goes on the way in: the first candidate, or the container
86
+ // itself (tabIndex="-1") so a screen reader still announces the role and
87
+ // name.
88
+ const initialTarget = (): HTMLElement => {
68
89
  const focusables = Array.from(
69
90
  container.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR),
70
91
  ).filter((el) => el.offsetParent !== null || el.getClientRects().length > 0)
@@ -75,13 +96,32 @@ export function FocusScope({
75
96
  }))
76
97
 
77
98
  const targetIdx = initialFocusIndex(candidates)
78
- if (targetIdx !== null && focusables[targetIdx]) {
79
- focusables[targetIdx].focus()
80
- } else {
81
- // Fallback: focus container itself (tabIndex="-1") so screen readers announce dialog role/label
82
- container.focus()
83
- }
99
+ return (targetIdx !== null && focusables[targetIdx]) || container
100
+ }
101
+
102
+ // `focus()` on an element that cannot take focus yet does nothing, and
103
+ // says nothing. `FloatingPositioner` is the case that found it: it draws
104
+ // its content `visibility: hidden` until it has measured, in an effect
105
+ // that runs after this one, so a popover's first focus landed on nothing
106
+ // and stayed on the trigger. Trying again shortly after covers that and
107
+ // any container like it -- but only while focus is still where the scope
108
+ // found it, so a person who has moved on is not pulled back. A timer
109
+ // rather than an animation frame: `focus()` resolves style itself, so it
110
+ // needs the positioner to have rendered, not the page to have painted --
111
+ // and frames do not run at all in a tab that is not being drawn.
112
+ let retry: ReturnType<typeof setTimeout> | undefined
113
+ const moveIn = (attempt: number) => {
114
+ const target = initialTarget()
115
+ target.focus()
116
+ if (document.activeElement === target || attempt >= INITIAL_FOCUS_ATTEMPTS) return
117
+ const stillWaiting =
118
+ document.activeElement === openerRef.current ||
119
+ document.activeElement === document.body ||
120
+ document.activeElement === null
121
+ if (!stillWaiting) return
122
+ retry = setTimeout(() => moveIn(attempt + 1), INITIAL_FOCUS_INTERVAL_MS)
84
123
  }
124
+ if (autoFocus) moveIn(0)
85
125
 
86
126
  const handleKeyDown = (event: KeyboardEvent) => {
87
127
  if (!trapped || event.key !== 'Tab') return
@@ -115,6 +155,7 @@ export function FocusScope({
115
155
  container.addEventListener('keydown', handleKeyDown)
116
156
 
117
157
  return () => {
158
+ clearTimeout(retry)
118
159
  container.removeEventListener('keydown', handleKeyDown)
119
160
  if (restoreFocus) {
120
161
  const opener = openerRef.current
@@ -128,7 +169,7 @@ export function FocusScope({
128
169
  }
129
170
  }
130
171
  }
131
- }, [trapped, autoFocus, restoreFocus])
172
+ }, [trapped, autoFocus, restoreFocus, active])
132
173
 
133
174
  return (
134
175
  <div
@@ -56,6 +56,7 @@ export {
56
56
  type PortalProps,
57
57
  PortalProvider,
58
58
  } from './portal.native.tsx'
59
+ export { type PresenceBinding, type PresenceState, usePresence } from './presence.native.ts'
59
60
  export {
60
61
  nextIndex,
61
62
  type Orientation,
package/src/index.ts CHANGED
@@ -56,6 +56,11 @@ export {
56
56
  type PortalProps,
57
57
  PortalProvider,
58
58
  } from './portal.tsx'
59
+ export {
60
+ type PresenceBinding,
61
+ type PresenceState,
62
+ usePresence,
63
+ } from './presence.ts'
59
64
  export {
60
65
  nextIndex,
61
66
  type Orientation,
package/src/native.ts CHANGED
@@ -1,3 +1,10 @@
1
+ export {
2
+ type HozoFocusMover,
3
+ type HozoFocusTarget,
4
+ hasAccessibilityFocusMover,
5
+ moveAccessibilityFocus,
6
+ setAccessibilityFocusMover,
7
+ } from './accessibility-focus.native.ts'
1
8
  export type { Placement } from './floating-geometry.ts'
2
9
  export {
3
10
  FloatingPositioner,
@@ -13,3 +20,4 @@ export {
13
20
  useHoverTrigger,
14
21
  } from './hover-trigger.native.tsx'
15
22
  export { Portal, PortalHost, type PortalProps, PortalProvider } from './portal.native.tsx'
23
+ export { type PresenceBinding, type PresenceState, usePresence } from './presence.native.ts'
@@ -0,0 +1,27 @@
1
+ // Keeping an element mounted while it animates out, on React Native
2
+ // (decision 007, slice 2). The Web half is `./presence.ts`.
3
+ //
4
+ // There is no computed style to read an exit's length from here, so the
5
+ // caller says when it is over: it runs its own `Animated` exit while
6
+ // `state` is `'closed'` and calls `done` from the completion callback.
7
+
8
+ import { useCallback, useState } from 'react'
9
+
10
+ export type PresenceState = 'open' | 'closed'
11
+
12
+ export interface PresenceBinding {
13
+ /** Whether to render the element at all. */
14
+ mounted: boolean
15
+ state: PresenceState
16
+ /** Ends the exit. Ignored once the element is shown again. */
17
+ done: () => void
18
+ }
19
+
20
+ export function usePresence(show: boolean): PresenceBinding {
21
+ const [mounted, setMounted] = useState(show)
22
+ if (show && !mounted) setMounted(true)
23
+ const done = useCallback(() => {
24
+ if (!show) setMounted(false)
25
+ }, [show])
26
+ return { mounted, state: show ? 'open' : 'closed', done }
27
+ }
@@ -0,0 +1,118 @@
1
+ // Keeping an element mounted while it animates out, on the Web
2
+ // (decision 007, slice 2).
3
+ //
4
+ // React removes an element the moment it stops being rendered, so nothing
5
+ // can animate after that. This holds on to it after `show` turns false,
6
+ // reports `state: 'closed'` for the caller to put on the element as
7
+ // `data-state`, and lets it go when the element's transition or animation
8
+ // ends. The exit itself is CSS -- a `data-[state=closed]:` class and a
9
+ // `transition-*` one -- so it costs no script beyond this.
10
+ //
11
+ // A hook rather than only a component because Hozo's overlays cannot wrap
12
+ // their panel in one: the panel sits inside a positioner, a dismiss layer
13
+ // and a focus scope, and it is the panel that leaves. `Presence` in
14
+ // `@hozo/primitives` is this hook around one child.
15
+
16
+ import { useCallback, useEffect, useRef, useState } from 'react'
17
+
18
+ export type PresenceState = 'open' | 'closed'
19
+
20
+ export interface PresenceBinding {
21
+ /** Whether to render the element at all. */
22
+ mounted: boolean
23
+ /** For the element's `data-state`. */
24
+ state: PresenceState
25
+ /** The element whose transition is the exit. */
26
+ ref: (node: Element | null) => void
27
+ onTransitionEnd: (event: { target: EventTarget; currentTarget: EventTarget }) => void
28
+ onAnimationEnd: (event: { target: EventTarget; currentTarget: EventTarget }) => void
29
+ }
30
+
31
+ /** How long past the computed end to wait for an event that never fires. */
32
+ const GRACE_MS = 100
33
+
34
+ /** The longest `duration + delay` across a comma-separated pair of lists. */
35
+ function longest(durations: string, delays: string): number {
36
+ const ms = (value: string) => {
37
+ const number = Number.parseFloat(value)
38
+ if (Number.isNaN(number)) return 0
39
+ return value.trim().endsWith('ms') ? number : number * 1000
40
+ }
41
+ const d = durations.split(',')
42
+ const l = delays.split(',')
43
+ // CSS repeats the shorter list to the length of the longer one.
44
+ const length = Math.max(d.length, l.length)
45
+ let out = 0
46
+ for (let i = 0; i < length; i++) {
47
+ out = Math.max(out, ms(d[i % d.length] ?? '0s') + ms(l[i % l.length] ?? '0s'))
48
+ }
49
+ return out
50
+ }
51
+
52
+ /** How long the element's exit runs, from its computed style. */
53
+ function exitDuration(element: Element): number {
54
+ const style = getComputedStyle(element)
55
+ return Math.max(
56
+ longest(style.transitionDuration, style.transitionDelay),
57
+ style.animationName === 'none' ? 0 : longest(style.animationDuration, style.animationDelay),
58
+ )
59
+ }
60
+
61
+ export function usePresence(show: boolean): PresenceBinding {
62
+ const [mounted, setMounted] = useState(show)
63
+ // Set during render rather than in an effect, so an element that is shown
64
+ // again appears in the same commit instead of one frame late.
65
+ if (show && !mounted) setMounted(true)
66
+
67
+ const element = useRef<Element | null>(null)
68
+ const ending = useRef<{ at: number; timer: ReturnType<typeof setTimeout> } | null>(null)
69
+
70
+ const finish = useCallback(() => {
71
+ if (ending.current) clearTimeout(ending.current.timer)
72
+ ending.current = null
73
+ setMounted(false)
74
+ }, [])
75
+
76
+ useEffect(() => {
77
+ if (show || !mounted) return
78
+ // Read after the commit that set `data-state="closed"`, so the
79
+ // computed style is the one the element is leaving with -- including
80
+ // `motion-reduce:transition-none`, which makes this zero.
81
+ const target = element.current
82
+ const duration = target ? exitDuration(target) : 0
83
+ if (duration === 0) {
84
+ finish()
85
+ return
86
+ }
87
+ const at = performance.now() + duration
88
+ ending.current = { at, timer: setTimeout(finish, duration + GRACE_MS) }
89
+ return () => {
90
+ if (ending.current) clearTimeout(ending.current.timer)
91
+ ending.current = null
92
+ }
93
+ }, [show, mounted, finish])
94
+
95
+ // `transitionend` fires once per property, and the properties may end
96
+ // at different times. Only the one that ends last finishes the exit.
97
+ const onEnd = useCallback(
98
+ (event: { target: EventTarget; currentTarget: EventTarget }) => {
99
+ if (event.target !== event.currentTarget) return
100
+ const pending = ending.current
101
+ if (!pending || performance.now() < pending.at - 20) return
102
+ finish()
103
+ },
104
+ [finish],
105
+ )
106
+
107
+ const ref = useCallback((node: Element | null) => {
108
+ element.current = node
109
+ }, [])
110
+
111
+ return {
112
+ mounted,
113
+ state: show ? 'open' : 'closed',
114
+ ref,
115
+ onTransitionEnd: onEnd,
116
+ onAnimationEnd: onEnd,
117
+ }
118
+ }