1
1
import { isElement } from "@floating-ui/utils/dom" ;
2
2
import { useFloatingTree } from "../components/floating-tree/hooks.svelte.js" ;
3
3
import type {
4
+ ContextData ,
4
5
ExtendedElements ,
6
+ FloatingEvents ,
5
7
FloatingTreeType ,
6
8
NarrowedElement ,
7
9
OpenChangeReason ,
@@ -12,6 +14,8 @@ import {
12
14
PositionState ,
13
15
type UsePositionOptions ,
14
16
} from "./use-position.svelte.js" ;
17
+ import type { Placement , Strategy } from "@floating-ui/utils" ;
18
+ import type { MiddlewareData } from "@floating-ui/dom" ;
15
19
16
20
interface UseFloatingOptions < RT extends ReferenceType = ReferenceType >
17
21
extends Omit < UsePositionOptions < RT > , "elements" > {
@@ -47,9 +51,59 @@ type FloatingContextOptions<RT extends ReferenceType = ReferenceType> = {
47
51
getElements : ( state : FloatingState < RT > ) => ExtendedElements < RT > ;
48
52
} ;
49
53
50
- class FloatingContext < RT extends ReferenceType = ReferenceType > {
54
+ interface FloatingContextData < RT extends ReferenceType = ReferenceType > {
55
+ elements : ExtendedElements < RT > ;
56
+ x : number ;
57
+ y : number ;
58
+ placement : Placement ;
59
+ strategy : Strategy ;
60
+ middlewareData : MiddlewareData ;
61
+ isPositioned : boolean ;
62
+ update : ( ) => Promise < void > ;
63
+ floatingStyles : string ;
64
+ onOpenChange : (
65
+ open : boolean ,
66
+ event ?: Event ,
67
+ reason ?: OpenChangeReason ,
68
+ ) => void ;
69
+ open : boolean ;
70
+ data : ContextData < RT > ;
71
+ floatingId : string ;
72
+ events : FloatingEvents ;
73
+ nodeId : string | undefined ;
74
+ }
75
+
76
+ class FloatingContext < RT extends ReferenceType = ReferenceType >
77
+ implements FloatingContextData < RT >
78
+ {
51
79
constructor ( private readonly opts : FloatingContextOptions < RT > ) { }
52
80
81
+ /**
82
+ * INTERNAL ONLY. DO NOT USE.
83
+ *
84
+ * @internal
85
+ */
86
+ // prefix with `z` to push to bottom of intellisense
87
+ readonly z_internal_current : FloatingContextData < RT > = $derived . by ( ( ) => {
88
+ return {
89
+ elements : this . opts . getElements ( this . opts . floating ) ,
90
+ x : this . opts . floating . x ,
91
+ y : this . opts . floating . y ,
92
+ placement : this . opts . floating . placement ,
93
+ strategy : this . opts . floating . strategy ,
94
+ middlewareData : this . opts . floating . middlewareData ,
95
+ isPositioned : this . opts . floating . isPositioned ,
96
+ update : this . opts . floating . update ,
97
+ floatingStyles : this . opts . floating . floatingStyles ,
98
+ onOpenChange : this . opts . rootContext . onOpenChange ,
99
+ open : this . opts . rootContext . open ,
100
+ data : this . opts . rootContext . data ,
101
+ floatingId : this . opts . rootContext . floatingId ,
102
+ events : this . opts . rootContext . events ,
103
+ nodeId : this . opts . floatingOptions . nodeId ,
104
+ } ;
105
+ } ) ;
106
+
53
107
get elements ( ) {
54
108
return this . opts . getElements ( this . opts . floating ) ;
55
109
}
@@ -251,4 +305,4 @@ function useFloating<RT extends ReferenceType = ReferenceType>(
251
305
}
252
306
253
307
export { FloatingState , FloatingContext , useFloating } ;
254
- export type { UseFloatingOptions } ;
308
+ export type { UseFloatingOptions , FloatingContextData } ;
0 commit comments