v-float 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 +210 -0
- package/dist/composables/index.d.ts +7 -0
- package/dist/composables/index.d.ts.map +1 -0
- package/dist/composables/interactions/index.d.ts +6 -0
- package/dist/composables/interactions/index.d.ts.map +1 -0
- package/dist/composables/interactions/use-click.d.ts +52 -0
- package/dist/composables/interactions/use-click.d.ts.map +1 -0
- package/dist/composables/interactions/use-client-point.d.ts +58 -0
- package/dist/composables/interactions/use-client-point.d.ts.map +1 -0
- package/dist/composables/interactions/use-dismiss.d.ts +68 -0
- package/dist/composables/interactions/use-dismiss.d.ts.map +1 -0
- package/dist/composables/interactions/use-focus.d.ts +30 -0
- package/dist/composables/interactions/use-focus.d.ts.map +1 -0
- package/dist/composables/interactions/use-hover.d.ts +64 -0
- package/dist/composables/interactions/use-hover.d.ts.map +1 -0
- package/dist/composables/middlewares/arrow.d.ts +26 -0
- package/dist/composables/middlewares/arrow.d.ts.map +1 -0
- package/dist/composables/middlewares/index.d.ts +3 -0
- package/dist/composables/middlewares/index.d.ts.map +1 -0
- package/dist/composables/use-arrow.d.ts +46 -0
- package/dist/composables/use-arrow.d.ts.map +1 -0
- package/dist/composables/use-floating-tree.d.ts +48 -0
- package/dist/composables/use-floating-tree.d.ts.map +1 -0
- package/dist/composables/use-floating.d.ts +161 -0
- package/dist/composables/use-floating.d.ts.map +1 -0
- package/dist/composables/use-tree.d.ts +151 -0
- package/dist/composables/use-tree.d.ts.map +1 -0
- package/dist/composables/utils/dom.d.ts +11 -0
- package/dist/composables/utils/dom.d.ts.map +1 -0
- package/dist/composables/utils/use-composition.d.ts +4 -0
- package/dist/composables/utils/use-composition.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/dom.d.ts +9 -0
- package/dist/utils/dom.d.ts.map +1 -0
- package/dist/utils/id.d.ts +2 -0
- package/dist/utils/id.d.ts.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/reactivity.d.ts +2 -0
- package/dist/utils/reactivity.d.ts.map +1 -0
- package/dist/utils/type-guards.d.ts +8 -0
- package/dist/utils/type-guards.d.ts.map +1 -0
- package/dist/v-float.es.js +1956 -0
- package/dist/v-float.umd.js +1 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 V-Float
|
|
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,210 @@
|
|
|
1
|
+
# V-Float
|
|
2
|
+
|
|
3
|
+
A Vue 3 library for positioning floating UI elements like tooltips, popovers, dropdowns, and modals. Built on top of [VFloat](https://vfloat.pages.com/) with Vue 3 Composition API.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Precise Positioning**: Pixel-perfect positioning with automatic collision detection
|
|
8
|
+
- **Vue 3 Composables**: Reactive composables designed for the Composition API
|
|
9
|
+
- **Interaction Handling**: Built-in hover, focus, click, and dismiss behaviors
|
|
10
|
+
- **Nested Elements**: Support for floating element trees and hierarchies
|
|
11
|
+
- **Ready-to-use Components**: Pre-built components like `FloatingArrow`
|
|
12
|
+
- **Lightweight**: Tree-shakable with minimal bundle impact
|
|
13
|
+
- **Cross-platform**: Works on desktop, mobile, and touch devices
|
|
14
|
+
- **TypeScript**: Full TypeScript support with comprehensive type definitions
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
# With pnpm (recommended)
|
|
20
|
+
pnpm add v-float
|
|
21
|
+
|
|
22
|
+
# With npm
|
|
23
|
+
npm install v-float
|
|
24
|
+
|
|
25
|
+
# With yarn
|
|
26
|
+
yarn add v-float
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
### Basic Tooltip
|
|
32
|
+
|
|
33
|
+
```vue
|
|
34
|
+
<script setup lang="ts">
|
|
35
|
+
import { useTemplateRef } from "vue"
|
|
36
|
+
import { useFloating, useHover, offset } from "v-float"
|
|
37
|
+
|
|
38
|
+
const anchorEl = useTemplateRef("anchorEl")
|
|
39
|
+
const floatingEl = useTemplateRef("floatingEl")
|
|
40
|
+
|
|
41
|
+
const context = useFloating(anchorEl, floatingEl, {
|
|
42
|
+
placement: "top",
|
|
43
|
+
middlewares: [offset(8)],
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
useHover(context)
|
|
47
|
+
</script>
|
|
48
|
+
|
|
49
|
+
<template>
|
|
50
|
+
<button ref="anchorEl">Hover me</button>
|
|
51
|
+
|
|
52
|
+
<div v-if="context.open.value" ref="floatingEl" :style="context.floatingStyles.value">
|
|
53
|
+
This is a tooltip
|
|
54
|
+
</div>
|
|
55
|
+
</template>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Dropdown Menu
|
|
59
|
+
|
|
60
|
+
```vue
|
|
61
|
+
<script setup lang="ts">
|
|
62
|
+
import { useTemplateRef } from "vue"
|
|
63
|
+
import { useFloating, useClick, useDismiss, offset, flip, shift } from "v-float"
|
|
64
|
+
|
|
65
|
+
const triggerEl = useTemplateRef("triggerEl")
|
|
66
|
+
const menuEl = useTemplateRef("menuEl")
|
|
67
|
+
|
|
68
|
+
const context = useFloating(triggerEl, menuEl, {
|
|
69
|
+
placement: "bottom-start",
|
|
70
|
+
middlewares: [offset(4), flip(), shift({ padding: 8 })],
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
useClick(context)
|
|
74
|
+
useDismiss(context)
|
|
75
|
+
</script>
|
|
76
|
+
|
|
77
|
+
<template>
|
|
78
|
+
<button ref="triggerEl">Open Menu</button>
|
|
79
|
+
|
|
80
|
+
<div v-if="context.open.value" ref="menuEl" :style="context.floatingStyles.value">
|
|
81
|
+
<div>Menu Item 1</div>
|
|
82
|
+
<div>Menu Item 2</div>
|
|
83
|
+
<div>Menu Item 3</div>
|
|
84
|
+
</div>
|
|
85
|
+
</template>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Core Composables
|
|
89
|
+
|
|
90
|
+
### Positioning
|
|
91
|
+
|
|
92
|
+
- **`useFloating`**: Core positioning logic with middleware support
|
|
93
|
+
- **`useArrow`**: Position arrow elements pointing to the anchor
|
|
94
|
+
- **`useFloatingTree`**: Manage nested floating element hierarchies
|
|
95
|
+
|
|
96
|
+
### Interactions
|
|
97
|
+
|
|
98
|
+
- **`useHover`**: Hover interactions with configurable delays and safe areas
|
|
99
|
+
- **`useFocus`**: Focus/blur event handling for keyboard navigation
|
|
100
|
+
- **`useClick`**: Click event handling with toggle and dismiss options
|
|
101
|
+
- **`useDismiss`**: Close on outside click, ESC key, or scroll events
|
|
102
|
+
- **`useClientPoint`**: Position floating elements at cursor/touch coordinates
|
|
103
|
+
|
|
104
|
+
### Middleware
|
|
105
|
+
|
|
106
|
+
All [Floating UI middleware](https://floating-ui.com/docs/middleware) are supported:
|
|
107
|
+
|
|
108
|
+
- **`offset`**: Add distance between anchor and floating element
|
|
109
|
+
- **`flip`**: Flip placement when there's insufficient space
|
|
110
|
+
- **`shift`**: Shift floating element to stay in view
|
|
111
|
+
- **`hide`**: Hide floating element when anchor is not visible
|
|
112
|
+
- **`arrow`**: Position arrow elements (via `useArrow`)
|
|
113
|
+
|
|
114
|
+
## Components
|
|
115
|
+
|
|
116
|
+
### FloatingArrow
|
|
117
|
+
|
|
118
|
+
Pre-built SVG arrow component with automatic positioning:
|
|
119
|
+
|
|
120
|
+
```vue
|
|
121
|
+
<script setup lang="ts">
|
|
122
|
+
import { FloatingArrow, useFloating, useArrow } from "v-float"
|
|
123
|
+
|
|
124
|
+
const context = useFloating(anchorEl, floatingEl, {
|
|
125
|
+
middlewares: [arrow({ element: arrowEl })],
|
|
126
|
+
})
|
|
127
|
+
</script>
|
|
128
|
+
|
|
129
|
+
<template>
|
|
130
|
+
<div ref="floatingEl" :style="context.floatingStyles.value">
|
|
131
|
+
Tooltip content
|
|
132
|
+
<FloatingArrow :context="context" fill="white" />
|
|
133
|
+
</div>
|
|
134
|
+
</template>
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Advanced Features
|
|
138
|
+
|
|
139
|
+
### Floating Trees
|
|
140
|
+
|
|
141
|
+
For nested floating elements like submenus:
|
|
142
|
+
|
|
143
|
+
```vue
|
|
144
|
+
<script setup lang="ts">
|
|
145
|
+
import { useFloatingTree, useFloating } from "v-float"
|
|
146
|
+
|
|
147
|
+
// Parent menu
|
|
148
|
+
const parentTree = useFloatingTree()
|
|
149
|
+
const parentContext = useFloating(triggerEl, menuEl, {
|
|
150
|
+
tree: parentTree,
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
// Submenu
|
|
154
|
+
const submenuContext = useFloating(submenuTriggerEl, submenuEl, {
|
|
155
|
+
tree: parentTree,
|
|
156
|
+
})
|
|
157
|
+
</script>
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Virtual Elements
|
|
161
|
+
|
|
162
|
+
Position relative to virtual coordinates:
|
|
163
|
+
|
|
164
|
+
```vue
|
|
165
|
+
<script setup lang="ts">
|
|
166
|
+
import { useFloating, useClientPoint } from "v-float"
|
|
167
|
+
|
|
168
|
+
const virtualEl = ref({
|
|
169
|
+
getBoundingClientRect: () => ({
|
|
170
|
+
x: 100,
|
|
171
|
+
y: 100,
|
|
172
|
+
width: 0,
|
|
173
|
+
height: 0,
|
|
174
|
+
top: 100,
|
|
175
|
+
left: 100,
|
|
176
|
+
right: 100,
|
|
177
|
+
bottom: 100,
|
|
178
|
+
}),
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
const context = useFloating(virtualEl, floatingEl)
|
|
182
|
+
useClientPoint(context) // Follow mouse cursor
|
|
183
|
+
</script>
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## TypeScript Support
|
|
187
|
+
|
|
188
|
+
V-Float is built with TypeScript and provides comprehensive type definitions:
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
import type { FloatingContext, UseFloatingOptions, AnchorElement, FloatingElement } from "v-float"
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Browser Support
|
|
195
|
+
|
|
196
|
+
- **Modern browsers**: Chrome, Firefox, Safari, Edge
|
|
197
|
+
- **Mobile browsers**: iOS Safari, Chrome Mobile, Samsung Internet
|
|
198
|
+
- **Node.js**: SSR compatible (with proper hydration)
|
|
199
|
+
|
|
200
|
+
## Documentation
|
|
201
|
+
|
|
202
|
+
For complete documentation with interactive examples, visit the [V-Float Documentation](https://v-float.com).
|
|
203
|
+
|
|
204
|
+
## Contributing
|
|
205
|
+
|
|
206
|
+
Contributions are welcome! Please read our contributing guidelines and submit pull requests to our [GitHub repository](https://github.com/v-float/v-float).
|
|
207
|
+
|
|
208
|
+
## License
|
|
209
|
+
|
|
210
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/composables/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,qBAAqB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/composables/interactions/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { MaybeRefOrGetter } from 'vue';
|
|
2
|
+
import { FloatingContext } from '..';
|
|
3
|
+
/**
|
|
4
|
+
* Enables showing/hiding the floating element when clicking the reference element.
|
|
5
|
+
*
|
|
6
|
+
* This composable provides event handlers for click interactions with the reference element
|
|
7
|
+
* to control the visibility of the floating element.
|
|
8
|
+
*
|
|
9
|
+
* @param context - The floating context with open state and change handler.
|
|
10
|
+
* @param options - Configuration options for click behavior.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const context = useFloating(...)
|
|
15
|
+
* useClick(context, {
|
|
16
|
+
* event: "mousedown",
|
|
17
|
+
* })
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function useClick(context: FloatingContext, options?: UseClickOptions): void;
|
|
21
|
+
/**
|
|
22
|
+
* Options for configuring the useClick behavior.
|
|
23
|
+
*/
|
|
24
|
+
export interface UseClickOptions {
|
|
25
|
+
/**
|
|
26
|
+
* Whether the Hook is enabled.
|
|
27
|
+
* @default true
|
|
28
|
+
*/
|
|
29
|
+
enabled?: MaybeRefOrGetter<boolean>;
|
|
30
|
+
/**
|
|
31
|
+
* The type of event to use to determine a "click" with mouse input.
|
|
32
|
+
* Keyboard clicks work as normal.
|
|
33
|
+
* @default 'click'
|
|
34
|
+
*/
|
|
35
|
+
event?: MaybeRefOrGetter<"click" | "mousedown">;
|
|
36
|
+
/**
|
|
37
|
+
* Whether to toggle the open state with repeated clicks.
|
|
38
|
+
* @default true
|
|
39
|
+
*/
|
|
40
|
+
toggle?: MaybeRefOrGetter<boolean>;
|
|
41
|
+
/**
|
|
42
|
+
* Whether to ignore the logic for mouse input.
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
ignoreMouse?: MaybeRefOrGetter<boolean>;
|
|
46
|
+
/**
|
|
47
|
+
* Whether to add keyboard handlers (Enter and Space key functionality).
|
|
48
|
+
* @default true
|
|
49
|
+
*/
|
|
50
|
+
keyboardHandlers?: MaybeRefOrGetter<boolean>;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=use-click.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-click.d.ts","sourceRoot":"","sources":["../../../src/composables/interactions/use-click.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,gBAAgB,EAA8C,MAAM,KAAK,CAAA;AACjG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAMpD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,GAAE,eAAoB,GAAG,IAAI,CA4HtF;AAqDD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,OAAO,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAA;IAEnC;;;;OAIG;IACH,KAAK,CAAC,EAAE,gBAAgB,CAAC,OAAO,GAAG,WAAW,CAAC,CAAA;IAE/C;;;OAGG;IACH,MAAM,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAA;IAElC;;;OAGG;IACH,WAAW,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAA;IAEvC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAA;CAC7C"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { MaybeRefOrGetter, Ref } from 'vue';
|
|
2
|
+
import { FloatingContext } from '..';
|
|
3
|
+
/**
|
|
4
|
+
* Positions the floating element relative to a client point (mouse position).
|
|
5
|
+
*
|
|
6
|
+
* This composable tracks pointer movements and positions the floating element
|
|
7
|
+
* accordingly, with options for axis locking and controlled coordinates.
|
|
8
|
+
*
|
|
9
|
+
* @param pointerTarget - The DOM element whose bounding box is used as the reference for pointer event listeners and initial positioning.
|
|
10
|
+
* @param context - The floating context with open state and position reference
|
|
11
|
+
* @param options - Configuration options for client point behavior
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const context = useFloating(...)
|
|
16
|
+
* useClientPoint(context, {
|
|
17
|
+
* axis: "x",
|
|
18
|
+
* enabled: true
|
|
19
|
+
* })
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function useClientPoint(pointerTarget: Ref<HTMLElement | null>, context: FloatingContext, options?: UseClientPointOptions): UseClientPointReturn;
|
|
23
|
+
export interface UseClientPointOptions {
|
|
24
|
+
/**
|
|
25
|
+
* Whether the Hook is enabled
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
28
|
+
enabled?: MaybeRefOrGetter<boolean>;
|
|
29
|
+
/**
|
|
30
|
+
* Whether to restrict the client point to an axis
|
|
31
|
+
* @default 'both'
|
|
32
|
+
*/
|
|
33
|
+
axis?: MaybeRefOrGetter<"x" | "y" | "both">;
|
|
34
|
+
/**
|
|
35
|
+
* Controlled x coordinate
|
|
36
|
+
* @default null
|
|
37
|
+
*/
|
|
38
|
+
x?: MaybeRefOrGetter<number | null>;
|
|
39
|
+
/**
|
|
40
|
+
* Controlled y coordinate
|
|
41
|
+
* @default null
|
|
42
|
+
*/
|
|
43
|
+
y?: MaybeRefOrGetter<number | null>;
|
|
44
|
+
}
|
|
45
|
+
export interface UseClientPointReturn {
|
|
46
|
+
/**
|
|
47
|
+
* Reactive object containing the current client coordinates (x/y)
|
|
48
|
+
*/
|
|
49
|
+
coordinates: Readonly<Ref<{
|
|
50
|
+
x: number | null;
|
|
51
|
+
y: number | null;
|
|
52
|
+
}>>;
|
|
53
|
+
/**
|
|
54
|
+
* Function to manually update the floating element's position
|
|
55
|
+
*/
|
|
56
|
+
updatePosition: (x: number, y: number) => void;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=use-client-point.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-client-point.d.ts","sourceRoot":"","sources":["../../../src/composables/interactions/use-client-point.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,gBAAgB,EAGrB,KAAK,GAAG,EAIT,MAAM,KAAK,CAAA;AACZ,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAOpD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,cAAc,CAC5B,aAAa,EAAE,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,EACtC,OAAO,EAAE,eAAe,EACxB,OAAO,GAAE,qBAA0B,GAClC,oBAAoB,CA4EtB;AAoGD,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,OAAO,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAA;IAEnC;;;OAGG;IACH,IAAI,CAAC,EAAE,gBAAgB,CAAC,GAAG,GAAG,GAAG,GAAG,MAAM,CAAC,CAAA;IAE3C;;;OAGG;IACH,CAAC,CAAC,EAAE,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;IAEnC;;;OAGG;IACH,CAAC,CAAC,EAAE,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;CACpC;AAED,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,WAAW,EAAE,QAAQ,CAAC,GAAG,CAAC;QAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC,CAAA;IAClE;;OAEG;IACH,cAAc,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;CAC/C"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { MaybeRefOrGetter } from 'vue';
|
|
2
|
+
import { FloatingContext } from '../use-floating';
|
|
3
|
+
export type DismissReason = "escape-key" | "outside-press" | "anchor-press" | "ancestor-scroll";
|
|
4
|
+
export interface UseDismissProps {
|
|
5
|
+
/**
|
|
6
|
+
* Whether dismiss event listeners are enabled.
|
|
7
|
+
* @default true
|
|
8
|
+
*/
|
|
9
|
+
enabled?: MaybeRefOrGetter<boolean>;
|
|
10
|
+
/**
|
|
11
|
+
* Whether to dismiss when the escape key is pressed.
|
|
12
|
+
* @default true
|
|
13
|
+
*/
|
|
14
|
+
escapeKey?: MaybeRefOrGetter<boolean>;
|
|
15
|
+
/**
|
|
16
|
+
* Whether to dismiss when the anchor element is pressed.
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
anchorPress?: MaybeRefOrGetter<boolean>;
|
|
20
|
+
/**
|
|
21
|
+
* Whether to dismiss when clicking outside the floating and anchor element.
|
|
22
|
+
* Can be a function to allow custom logic.
|
|
23
|
+
* @default true
|
|
24
|
+
*/
|
|
25
|
+
outsidePress?: MaybeRefOrGetter<boolean | ((event: MouseEvent) => boolean)>;
|
|
26
|
+
/**
|
|
27
|
+
* Whether to dismiss when a scrollable ancestor of the floating element is scrolled.
|
|
28
|
+
* @default false
|
|
29
|
+
*/
|
|
30
|
+
ancestorScroll?: MaybeRefOrGetter<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Whether to use capture phase for document event listeners.
|
|
33
|
+
* @default { escapeKey: false, outsidePress: true }
|
|
34
|
+
*/
|
|
35
|
+
capture?: boolean | {
|
|
36
|
+
escapeKey?: boolean;
|
|
37
|
+
outsidePress?: boolean;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* The event name to use for anchor press.
|
|
41
|
+
* @default 'pointerdown'
|
|
42
|
+
*/
|
|
43
|
+
anchorPressEvent?: "pointerdown" | "mousedown" | "click";
|
|
44
|
+
/**
|
|
45
|
+
* The event name to use for outside press.
|
|
46
|
+
* @default 'pointerdown'
|
|
47
|
+
*/
|
|
48
|
+
outsidePressEvent?: "pointerdown" | "mousedown" | "click";
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Closes the floating element when a dismissal is requested.
|
|
52
|
+
*
|
|
53
|
+
* This composable provides event handlers for dismissal behaviors including
|
|
54
|
+
* outside clicks, escape key press, anchor element press, and ancestor scroll.
|
|
55
|
+
*
|
|
56
|
+
* @param context - The floating context with open state and change handler.
|
|
57
|
+
* @param options - Configuration options for dismissal behavior.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* useDismiss(context, {
|
|
62
|
+
* escapeKey: true,
|
|
63
|
+
* outsidePress: (event) => !event.target.closest('.toast'),
|
|
64
|
+
* })
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare function useDismiss(context: FloatingContext, options?: UseDismissProps): void;
|
|
68
|
+
//# sourceMappingURL=use-dismiss.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-dismiss.d.ts","sourceRoot":"","sources":["../../../src/composables/interactions/use-dismiss.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,gBAAgB,EAAkD,MAAM,KAAK,CAAA;AAC3F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAQtD,MAAM,MAAM,aAAa,GAAG,YAAY,GAAG,eAAe,GAAG,cAAc,GAAG,iBAAiB,CAAA;AAE/F,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,OAAO,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAA;IAEnC;;;OAGG;IACH,SAAS,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAA;IAErC;;;OAGG;IACH,WAAW,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAA;IAEvC;;;;OAIG;IACH,YAAY,CAAC,EAAE,gBAAgB,CAAC,OAAO,GAAG,CAAC,CAAC,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC,CAAC,CAAA;IAE3E;;;OAGG;IACH,cAAc,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAA;IAE1C;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,GAAG;QAAE,SAAS,CAAC,EAAE,OAAO,CAAC;QAAC,YAAY,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;IAEnE;;;OAGG;IACH,gBAAgB,CAAC,EAAE,aAAa,GAAG,WAAW,GAAG,OAAO,CAAA;IAExD;;;OAGG;IACH,iBAAiB,CAAC,EAAE,aAAa,GAAG,WAAW,GAAG,OAAO,CAAA;CAC1D;AAMD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,GAAE,eAAoB,GAAG,IAAI,CAqIxF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { FloatingContext } from '..';
|
|
2
|
+
import { MaybeRefOrGetter } from 'vue';
|
|
3
|
+
/**
|
|
4
|
+
* Enables showing/hiding the floating element when focusing the reference element.
|
|
5
|
+
*
|
|
6
|
+
* This composable is responsible for KEYBOARD-ONLY interactions. For a complete user experience,
|
|
7
|
+
* it should be composed with other hooks like `useClick`, `useHover`, and `useDismiss`.
|
|
8
|
+
*
|
|
9
|
+
* @param context - The floating context with open state and change handler.
|
|
10
|
+
* @param options - Configuration options for focus behavior.
|
|
11
|
+
*/
|
|
12
|
+
export declare function useFocus(context: FloatingContext, options?: UseFocusOptions): UseFocusReturn;
|
|
13
|
+
export interface UseFocusOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Whether focus event listeners are enabled
|
|
16
|
+
* @default true
|
|
17
|
+
*/
|
|
18
|
+
enabled?: MaybeRefOrGetter<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* Whether the open state only changes if the focus event is considered
|
|
21
|
+
* visible (`:focus-visible` CSS selector).
|
|
22
|
+
* @default true
|
|
23
|
+
*/
|
|
24
|
+
requireFocusVisible?: MaybeRefOrGetter<boolean>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Return value of the useFocus composable
|
|
28
|
+
*/
|
|
29
|
+
export type UseFocusReturn = undefined;
|
|
30
|
+
//# sourceMappingURL=use-focus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-focus.d.ts","sourceRoot":"","sources":["../../../src/composables/interactions/use-focus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAEpD,OAAO,EAEL,KAAK,gBAAgB,EAMtB,MAAM,KAAK,CAAA;AAMZ;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,GAAE,eAAoB,GAAG,cAAc,CA+HhG;AAMD,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,OAAO,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAA;IAEnC;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAA;CAChD;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,SAAS,CAAA"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { MaybeRef } from 'vue';
|
|
2
|
+
import { FloatingContext, FloatingElement, AnchorElement } from '../use-floating';
|
|
3
|
+
type PointerType = "mouse" | "pen" | "touch" | null;
|
|
4
|
+
export interface HandleCloseContext {
|
|
5
|
+
context: FloatingContext;
|
|
6
|
+
open: boolean;
|
|
7
|
+
pointerType: PointerType;
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
referenceEl: AnchorElement;
|
|
11
|
+
floatingEl: FloatingElement;
|
|
12
|
+
isPointInFloating(event: PointerEvent | MouseEvent | TouchEvent): boolean;
|
|
13
|
+
originalEvent?: Event;
|
|
14
|
+
}
|
|
15
|
+
export type HandleCloseFn = (context: HandleCloseContext, onClose: () => void) => undefined | (() => void);
|
|
16
|
+
export interface UseHoverOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Whether hover event listeners are enabled.
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
enabled?: MaybeRef<boolean>;
|
|
22
|
+
/**
|
|
23
|
+
* Delay in milliseconds before showing/hiding the floating element.
|
|
24
|
+
* Can be a single number for both open and close, or an object
|
|
25
|
+
* specifying different delays.
|
|
26
|
+
* @default 0
|
|
27
|
+
*/
|
|
28
|
+
delay?: MaybeRef<number | {
|
|
29
|
+
open?: number;
|
|
30
|
+
close?: number;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* Time in milliseconds the pointer must rest within the reference
|
|
34
|
+
* element before opening the floating element.
|
|
35
|
+
* this option is ignored if an open delay is specified.
|
|
36
|
+
* @default 0
|
|
37
|
+
*/
|
|
38
|
+
restMs?: MaybeRef<number>;
|
|
39
|
+
/**
|
|
40
|
+
* Whether hover events should only trigger for mouse like pointers (mouse, pen ,stylus ..etc).
|
|
41
|
+
* @default false
|
|
42
|
+
*/
|
|
43
|
+
mouseOnly?: MaybeRef<boolean>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Enables showing/hiding the floating element when hovering the reference element
|
|
47
|
+
* with enhanced behaviors like delayed open/close, rest detection, and custom
|
|
48
|
+
* exit handling.
|
|
49
|
+
*
|
|
50
|
+
* @param context - The floating context with open state and change handler
|
|
51
|
+
* @param options - Configuration options for hover behavior
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const context = useFloating(...)
|
|
56
|
+
* useHover(context, {
|
|
57
|
+
* delay: { open: 100, close: 300 },
|
|
58
|
+
* restMs: 150
|
|
59
|
+
* })
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function useHover(context: FloatingContext, options?: UseHoverOptions): void;
|
|
63
|
+
export {};
|
|
64
|
+
//# sourceMappingURL=use-hover.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-hover.d.ts","sourceRoot":"","sources":["../../../src/composables/interactions/use-hover.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,QAAQ,EAMd,MAAM,KAAK,CAAA;AACZ,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAMtF,KAAK,WAAW,GAAG,OAAO,GAAG,KAAK,GAAG,OAAO,GAAG,IAAI,CAAA;AAEnD,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,eAAe,CAAA;IACxB,IAAI,EAAE,OAAO,CAAA;IACb,WAAW,EAAE,WAAW,CAAA;IACxB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,WAAW,EAAE,aAAa,CAAA;IAC1B,UAAU,EAAE,eAAe,CAAA;IAC3B,iBAAiB,CAAC,KAAK,EAAE,YAAY,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,CAAA;IACzE,aAAa,CAAC,EAAE,KAAK,CAAA;CACtB;AAED,MAAM,MAAM,aAAa,GAAG,CAC1B,OAAO,EAAE,kBAAkB,EAC3B,OAAO,EAAE,MAAM,IAAI,KAChB,SAAS,GAAG,CAAC,MAAM,IAAI,CAAC,CAAA;AAE7B,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,OAAO,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IAE3B;;;;;OAKG;IACH,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,GAAG;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAE5D;;;;;OAKG;IACH,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;IAEzB;;;OAGG;IACH,SAAS,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;CAC9B;AAqED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,GAAE,eAAoB,GAAG,IAAI,CAiJtF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Middleware, Padding } from '@floating-ui/dom';
|
|
2
|
+
import { Ref } from 'vue';
|
|
3
|
+
/**
|
|
4
|
+
* Options for configuring arrow positioning within floating elements
|
|
5
|
+
*/
|
|
6
|
+
export interface ArrowMiddlewareOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Padding to apply around the arrow element
|
|
9
|
+
*/
|
|
10
|
+
padding?: Padding;
|
|
11
|
+
/**
|
|
12
|
+
* Reference to the arrow element
|
|
13
|
+
*/
|
|
14
|
+
element: Ref<HTMLElement | null>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Positions an inner element of the floating element such that it is centered to the reference element.
|
|
18
|
+
*
|
|
19
|
+
* This middleware is used to position arrow elements within floating elements.
|
|
20
|
+
*
|
|
21
|
+
* @param options - The arrow options including padding and element reference
|
|
22
|
+
* @returns A middleware function for arrow positioning
|
|
23
|
+
* @see https://floating-ui.com/docs/arrow
|
|
24
|
+
*/
|
|
25
|
+
export declare function arrow(options: ArrowMiddlewareOptions): Middleware;
|
|
26
|
+
//# sourceMappingURL=arrow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrow.d.ts","sourceRoot":"","sources":["../../../src/composables/middlewares/arrow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAE3D,OAAO,EAAE,KAAK,GAAG,EAAW,MAAM,KAAK,CAAA;AAMvC;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;OAEG;IACH,OAAO,EAAE,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;CACjC;AAMD;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,sBAAsB,GAAG,UAAU,CAcjE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/composables/middlewares/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ComputedRef } from 'vue';
|
|
2
|
+
import { FloatingContext } from './use-floating';
|
|
3
|
+
/**
|
|
4
|
+
* Return value of the useArrow composable
|
|
5
|
+
*/
|
|
6
|
+
export interface UseArrowReturn {
|
|
7
|
+
/**
|
|
8
|
+
* The computed X position of the arrow
|
|
9
|
+
*/
|
|
10
|
+
arrowX: ComputedRef<number>;
|
|
11
|
+
/**
|
|
12
|
+
* The computed Y position of the arrow
|
|
13
|
+
*/
|
|
14
|
+
arrowY: ComputedRef<number>;
|
|
15
|
+
/**
|
|
16
|
+
* The computed CSS styles for positioning the arrow
|
|
17
|
+
*/
|
|
18
|
+
arrowStyles: ComputedRef<Record<string, string>>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Options for the useArrow composable
|
|
22
|
+
*/
|
|
23
|
+
export interface UseArrowOptions {
|
|
24
|
+
/**
|
|
25
|
+
* The offset for the arrow positioning.
|
|
26
|
+
* Defaults to "-12px" if not provided.
|
|
27
|
+
*/
|
|
28
|
+
offset?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Composable for computing arrow position styles for floating elements
|
|
32
|
+
*
|
|
33
|
+
* This composable calculates the position and styles for an arrow element
|
|
34
|
+
* based on the placement and middleware data from a floating element.
|
|
35
|
+
*
|
|
36
|
+
* @param context - The floating context containing middleware data and placement information
|
|
37
|
+
* @param options - Optional configuration for the arrow, e.g., offset
|
|
38
|
+
* @returns Computed arrow positions and CSS styles
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* const { arrowStyles } = useArrow(floatingContext, { offset: "-10px" })
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function useArrow(context: FloatingContext, options?: UseArrowOptions): UseArrowReturn;
|
|
46
|
+
//# sourceMappingURL=use-arrow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-arrow.d.ts","sourceRoot":"","sources":["../../src/composables/use-arrow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,KAAK,CAAA;AAEtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAMrD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IAE3B;;OAEG;IACH,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IAE3B;;OAEG;IACH,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CACjD;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAMD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,GAAE,eAAoB,GAAG,cAAc,CA8BhG"}
|