@hozo/behaviors 0.1.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/LICENSE +21 -0
- package/README.md +80 -0
- package/dist/dismissable-layer.d.ts +17 -0
- package/dist/dismissable-layer.d.ts.map +1 -0
- package/dist/dismissable-layer.js +67 -0
- package/dist/dismissable-layer.js.map +1 -0
- package/dist/dismissable-layer.native.d.ts +28 -0
- package/dist/dismissable-layer.native.d.ts.map +1 -0
- package/dist/dismissable-layer.native.js +38 -0
- package/dist/dismissable-layer.native.js.map +1 -0
- package/dist/floating-geometry.d.ts +63 -0
- package/dist/floating-geometry.d.ts.map +1 -0
- package/dist/floating-geometry.js +191 -0
- package/dist/floating-geometry.js.map +1 -0
- package/dist/floating-positioner.d.ts +24 -0
- package/dist/floating-positioner.d.ts.map +1 -0
- package/dist/floating-positioner.js +110 -0
- package/dist/floating-positioner.js.map +1 -0
- package/dist/floating-positioner.native.d.ts +43 -0
- package/dist/floating-positioner.native.d.ts.map +1 -0
- package/dist/floating-positioner.native.js +82 -0
- package/dist/floating-positioner.native.js.map +1 -0
- package/dist/focus-scope.d.ts +31 -0
- package/dist/focus-scope.d.ts.map +1 -0
- package/dist/focus-scope.js +96 -0
- package/dist/focus-scope.js.map +1 -0
- package/dist/focus-scope.native.d.ts +33 -0
- package/dist/focus-scope.native.d.ts.map +1 -0
- package/dist/focus-scope.native.js +25 -0
- package/dist/focus-scope.native.js.map +1 -0
- package/dist/hover-geometry.d.ts +64 -0
- package/dist/hover-geometry.d.ts.map +1 -0
- package/dist/hover-geometry.js +146 -0
- package/dist/hover-geometry.js.map +1 -0
- package/dist/hover-trigger.d.ts +64 -0
- package/dist/hover-trigger.d.ts.map +1 -0
- package/dist/hover-trigger.js +174 -0
- package/dist/hover-trigger.js.map +1 -0
- package/dist/hover-trigger.native.d.ts +45 -0
- package/dist/hover-trigger.native.d.ts.map +1 -0
- package/dist/hover-trigger.native.js +101 -0
- package/dist/hover-trigger.native.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/index.native.d.ts +12 -0
- package/dist/index.native.d.ts.map +1 -0
- package/dist/index.native.js +12 -0
- package/dist/index.native.js.map +1 -0
- package/dist/live-region.d.ts +19 -0
- package/dist/live-region.d.ts.map +1 -0
- package/dist/live-region.js +51 -0
- package/dist/live-region.js.map +1 -0
- package/dist/live-region.native.d.ts +31 -0
- package/dist/live-region.native.d.ts.map +1 -0
- package/dist/live-region.native.js +38 -0
- package/dist/live-region.native.js.map +1 -0
- package/dist/native.d.ts +5 -0
- package/dist/native.d.ts.map +1 -0
- package/dist/native.js +4 -0
- package/dist/native.js.map +1 -0
- package/dist/portal.d.ts +26 -0
- package/dist/portal.d.ts.map +1 -0
- package/dist/portal.js +41 -0
- package/dist/portal.js.map +1 -0
- package/dist/portal.native.d.ts +44 -0
- package/dist/portal.native.d.ts.map +1 -0
- package/dist/portal.native.js +79 -0
- package/dist/portal.native.js.map +1 -0
- package/dist/roving-focus-rules.d.ts +13 -0
- package/dist/roving-focus-rules.d.ts.map +1 -0
- package/dist/roving-focus-rules.js +49 -0
- package/dist/roving-focus-rules.js.map +1 -0
- package/dist/roving-focus.d.ts +27 -0
- package/dist/roving-focus.d.ts.map +1 -0
- package/dist/roving-focus.js +52 -0
- package/dist/roving-focus.js.map +1 -0
- package/dist/roving-focus.native.d.ts +36 -0
- package/dist/roving-focus.native.d.ts.map +1 -0
- package/dist/roving-focus.native.js +28 -0
- package/dist/roving-focus.native.js.map +1 -0
- package/dist/text-child.d.ts +4 -0
- package/dist/text-child.d.ts.map +1 -0
- package/dist/text-child.js +17 -0
- package/dist/text-child.js.map +1 -0
- package/dist/text-child.native.d.ts +14 -0
- package/dist/text-child.native.d.ts.map +1 -0
- package/dist/text-child.native.js +42 -0
- package/dist/text-child.native.js.map +1 -0
- package/dist/typeahead.d.ts +36 -0
- package/dist/typeahead.d.ts.map +1 -0
- package/dist/typeahead.js +97 -0
- package/dist/typeahead.js.map +1 -0
- package/package.json +82 -0
- package/src/dismissable-layer.native.tsx +72 -0
- package/src/dismissable-layer.tsx +106 -0
- package/src/floating-geometry.ts +306 -0
- package/src/floating-positioner.native.tsx +155 -0
- package/src/floating-positioner.tsx +173 -0
- package/src/focus-scope.native.tsx +53 -0
- package/src/focus-scope.tsx +143 -0
- package/src/hover-geometry.ts +182 -0
- package/src/hover-trigger.native.tsx +179 -0
- package/src/hover-trigger.tsx +303 -0
- package/src/index.native.ts +77 -0
- package/src/index.ts +77 -0
- package/src/live-region.native.tsx +61 -0
- package/src/live-region.tsx +74 -0
- package/src/native.ts +15 -0
- package/src/portal.native.tsx +130 -0
- package/src/portal.tsx +68 -0
- package/src/roving-focus-rules.ts +79 -0
- package/src/roving-focus.native.tsx +81 -0
- package/src/roving-focus.tsx +118 -0
- package/src/text-child.native.tsx +44 -0
- package/src/text-child.ts +19 -0
- package/src/typeahead.ts +120 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 iray-tno
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# @hozo/behaviors
|
|
2
|
+
|
|
3
|
+
Universal headless runtime behaviors and positioning primitives for Hozo.
|
|
4
|
+
|
|
5
|
+
These primitives provide the essential interaction mechanics — focus management, outside click handling, keyboard navigation, collision-aware floating positioning, disclosure states, phonetic reading control, and hover delay groups — on both Web and React Native.
|
|
6
|
+
|
|
7
|
+
## Included Behaviors
|
|
8
|
+
|
|
9
|
+
### 1. Hover & Tooltip Mechanics
|
|
10
|
+
- **`useHoverTrigger`**: Headless hook managing hover, keyboard focus, Escape dismissal, and mobile long-press triggers. Monitors pointer movement against safe polygons to avoid flickering.
|
|
11
|
+
- **`TooltipGroupProvider` / `useTooltipGroup`**: Warmup and cooldown delay state machine for sibling tooltips (e.g. toolbars). Opens with an intentional delay (`openDelay`, default 700ms) on first hover, then switches instantly (`0ms`) between adjacent tools until the cooldown timer (`skipDelayDuration`, default 300ms) expires.
|
|
12
|
+
- **`computeSafePolygon` / `isPointInPolygon`**: Pure ray-casting geometric calculation creating a dynamic safe bridge between the pointer on the trigger and the floating content rectangle (e.g. HoverCards with buttons), allowing diagonal cursor travel without accidental dismissals.
|
|
13
|
+
- **`@hozo/patterns` `Tooltip`** composes these headless pieces and owns the rendered widget.
|
|
14
|
+
|
|
15
|
+
### 2. Focus & Keyboard Management
|
|
16
|
+
- **`FocusScope`**: Universal focus containment (tab trapping), initial auto-focus target resolution, and focus restoration to opener element on unmount.
|
|
17
|
+
- **`RovingFocusGroup` / `useRovingItem`**: WAI-ARIA roving `tabIndex` manager for toolbars, menus, tablists, radio groups, and tree views, supporting horizontal/vertical orientations and wrap-around.
|
|
18
|
+
- **`useTypeahead`**: Predictive keyboard navigation matching query prefixes with loop prevention and reset timeout.
|
|
19
|
+
|
|
20
|
+
### 3. Layers, Portals & Dismissals
|
|
21
|
+
- **`DismissableLayer`**: Outside pointerdown/press dismissal and Escape key handling with proper nested stacking order.
|
|
22
|
+
- **`Portal` / `PortalHost` / `PortalProvider`**: Universal React Portal rendering across Web DOM (`document.body` or custom node) and React Native root hierarchies with sibling `inert` coordination.
|
|
23
|
+
- **Dialog foundations**: focus scope, dismissable layers, and portals remain here; the rendered
|
|
24
|
+
`Dialog` / `HozoDialog` component is owned by `@hozo/patterns`.
|
|
25
|
+
|
|
26
|
+
### 4. Floating Anchoring & Positioning
|
|
27
|
+
- **`FloatingPositioner` / `useFloatingPosition`**: Zero-dependency floating positioning supporting 12 placements, auto-flip, shift overflow boundary constraints, arrow offset clamping, `matchAnchorWidth` for selects, and `referenceHidden` tracking.
|
|
28
|
+
|
|
29
|
+
### 5. Screen Reader Announcements
|
|
30
|
+
- **`LiveRegion` / `useAnnounce`**: Universal polite and assertive screen reader live announcements with queued vocalization.
|
|
31
|
+
|
|
32
|
+
## Usage Example
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { useState } from 'react'
|
|
36
|
+
import {
|
|
37
|
+
FloatingPositioner,
|
|
38
|
+
DismissableLayer,
|
|
39
|
+
FocusScope,
|
|
40
|
+
Portal,
|
|
41
|
+
useHoverTrigger,
|
|
42
|
+
} from '@hozo/behaviors'
|
|
43
|
+
|
|
44
|
+
export function HoverPreview() {
|
|
45
|
+
const [open, setOpen] = useState(false)
|
|
46
|
+
const { triggerProps, contentProps } = useHoverTrigger({
|
|
47
|
+
open,
|
|
48
|
+
onOpenChange: setOpen,
|
|
49
|
+
openDelay: 400,
|
|
50
|
+
closeDelay: 200,
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<>
|
|
55
|
+
<button type="button" {...triggerProps}>
|
|
56
|
+
Hover or Focus me
|
|
57
|
+
</button>
|
|
58
|
+
{open && (
|
|
59
|
+
<Portal>
|
|
60
|
+
<DismissableLayer onDismiss={() => setOpen(false)}>
|
|
61
|
+
<FocusScope trapFocus={false}>
|
|
62
|
+
<FloatingPositioner placement="top">
|
|
63
|
+
<div {...contentProps}>Accessible contextual card</div>
|
|
64
|
+
</FloatingPositioner>
|
|
65
|
+
</FocusScope>
|
|
66
|
+
</DismissableLayer>
|
|
67
|
+
</Portal>
|
|
68
|
+
)}
|
|
69
|
+
</>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
<!-- generated: package-footer -->
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
Part of [Hozo](https://iray-tno.github.io/hozo/), a Rust-powered universal UI compiler and accessibility-first layer for React Native. Most applications install [`@hozo/core`](https://www.npmjs.com/package/@hozo/core) and one build integration; see [Getting started](https://github.com/iray-tno/hozo#getting-started). Source and issues: [github.com/iray-tno/hozo](https://github.com/iray-tno/hozo).
|
|
79
|
+
|
|
80
|
+
<!-- /generated: package-footer -->
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
|
+
export interface DismissableLayerProps {
|
|
3
|
+
children?: ReactNode;
|
|
4
|
+
onDismiss?: () => void;
|
|
5
|
+
onEscapeKeyDown?: (event: KeyboardEvent) => void;
|
|
6
|
+
onPointerDownOutside?: (event: PointerEvent) => void;
|
|
7
|
+
disableOutsidePointerEvents?: boolean;
|
|
8
|
+
className?: string;
|
|
9
|
+
style?: CSSProperties;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Universal `<DismissableLayer>` component for Web.
|
|
13
|
+
* Detects Escape key presses and pointer down outside the layer boundary.
|
|
14
|
+
* Manages layer stacking order so only the top-most active layer dismisses.
|
|
15
|
+
*/
|
|
16
|
+
export declare function DismissableLayer({ children, onDismiss, onEscapeKeyDown, onPointerDownOutside, disableOutsidePointerEvents, className, style, }: DismissableLayerProps): import("react").JSX.Element;
|
|
17
|
+
//# sourceMappingURL=dismissable-layer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dismissable-layer.d.ts","sourceRoot":"","sources":["../src/dismissable-layer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,SAAS,EAAqB,MAAM,OAAO,CAAA;AAE7E,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IACtB,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAA;IAChD,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;IACpD,2BAA2B,CAAC,EAAE,OAAO,CAAA;IACrC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,aAAa,CAAA;CACtB;AAYD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,QAAQ,EACR,SAAS,EACT,eAAe,EACf,oBAAoB,EACpB,2BAAmC,EACnC,SAAS,EACT,KAAK,GACN,EAAE,qBAAqB,+BAsEvB"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
// Global stack of active dismissable layers (LIFO: last opened is top-most)
|
|
4
|
+
const layers = [];
|
|
5
|
+
/**
|
|
6
|
+
* Universal `<DismissableLayer>` component for Web.
|
|
7
|
+
* Detects Escape key presses and pointer down outside the layer boundary.
|
|
8
|
+
* Manages layer stacking order so only the top-most active layer dismisses.
|
|
9
|
+
*/
|
|
10
|
+
export function DismissableLayer({ children, onDismiss, onEscapeKeyDown, onPointerDownOutside, disableOutsidePointerEvents = false, className, style, }) {
|
|
11
|
+
const ref = useRef(null);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const node = ref.current;
|
|
14
|
+
const instance = {
|
|
15
|
+
node,
|
|
16
|
+
onDismiss,
|
|
17
|
+
onEscapeKeyDown,
|
|
18
|
+
onPointerDownOutside,
|
|
19
|
+
};
|
|
20
|
+
layers.push(instance);
|
|
21
|
+
const handleKeyDown = (event) => {
|
|
22
|
+
if (event.key !== 'Escape')
|
|
23
|
+
return;
|
|
24
|
+
// Only the top-most layer reacts to Escape
|
|
25
|
+
const topLayer = layers[layers.length - 1];
|
|
26
|
+
if (topLayer !== instance)
|
|
27
|
+
return;
|
|
28
|
+
instance.onEscapeKeyDown?.(event);
|
|
29
|
+
if (!event.defaultPrevented) {
|
|
30
|
+
instance.onDismiss?.();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const handlePointerDown = (event) => {
|
|
34
|
+
const topLayer = layers[layers.length - 1];
|
|
35
|
+
if (topLayer !== instance)
|
|
36
|
+
return;
|
|
37
|
+
if (!instance.node)
|
|
38
|
+
return;
|
|
39
|
+
const target = event.target;
|
|
40
|
+
const isOutside = target && !instance.node.contains(target);
|
|
41
|
+
if (isOutside) {
|
|
42
|
+
if (disableOutsidePointerEvents) {
|
|
43
|
+
event.preventDefault();
|
|
44
|
+
}
|
|
45
|
+
instance.onPointerDownOutside?.(event);
|
|
46
|
+
if (!event.defaultPrevented) {
|
|
47
|
+
instance.onDismiss?.();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
52
|
+
document.addEventListener('pointerdown', handlePointerDown);
|
|
53
|
+
return () => {
|
|
54
|
+
const index = layers.indexOf(instance);
|
|
55
|
+
if (index !== -1) {
|
|
56
|
+
layers.splice(index, 1);
|
|
57
|
+
}
|
|
58
|
+
document.removeEventListener('keydown', handleKeyDown);
|
|
59
|
+
document.removeEventListener('pointerdown', handlePointerDown);
|
|
60
|
+
};
|
|
61
|
+
}, [onDismiss, onEscapeKeyDown, onPointerDownOutside, disableOutsidePointerEvents]);
|
|
62
|
+
return (_jsx("div", { ref: ref, className: className, style: {
|
|
63
|
+
...style,
|
|
64
|
+
pointerEvents: 'auto',
|
|
65
|
+
}, children: children }));
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=dismissable-layer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dismissable-layer.js","sourceRoot":"","sources":["../src/dismissable-layer.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAsC,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAmB7E,4EAA4E;AAC5E,MAAM,MAAM,GAAoB,EAAE,CAAA;AAElC;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAC/B,QAAQ,EACR,SAAS,EACT,eAAe,EACf,oBAAoB,EACpB,2BAA2B,GAAG,KAAK,EACnC,SAAS,EACT,KAAK,GACiB;IACtB,MAAM,GAAG,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAA;IAExC,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAA;QACxB,MAAM,QAAQ,GAAkB;YAC9B,IAAI;YACJ,SAAS;YACT,eAAe;YACf,oBAAoB;SACrB,CAAA;QAED,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAErB,MAAM,aAAa,GAAG,CAAC,KAAoB,EAAE,EAAE;YAC7C,IAAI,KAAK,CAAC,GAAG,KAAK,QAAQ;gBAAE,OAAM;YAClC,2CAA2C;YAC3C,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;YAC1C,IAAI,QAAQ,KAAK,QAAQ;gBAAE,OAAM;YAEjC,QAAQ,CAAC,eAAe,EAAE,CAAC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AAA;YACtD,QAAQ,CAAC,mBAAmB,CAAC,aAAa,EAAE,iBAAiB,CAAC,CAAA;QAChE,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,SAAS,EAAE,eAAe,EAAE,oBAAoB,EAAE,2BAA2B,CAAC,CAAC,CAAA;IAEnF,OAAO,CACL,cACE,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE;YACL,GAAG,KAAK;YACR,aAAa,EAAE,MAAM;SACtB,YAEA,QAAQ,GACL,CACP,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React, { type ReactNode } from 'react';
|
|
2
|
+
import { type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
+
export interface DismissableLayerProps {
|
|
4
|
+
/**
|
|
5
|
+
* Tailwind classes, the same prop the Web half takes.
|
|
6
|
+
*
|
|
7
|
+
* On a tag the compiler lowers it is gone by runtime, replaced by a
|
|
8
|
+
* `StyleSheet` entry. Anywhere else it is carried and ignored here --
|
|
9
|
+
* this side has no CSS engine to resolve a class list against -- and
|
|
10
|
+
* the type still has to accept it, because an app is type-checked
|
|
11
|
+
* against the source the compiler reads rather than its output.
|
|
12
|
+
*/
|
|
13
|
+
className?: string;
|
|
14
|
+
children?: ReactNode;
|
|
15
|
+
onDismiss?: () => void;
|
|
16
|
+
onEscapeKeyDown?: () => void;
|
|
17
|
+
onPointerDownOutside?: () => void;
|
|
18
|
+
disableOutsidePointerEvents?: boolean;
|
|
19
|
+
style?: StyleProp<ViewStyle>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Universal `<DismissableLayer>` component for React Native.
|
|
23
|
+
* Listens to BackHandler on Android and manages layered dismiss stack.
|
|
24
|
+
*/
|
|
25
|
+
export declare function DismissableLayer({ children, onDismiss, onEscapeKeyDown, style, ...props }: DismissableLayerProps): React.FunctionComponentElement<Omit<import("react-native").ViewProps, "ref"> & {
|
|
26
|
+
ref?: React.Ref<import("react-native").ViewInstance> | undefined;
|
|
27
|
+
}>;
|
|
28
|
+
//# sourceMappingURL=dismissable-layer.native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dismissable-layer.native.d.ts","sourceRoot":"","sources":["../src/dismissable-layer.native.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,KAAK,SAAS,EAAa,MAAM,OAAO,CAAA;AACxD,OAAO,EAAe,KAAK,SAAS,EAAQ,KAAK,SAAS,EAAE,MAAM,cAAc,CAAA;AAEhF,MAAM,WAAW,qBAAqB;IACpC;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IACtB,eAAe,CAAC,EAAE,MAAM,IAAI,CAAA;IAC5B,oBAAoB,CAAC,EAAE,MAAM,IAAI,CAAA;IACjC,2BAA2B,CAAC,EAAE,OAAO,CAAA;IACrC,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAA;CAC7B;AASD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,QAAQ,EACR,SAAS,EACT,eAAe,EACf,KAAK,EACL,GAAG,KAAK,EACT,EAAE,qBAAqB;;GAgCvB"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
import { BackHandler, View } from 'react-native';
|
|
3
|
+
const nativeLayers = [];
|
|
4
|
+
/**
|
|
5
|
+
* Universal `<DismissableLayer>` component for React Native.
|
|
6
|
+
* Listens to BackHandler on Android and manages layered dismiss stack.
|
|
7
|
+
*/
|
|
8
|
+
export function DismissableLayer({ children, onDismiss, onEscapeKeyDown, style, ...props }) {
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const instance = {
|
|
11
|
+
onDismiss,
|
|
12
|
+
onEscapeKeyDown,
|
|
13
|
+
};
|
|
14
|
+
nativeLayers.push(instance);
|
|
15
|
+
// `BackHandler` imported rather than read off `globalThis`, where React Native
|
|
16
|
+
// has never put it. The lookup always returned `undefined` and the
|
|
17
|
+
// `if` around it always failed, so this did nothing at all -- silently,
|
|
18
|
+
// which is the worst way for an accessibility affordance to be absent.
|
|
19
|
+
const subscription = BackHandler.addEventListener('hardwareBackPress', () => {
|
|
20
|
+
const top = nativeLayers[nativeLayers.length - 1];
|
|
21
|
+
if (top === instance) {
|
|
22
|
+
instance.onEscapeKeyDown?.();
|
|
23
|
+
instance.onDismiss?.();
|
|
24
|
+
return true; // Handled
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
});
|
|
28
|
+
return () => {
|
|
29
|
+
const idx = nativeLayers.indexOf(instance);
|
|
30
|
+
if (idx !== -1) {
|
|
31
|
+
nativeLayers.splice(idx, 1);
|
|
32
|
+
}
|
|
33
|
+
subscription.remove();
|
|
34
|
+
};
|
|
35
|
+
}, [onDismiss, onEscapeKeyDown]);
|
|
36
|
+
return React.createElement(View, { style, ...props }, children);
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=dismissable-layer.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dismissable-layer.native.js","sourceRoot":"","sources":["../src/dismissable-layer.native.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAkB,SAAS,EAAE,MAAM,OAAO,CAAA;AACxD,OAAO,EAAE,WAAW,EAAkB,IAAI,EAAkB,MAAM,cAAc,CAAA;AA0BhF,MAAM,YAAY,GAA0B,EAAE,CAAA;AAE9C;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAC/B,QAAQ,EACR,SAAS,EACT,eAAe,EACf,KAAK,EACL,GAAG,KAAK,EACc;IACtB,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,QAAQ,GAAwB;YACpC,SAAS;YACT,eAAe;SAChB,CAAA;QACD,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAE3B,+EAA+E;QAC/E,mEAAmE;QACnE,wEAAwE;QACxE,uEAAuE;QACvE,MAAM,YAAY,GAAG,WAAW,CAAC,gBAAgB,CAAC,mBAAmB,EAAE,GAAG,EAAE;YAC1E,MAAM,GAAG,GAAG,YAAY,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;YACjD,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;gBACrB,QAAQ,CAAC,eAAe,EAAE,EAAE,CAAA;gBAC5B,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAA;gBACtB,OAAO,IAAI,CAAA,CAAC,UAAU;YACxB,CAAC;YACD,OAAO,KAAK,CAAA;QACd,CAAC,CAAC,CAAA;QAEF,OAAO,GAAG,EAAE;YACV,MAAM,GAAG,GAAG,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;YAC1C,IAAI,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;gBACf,YAAY,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;YAC7B,CAAC;YACD,YAAY,CAAC,MAAM,EAAE,CAAA;QACvB,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC,CAAA;IAEhC,OAAO,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE,QAAQ,CAAC,CAAA;AACjE,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export interface Rect {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
}
|
|
7
|
+
export interface Viewport {
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
}
|
|
11
|
+
export type BasePlacement = 'top' | 'bottom' | 'left' | 'right';
|
|
12
|
+
export type Alignment = 'start' | 'center' | 'end';
|
|
13
|
+
export type Placement = BasePlacement | `${BasePlacement}-start` | `${BasePlacement}-end`;
|
|
14
|
+
export interface ComputePositionOptions {
|
|
15
|
+
/** Desired placement relative to the anchor. Default: 'bottom' */
|
|
16
|
+
placement?: Placement;
|
|
17
|
+
/** Distance along the main axis between anchor and floating element in pixels. Default: 8 */
|
|
18
|
+
offset?: number;
|
|
19
|
+
/** Offset along the cross axis in pixels. Default: 0 */
|
|
20
|
+
crossAxisOffset?: number;
|
|
21
|
+
/** Whether to flip placement if floating element overflows viewport. Default: true */
|
|
22
|
+
flip?: boolean;
|
|
23
|
+
/** Whether to shift floating element to keep it within viewport. Default: true */
|
|
24
|
+
shift?: boolean;
|
|
25
|
+
/** Minimum padding from the viewport edge in pixels. Default: 8 */
|
|
26
|
+
viewportPadding?: number;
|
|
27
|
+
/** Minimum padding from the floating edge to arrow center in pixels. Default: 4 */
|
|
28
|
+
arrowPadding?: number;
|
|
29
|
+
/** Whether the floating element width should match the anchor width. Default: false */
|
|
30
|
+
matchAnchorWidth?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface PositionResult {
|
|
33
|
+
x: number;
|
|
34
|
+
y: number;
|
|
35
|
+
placement: Placement;
|
|
36
|
+
basePlacement: BasePlacement;
|
|
37
|
+
alignment: Alignment;
|
|
38
|
+
flipped: boolean;
|
|
39
|
+
shifted: boolean;
|
|
40
|
+
/** Whether the anchor element is currently completely outside the viewport (hidden by scroll) */
|
|
41
|
+
referenceHidden: boolean;
|
|
42
|
+
/** The anchor element's measured width in pixels */
|
|
43
|
+
anchorWidth: number;
|
|
44
|
+
/** Maximum dimensions available for the floating element before overflowing viewport */
|
|
45
|
+
availableDimensions: {
|
|
46
|
+
width: number;
|
|
47
|
+
height: number;
|
|
48
|
+
};
|
|
49
|
+
arrow?: {
|
|
50
|
+
x?: number;
|
|
51
|
+
y?: number;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export declare function parsePlacement(placement: Placement): {
|
|
55
|
+
basePlacement: BasePlacement;
|
|
56
|
+
alignment: Alignment;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Pure geometric calculation for positioning floating elements relative to an anchor.
|
|
60
|
+
* Supports Popper/Floating-UI equivalent placement, flip, shift, size limits, and arrow calculation.
|
|
61
|
+
*/
|
|
62
|
+
export declare function computePosition(anchor: Rect, floating: Rect, viewport: Viewport, options?: ComputePositionOptions): PositionResult;
|
|
63
|
+
//# sourceMappingURL=floating-geometry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"floating-geometry.d.ts","sourceRoot":"","sources":["../src/floating-geometry.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,IAAI;IACnB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;AAC/D,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAA;AAClD,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,GAAG,aAAa,QAAQ,GAAG,GAAG,aAAa,MAAM,CAAA;AAEzF,MAAM,WAAW,sBAAsB;IACrC,kEAAkE;IAClE,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,6FAA6F;IAC7F,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,wDAAwD;IACxD,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,sFAAsF;IACtF,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,kFAAkF;IAClF,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,mEAAmE;IACnE,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,mFAAmF;IACnF,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,uFAAuF;IACvF,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B;AAED,MAAM,WAAW,cAAc;IAC7B,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,SAAS,EAAE,SAAS,CAAA;IACpB,aAAa,EAAE,aAAa,CAAA;IAC5B,SAAS,EAAE,SAAS,CAAA;IACpB,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,iGAAiG;IACjG,eAAe,EAAE,OAAO,CAAA;IACxB,oDAAoD;IACpD,WAAW,EAAE,MAAM,CAAA;IACnB,wFAAwF;IACxF,mBAAmB,EAAE;QACnB,KAAK,EAAE,MAAM,CAAA;QACb,MAAM,EAAE,MAAM,CAAA;KACf,CAAA;IACD,KAAK,CAAC,EAAE;QACN,CAAC,CAAC,EAAE,MAAM,CAAA;QACV,CAAC,CAAC,EAAE,MAAM,CAAA;KACX,CAAA;CACF;AAED,wBAAgB,cAAc,CAAC,SAAS,EAAE,SAAS,GAAG;IACpD,aAAa,EAAE,aAAa,CAAA;IAC5B,SAAS,EAAE,SAAS,CAAA;CACrB,CAMA;AAyDD;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,IAAI,EACZ,QAAQ,EAAE,IAAI,EACd,QAAQ,EAAE,QAAQ,EAClB,OAAO,GAAE,sBAA2B,GACnC,cAAc,CA4KhB"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
export function parsePlacement(placement) {
|
|
2
|
+
const [base, align] = placement.split('-');
|
|
3
|
+
return {
|
|
4
|
+
basePlacement: base,
|
|
5
|
+
alignment: align ?? 'center',
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
function getOppositeBase(base) {
|
|
9
|
+
switch (base) {
|
|
10
|
+
case 'top':
|
|
11
|
+
return 'bottom';
|
|
12
|
+
case 'bottom':
|
|
13
|
+
return 'top';
|
|
14
|
+
case 'left':
|
|
15
|
+
return 'right';
|
|
16
|
+
case 'right':
|
|
17
|
+
return 'left';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function calculateRawCoords(anchor, floating, base, align, offset, crossAxisOffset) {
|
|
21
|
+
let x = 0;
|
|
22
|
+
let y = 0;
|
|
23
|
+
if (base === 'top') {
|
|
24
|
+
y = anchor.y - floating.height - offset;
|
|
25
|
+
}
|
|
26
|
+
else if (base === 'bottom') {
|
|
27
|
+
y = anchor.y + anchor.height + offset;
|
|
28
|
+
}
|
|
29
|
+
else if (base === 'left') {
|
|
30
|
+
x = anchor.x - floating.width - offset;
|
|
31
|
+
}
|
|
32
|
+
else if (base === 'right') {
|
|
33
|
+
x = anchor.x + anchor.width + offset;
|
|
34
|
+
}
|
|
35
|
+
if (base === 'top' || base === 'bottom') {
|
|
36
|
+
if (align === 'start') {
|
|
37
|
+
x = anchor.x + crossAxisOffset;
|
|
38
|
+
}
|
|
39
|
+
else if (align === 'end') {
|
|
40
|
+
x = anchor.x + anchor.width - floating.width + crossAxisOffset;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
x = anchor.x + (anchor.width - floating.width) / 2 + crossAxisOffset;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
if (align === 'start') {
|
|
48
|
+
y = anchor.y + crossAxisOffset;
|
|
49
|
+
}
|
|
50
|
+
else if (align === 'end') {
|
|
51
|
+
y = anchor.y + anchor.height - floating.height + crossAxisOffset;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
y = anchor.y + (anchor.height - floating.height) / 2 + crossAxisOffset;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return { x, y };
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Pure geometric calculation for positioning floating elements relative to an anchor.
|
|
61
|
+
* Supports Popper/Floating-UI equivalent placement, flip, shift, size limits, and arrow calculation.
|
|
62
|
+
*/
|
|
63
|
+
export function computePosition(anchor, floating, viewport, options = {}) {
|
|
64
|
+
const { placement = 'bottom', offset = 8, crossAxisOffset = 0, flip = true, shift = true, viewportPadding = 8, arrowPadding = 4, matchAnchorWidth = false, } = options;
|
|
65
|
+
const effectiveFloating = matchAnchorWidth ? { ...floating, width: anchor.width } : floating;
|
|
66
|
+
const parsed = parsePlacement(placement);
|
|
67
|
+
let currentBase = parsed.basePlacement;
|
|
68
|
+
const currentAlign = parsed.alignment;
|
|
69
|
+
let flipped = false;
|
|
70
|
+
let coords = calculateRawCoords(anchor, effectiveFloating, currentBase, currentAlign, offset, crossAxisOffset);
|
|
71
|
+
// Check collision for flipping
|
|
72
|
+
if (flip) {
|
|
73
|
+
let overflows = false;
|
|
74
|
+
if (currentBase === 'top') {
|
|
75
|
+
overflows = coords.y < viewportPadding;
|
|
76
|
+
}
|
|
77
|
+
else if (currentBase === 'bottom') {
|
|
78
|
+
overflows = coords.y + effectiveFloating.height > viewport.height - viewportPadding;
|
|
79
|
+
}
|
|
80
|
+
else if (currentBase === 'left') {
|
|
81
|
+
overflows = coords.x < viewportPadding;
|
|
82
|
+
}
|
|
83
|
+
else if (currentBase === 'right') {
|
|
84
|
+
overflows = coords.x + effectiveFloating.width > viewport.width - viewportPadding;
|
|
85
|
+
}
|
|
86
|
+
if (overflows) {
|
|
87
|
+
const oppositeBase = getOppositeBase(currentBase);
|
|
88
|
+
const oppositeCoords = calculateRawCoords(anchor, effectiveFloating, oppositeBase, currentAlign, offset, crossAxisOffset);
|
|
89
|
+
// Measure spaces
|
|
90
|
+
let currentSpace = 0;
|
|
91
|
+
let oppositeSpace = 0;
|
|
92
|
+
if (currentBase === 'top') {
|
|
93
|
+
currentSpace = anchor.y;
|
|
94
|
+
oppositeSpace = viewport.height - (anchor.y + anchor.height);
|
|
95
|
+
}
|
|
96
|
+
else if (currentBase === 'bottom') {
|
|
97
|
+
currentSpace = viewport.height - (anchor.y + anchor.height);
|
|
98
|
+
oppositeSpace = anchor.y;
|
|
99
|
+
}
|
|
100
|
+
else if (currentBase === 'left') {
|
|
101
|
+
currentSpace = anchor.x;
|
|
102
|
+
oppositeSpace = viewport.width - (anchor.x + anchor.width);
|
|
103
|
+
}
|
|
104
|
+
else if (currentBase === 'right') {
|
|
105
|
+
currentSpace = viewport.width - (anchor.x + anchor.width);
|
|
106
|
+
oppositeSpace = anchor.x;
|
|
107
|
+
}
|
|
108
|
+
// Flip if opposite side has more space or fits
|
|
109
|
+
if (oppositeSpace > currentSpace) {
|
|
110
|
+
currentBase = oppositeBase;
|
|
111
|
+
coords = oppositeCoords;
|
|
112
|
+
flipped = true;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
let finalX = coords.x;
|
|
117
|
+
let finalY = coords.y;
|
|
118
|
+
let shifted = false;
|
|
119
|
+
// Shift along cross-axis to stay within viewport
|
|
120
|
+
if (shift) {
|
|
121
|
+
const minX = viewportPadding;
|
|
122
|
+
const maxX = Math.max(viewportPadding, viewport.width - effectiveFloating.width - viewportPadding);
|
|
123
|
+
const minY = viewportPadding;
|
|
124
|
+
const maxY = Math.max(viewportPadding, viewport.height - effectiveFloating.height - viewportPadding);
|
|
125
|
+
const clampedX = Math.min(Math.max(finalX, minX), maxX);
|
|
126
|
+
const clampedY = Math.min(Math.max(finalY, minY), maxY);
|
|
127
|
+
if (clampedX !== finalX || clampedY !== finalY) {
|
|
128
|
+
shifted = true;
|
|
129
|
+
finalX = clampedX;
|
|
130
|
+
finalY = clampedY;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// Calculate arrow position (relative to floating element top-left)
|
|
134
|
+
let arrow;
|
|
135
|
+
if (currentBase === 'top' || currentBase === 'bottom') {
|
|
136
|
+
const anchorCenter = anchor.x + anchor.width / 2;
|
|
137
|
+
const rawArrowX = anchorCenter - finalX;
|
|
138
|
+
const minArrowX = arrowPadding;
|
|
139
|
+
const maxArrowX = Math.max(arrowPadding, effectiveFloating.width - arrowPadding);
|
|
140
|
+
arrow = {
|
|
141
|
+
x: Math.min(Math.max(rawArrowX, minArrowX), maxArrowX),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
const anchorCenter = anchor.y + anchor.height / 2;
|
|
146
|
+
const rawArrowY = anchorCenter - finalY;
|
|
147
|
+
const minArrowY = arrowPadding;
|
|
148
|
+
const maxArrowY = Math.max(arrowPadding, effectiveFloating.height - arrowPadding);
|
|
149
|
+
arrow = {
|
|
150
|
+
y: Math.min(Math.max(rawArrowY, minArrowY), maxArrowY),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
// Calculate available dimensions for the floating content
|
|
154
|
+
let availableWidth = Math.max(0, viewport.width - 2 * viewportPadding);
|
|
155
|
+
let availableHeight = Math.max(0, viewport.height - 2 * viewportPadding);
|
|
156
|
+
if (currentBase === 'top') {
|
|
157
|
+
availableHeight = Math.max(0, anchor.y - offset - viewportPadding);
|
|
158
|
+
}
|
|
159
|
+
else if (currentBase === 'bottom') {
|
|
160
|
+
availableHeight = Math.max(0, viewport.height - (anchor.y + anchor.height) - offset - viewportPadding);
|
|
161
|
+
}
|
|
162
|
+
else if (currentBase === 'left') {
|
|
163
|
+
availableWidth = Math.max(0, anchor.x - offset - viewportPadding);
|
|
164
|
+
}
|
|
165
|
+
else if (currentBase === 'right') {
|
|
166
|
+
availableWidth = Math.max(0, viewport.width - (anchor.x + anchor.width) - offset - viewportPadding);
|
|
167
|
+
}
|
|
168
|
+
// Detect whether the anchor reference is hidden (scrolled completely off-screen)
|
|
169
|
+
const referenceHidden = anchor.y + anchor.height < 0 ||
|
|
170
|
+
anchor.y > viewport.height ||
|
|
171
|
+
anchor.x + anchor.width < 0 ||
|
|
172
|
+
anchor.x > viewport.width;
|
|
173
|
+
const finalPlacement = currentAlign === 'center' ? currentBase : `${currentBase}-${currentAlign}`;
|
|
174
|
+
return {
|
|
175
|
+
x: Math.round(finalX),
|
|
176
|
+
y: Math.round(finalY),
|
|
177
|
+
placement: finalPlacement,
|
|
178
|
+
basePlacement: currentBase,
|
|
179
|
+
alignment: currentAlign,
|
|
180
|
+
flipped,
|
|
181
|
+
shifted,
|
|
182
|
+
referenceHidden,
|
|
183
|
+
anchorWidth: Math.round(anchor.width),
|
|
184
|
+
availableDimensions: {
|
|
185
|
+
width: Math.round(availableWidth),
|
|
186
|
+
height: Math.round(availableHeight),
|
|
187
|
+
},
|
|
188
|
+
arrow,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=floating-geometry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"floating-geometry.js","sourceRoot":"","sources":["../src/floating-geometry.ts"],"names":[],"mappings":"AA0DA,MAAM,UAAU,cAAc,CAAC,SAAoB;IAIjD,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAA2C,CAAA;IACpF,OAAO;QACL,aAAa,EAAE,IAAI;QACnB,SAAS,EAAE,KAAK,IAAI,QAAQ;KAC7B,CAAA;AACH,CAAC;AAED,SAAS,eAAe,CAAC,IAAmB;IAC1C,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,KAAK;YACR,OAAO,QAAQ,CAAA;QACjB,KAAK,QAAQ;YACX,OAAO,KAAK,CAAA;QACd,KAAK,MAAM;YACT,OAAO,OAAO,CAAA;QAChB,KAAK,OAAO;YACV,OAAO,MAAM,CAAA;IACjB,CAAC;AACH,CAAC;AAED,SAAS,kBAAkB,CACzB,MAAY,EACZ,QAAc,EACd,IAAmB,EACnB,KAAgB,EAChB,MAAc,EACd,eAAuB;IAEvB,IAAI,CAAC,GAAG,CAAC,CAAA;IACT,IAAI,CAAC,GAAG,CAAC,CAAA;IAET,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;QACnB,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAA;IACzC,CAAC;SAAM,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,CAAC,GAAG,MAAM,C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AE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;QACrB,SAAS,EAAE,cAAc;QACzB,aAAa,EAAE,WAAW;QAC1B,SAAS,EAAE,YAAY;QACvB,OAAO;QACP,OAAO;QACP,eAAe;QACf,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;QACrC,mBAAmB,EAAE;YACnB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC;YACjC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC;SACpC;QACD,KAAK;KACN,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode, type RefObject } from 'react';
|
|
2
|
+
import { type ComputePositionOptions, type PositionResult } from './floating-geometry.ts';
|
|
3
|
+
export interface UseFloatingPositionOptions extends ComputePositionOptions {
|
|
4
|
+
anchorRef: RefObject<HTMLElement | null>;
|
|
5
|
+
floatingRef: RefObject<HTMLElement | null>;
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Universal React hook for floating element positioning on Web.
|
|
10
|
+
* Automatically recalculates position on scroll, resize, and element dimension changes.
|
|
11
|
+
*/
|
|
12
|
+
export declare function useFloatingPosition({ anchorRef, floatingRef, enabled, placement, offset, crossAxisOffset, flip, shift, viewportPadding, arrowPadding, matchAnchorWidth, }: UseFloatingPositionOptions): PositionResult | null;
|
|
13
|
+
export interface FloatingPositionerProps extends ComputePositionOptions {
|
|
14
|
+
children?: ReactNode | ((position: PositionResult | null) => ReactNode);
|
|
15
|
+
anchorRef: RefObject<HTMLElement | null>;
|
|
16
|
+
className?: string;
|
|
17
|
+
style?: CSSProperties;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Universal `<FloatingPositioner>` component for Web.
|
|
21
|
+
* Popper/Floating-UI equivalent positioning container that attaches to an anchor element.
|
|
22
|
+
*/
|
|
23
|
+
export declare function FloatingPositioner({ children, anchorRef, className, style, ...options }: FloatingPositionerProps): import("react").JSX.Element;
|
|
24
|
+
//# sourceMappingURL=floating-positioner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"floating-positioner.d.ts","sourceRoot":"","sources":["../src/floating-positioner.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,SAAS,EAKf,MAAM,OAAO,CAAA;AACd,OAAO,EACL,KAAK,sBAAsB,EAE3B,KAAK,cAAc,EACpB,MAAM,wBAAwB,CAAA;AAE/B,MAAM,WAAW,0BAA2B,SAAQ,sBAAsB;IACxE,SAAS,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IACxC,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IAC1C,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,SAAS,EACT,WAAW,EACX,OAAc,EACd,SAAoB,EACpB,MAAU,EACV,eAAmB,EACnB,IAAW,EACX,KAAY,EACZ,eAAmB,EACnB,YAAgB,EAChB,gBAAwB,GACzB,EAAE,0BAA0B,GAAG,cAAc,GAAG,IAAI,CA+EpD;AAED,MAAM,WAAW,uBAAwB,SAAQ,sBAAsB;IACrE,QAAQ,CAAC,EAAE,SAAS,GAAG,CAAC,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI,KAAK,SAAS,CAAC,CAAA;IACvE,SAAS,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IACxC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,aAAa,CAAA;CACtB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,QAAQ,EACR,SAAS,EACT,SAAS,EACT,KAAK,EACL,GAAG,OAAO,EACX,EAAE,uBAAuB,+BAqCzB"}
|