@pzerelles/headlessui-svelte 2.1.2-next.10 → 2.1.2-next.12
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/dist/hooks/use-controllable.svelte.js +2 -1
- package/dist/hooks/use-did-element-move.svelte.js +5 -10
- package/dist/internal/FloatingProvider.svelte +12 -0
- package/dist/internal/FloatingProvider.svelte.d.ts +22 -0
- package/dist/internal/floating-provider.svelte.d.ts +3 -0
- package/dist/internal/floating-provider.svelte.js +206 -0
- package/dist/internal/floating.svelte.d.ts +48 -23
- package/dist/internal/floating.svelte.js +78 -260
- package/dist/internal/inner.svelte.d.ts +91 -0
- package/dist/internal/inner.svelte.js +202 -0
- package/dist/listbox/Listbox.svelte +38 -52
- package/dist/listbox/Listbox.svelte.d.ts +3 -54
- package/dist/listbox/ListboxButton.svelte +7 -6
- package/dist/listbox/ListboxOption.svelte +7 -3
- package/dist/listbox/ListboxOptions.svelte +50 -50
- package/dist/listbox/context.svelte.d.ts +75 -0
- package/dist/listbox/context.svelte.js +36 -0
- package/dist/menu/Menu.svelte +2 -2
- package/dist/menu/MenuButton.svelte +4 -2
- package/dist/menu/MenuItems.svelte +15 -11
- package/dist/tabs/TabGroup.svelte.d.ts +1 -1
- package/dist/utils/ElementOrComponent.svelte +1 -1
- package/dist/utils/floating-ui/svelte/components/FloatingNode.svelte +17 -0
- package/dist/utils/floating-ui/svelte/components/FloatingNode.svelte.d.ts +23 -0
- package/dist/utils/floating-ui/svelte/components/FloatingTree.svelte +50 -0
- package/dist/utils/floating-ui/svelte/components/FloatingTree.svelte.d.ts +41 -0
- package/dist/utils/floating-ui/svelte/hooks/useFloating.svelte.d.ts +6 -0
- package/dist/utils/floating-ui/svelte/hooks/useFloating.svelte.js +158 -0
- package/dist/utils/floating-ui/svelte/hooks/useFloatingRootContext.svelte.d.ts +11 -0
- package/dist/utils/floating-ui/svelte/hooks/useFloatingRootContext.svelte.js +53 -0
- package/dist/utils/floating-ui/svelte/hooks/useId.svelte.d.ts +9 -0
- package/dist/utils/floating-ui/svelte/hooks/useId.svelte.js +28 -0
- package/dist/utils/floating-ui/svelte/hooks/useInteractions.svelte.d.ts +23 -0
- package/dist/utils/floating-ui/svelte/hooks/useInteractions.svelte.js +72 -0
- package/dist/utils/floating-ui/svelte/index.d.ts +5 -0
- package/dist/utils/floating-ui/svelte/index.js +5 -0
- package/dist/utils/floating-ui/svelte/inner.svelte.d.ts +83 -0
- package/dist/utils/floating-ui/svelte/inner.svelte.js +178 -0
- package/dist/utils/floating-ui/svelte/types.d.ts +114 -0
- package/dist/utils/floating-ui/svelte/types.js +1 -0
- package/dist/utils/floating-ui/svelte/utils/createPubSub.d.ts +5 -0
- package/dist/utils/floating-ui/svelte/utils/createPubSub.js +14 -0
- package/dist/utils/floating-ui/svelte/utils/getFloatingFocusElement.d.ts +2 -0
- package/dist/utils/floating-ui/svelte/utils/getFloatingFocusElement.js +13 -0
- package/dist/utils/floating-ui/svelte/utils/log.d.ts +2 -0
- package/dist/utils/floating-ui/svelte/utils/log.js +19 -0
- package/dist/utils/floating-ui/svelte/utils.d.ts +19 -0
- package/dist/utils/floating-ui/svelte/utils.js +136 -0
- package/dist/utils/floating-ui/svelte-dom/arrow.d.ts +22 -0
- package/dist/utils/floating-ui/svelte-dom/arrow.js +29 -0
- package/dist/utils/floating-ui/svelte-dom/index.d.ts +2 -0
- package/dist/utils/floating-ui/svelte-dom/index.js +2 -0
- package/dist/utils/floating-ui/svelte-dom/types.d.ts +80 -0
- package/dist/utils/floating-ui/svelte-dom/types.js +3 -0
- package/dist/utils/floating-ui/svelte-dom/useFloating.svelte.d.ts +6 -0
- package/dist/utils/floating-ui/svelte-dom/useFloating.svelte.js +182 -0
- package/dist/utils/floating-ui/svelte-dom/utils/deepEqual.d.ts +1 -0
- package/dist/utils/floating-ui/svelte-dom/utils/deepEqual.js +50 -0
- package/dist/utils/floating-ui/svelte-dom/utils/getDPR.d.ts +1 -0
- package/dist/utils/floating-ui/svelte-dom/utils/getDPR.js +7 -0
- package/dist/utils/floating-ui/svelte-dom/utils/roundByDPR.d.ts +1 -0
- package/dist/utils/floating-ui/svelte-dom/utils/roundByDPR.js +5 -0
- package/dist/utils/floating-ui/svelte-dom/utils/useLatestRef.d.ts +4 -0
- package/dist/utils/floating-ui/svelte-dom/utils/useLatestRef.js +7 -0
- package/dist/utils/style.d.ts +2 -0
- package/dist/utils/style.js +6 -0
- package/package.json +3 -2
- package/dist/listbox/ListboxStates.d.ts +0 -12
- package/dist/listbox/ListboxStates.js +0 -15
|
@@ -1,47 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
-
/* eslint-disable prefer-const */
|
|
1
|
+
import { useInteractions } from "../utils/floating-ui/svelte/index.js";
|
|
4
2
|
import { useDisposables } from "../utils/disposables.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function useResolvedAnchor(anchor) {
|
|
19
|
-
if (!anchor)
|
|
20
|
-
return null; // Disable entirely
|
|
21
|
-
if (typeof anchor === "string")
|
|
22
|
-
return { to: anchor }; // Simple string based value,
|
|
23
|
-
return anchor; // User-provided value
|
|
3
|
+
import { getContext, untrack } from "svelte";
|
|
4
|
+
export { useFloatingProvider } from "./floating-provider.svelte.js";
|
|
5
|
+
export function useResolvedAnchor(options) {
|
|
6
|
+
const { anchor } = $derived(options);
|
|
7
|
+
return {
|
|
8
|
+
get anchor() {
|
|
9
|
+
if (!anchor)
|
|
10
|
+
return null; // Disable entirely
|
|
11
|
+
if (typeof anchor === "string")
|
|
12
|
+
return { to: anchor }; // Simple string based value,
|
|
13
|
+
return anchor; // User-provided value
|
|
14
|
+
},
|
|
15
|
+
};
|
|
24
16
|
}
|
|
25
|
-
export function
|
|
26
|
-
|
|
17
|
+
export function useFloatingReference() {
|
|
18
|
+
const context = getContext("FloatingContext");
|
|
19
|
+
return {
|
|
20
|
+
get setReference() {
|
|
21
|
+
return context.setReference;
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function useFloatingReferenceProps() {
|
|
26
|
+
const context = getContext("FloatingContext");
|
|
27
|
+
return {
|
|
28
|
+
get getReferenceProps() {
|
|
29
|
+
return context.getReferenceProps;
|
|
30
|
+
},
|
|
31
|
+
};
|
|
27
32
|
}
|
|
28
33
|
export function useFloatingPanelProps() {
|
|
29
|
-
const
|
|
34
|
+
const context = getContext("FloatingContext");
|
|
35
|
+
const { getFloatingProps, slot } = $derived(context);
|
|
30
36
|
return (...args) => {
|
|
31
37
|
return Object.assign({}, getFloatingProps(...args), {
|
|
32
38
|
"data-anchor": slot.anchor,
|
|
33
39
|
});
|
|
34
40
|
};
|
|
35
41
|
}
|
|
36
|
-
export function useFloatingPanel(options) {
|
|
37
|
-
const placement = $derived.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
const
|
|
42
|
+
export function useFloatingPanel(options = { placement: null }) {
|
|
43
|
+
const placement = $derived(options.placement === false
|
|
44
|
+
? null
|
|
45
|
+
: typeof options.placement === "string"
|
|
46
|
+
? { to: options.placement }
|
|
47
|
+
: options.placement);
|
|
48
|
+
//if (placement === false) placement = null // Disable entirely
|
|
49
|
+
//if (typeof placement === "string") placement = { to: placement } // Simple string based value
|
|
50
|
+
const placementContext = getContext("PlacementContext");
|
|
51
|
+
const { updatePlacementConfig } = $derived(placementContext);
|
|
45
52
|
const trigger = $derived(JSON.stringify(placement, typeof HTMLElement !== "undefined"
|
|
46
53
|
? (_, v) => {
|
|
47
54
|
if (v instanceof HTMLElement) {
|
|
@@ -62,233 +69,41 @@ export function useFloatingPanel(options) {
|
|
|
62
69
|
get setFloating() {
|
|
63
70
|
return context.setFloating;
|
|
64
71
|
},
|
|
65
|
-
get
|
|
72
|
+
get styles() {
|
|
66
73
|
return placement ? context.styles : undefined;
|
|
67
74
|
},
|
|
68
75
|
};
|
|
69
76
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
export const createFloatingContext = ({ enabled = true } = {}) => {
|
|
73
|
-
let config = $state(null);
|
|
74
|
-
//let innerOffset = $state(0)
|
|
75
|
-
//let overflowRef = $state<HTMLElement | null>(null)
|
|
76
|
-
let referenceEl = $state(null);
|
|
77
|
-
let floatingEl = $state(null);
|
|
78
|
-
$effect(() => useFixScrollingPixel(floatingEl));
|
|
79
|
-
const isEnabled = $derived(enabled && config !== null && floatingEl !== null);
|
|
80
|
-
const { to: placement = "bottom", gap = 0, offset = 0, padding = 0, inner, } = $derived(useResolvedConfig({
|
|
81
|
-
get config() {
|
|
82
|
-
return config;
|
|
83
|
-
},
|
|
84
|
-
get element() {
|
|
85
|
-
return floatingEl;
|
|
86
|
-
},
|
|
87
|
-
}));
|
|
88
|
-
const [to, align = "center"] = $derived(placement.split(" "));
|
|
89
|
-
// Reset
|
|
90
|
-
$effect(() => {
|
|
91
|
-
if (!isEnabled)
|
|
92
|
-
return;
|
|
93
|
-
//innerOffset = 0
|
|
94
|
-
});
|
|
95
|
-
let floatingStyles = $state();
|
|
96
|
-
let context = $state();
|
|
97
|
-
let currentComputeId = $state(0);
|
|
77
|
+
export function useFixScrollingPixel(options) {
|
|
78
|
+
const { element } = $derived(options);
|
|
98
79
|
$effect(() => {
|
|
99
|
-
if (!
|
|
80
|
+
if (!element)
|
|
100
81
|
return;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
offsetMiddleware({
|
|
122
|
-
mainAxis: to === "selection" ? 0 : gap,
|
|
123
|
-
crossAxis: offset,
|
|
124
|
-
}),
|
|
125
|
-
// When the panel overflows the viewport, we will try to nudge the panel to the other side to
|
|
126
|
-
// ensure it's not clipped. We use the `padding` to define the minimum space between the
|
|
127
|
-
// panel and the viewport.
|
|
128
|
-
shiftMiddleware({ padding }),
|
|
129
|
-
// The `flip` middleware will swap the `placement` of the panel if there is not enough room.
|
|
130
|
-
// This is not compatible with the `inner` middleware (which is only enabled when `to` is set
|
|
131
|
-
// to "selection").
|
|
132
|
-
to !== "selection" && flipMiddleware({ padding }),
|
|
133
|
-
// The `inner` middleware will ensure the panel is always fully visible on screen and
|
|
134
|
-
// positioned on top of the reference and moved to the currently selected item.
|
|
135
|
-
to === "selection" && inner
|
|
136
|
-
? null /* TODO: use inner when available: innerMiddleware({
|
|
137
|
-
...inner,
|
|
138
|
-
padding, // For overflow detection
|
|
139
|
-
overflowRef,
|
|
140
|
-
offset: innerOffset,
|
|
141
|
-
minItemsVisible: MINIMUM_ITEMS_VISIBLE,
|
|
142
|
-
referenceOverflowThreshold: padding,
|
|
143
|
-
onFallbackChange(fallback) {
|
|
144
|
-
if (!fallback) return
|
|
145
|
-
let parent = context.elements.floating
|
|
146
|
-
if (!parent) return
|
|
147
|
-
let scrollPaddingBottom =
|
|
148
|
-
parseFloat(getComputedStyle(parent!).scrollPaddingBottom) || 0
|
|
149
|
-
|
|
150
|
-
// We want at least X visible items, but if there are less than X items in the list,
|
|
151
|
-
// we want to show as many as possible.
|
|
152
|
-
let missing = Math.min(MINIMUM_ITEMS_VISIBLE, parent.childElementCount)
|
|
153
|
-
|
|
154
|
-
let elementHeight = 0
|
|
155
|
-
let elementAmountVisible = 0
|
|
156
|
-
|
|
157
|
-
for (let child of context.elements.floating?.childNodes ?? []) {
|
|
158
|
-
if (child instanceof HTMLElement) {
|
|
159
|
-
let childTop = child.offsetTop
|
|
160
|
-
// It can be that the child is fully visible, but we also want to keep the scroll
|
|
161
|
-
// padding into account to ensure the UI looks good. Therefore we fake that the
|
|
162
|
-
// bottom of the child is actually `scrollPaddingBottom` amount of pixels lower.
|
|
163
|
-
let childBottom = childTop + child.clientHeight + scrollPaddingBottom
|
|
164
|
-
|
|
165
|
-
let parentTop = parent.scrollTop
|
|
166
|
-
let parentBottom = parentTop + parent.clientHeight
|
|
167
|
-
|
|
168
|
-
// Figure out if the child is fully visible in the scroll parent.
|
|
169
|
-
if (childTop >= parentTop && childBottom <= parentBottom) {
|
|
170
|
-
missing--
|
|
171
|
-
} else {
|
|
172
|
-
// Not fully visible, so we will use this child to calculate the height of
|
|
173
|
-
// each item. We will also use this to calculate how much of the item is
|
|
174
|
-
// already visible.
|
|
175
|
-
elementAmountVisible = Math.max(
|
|
176
|
-
0,
|
|
177
|
-
Math.min(childBottom, parentBottom) - Math.max(childTop, parentTop)
|
|
178
|
-
)
|
|
179
|
-
elementHeight = child.clientHeight
|
|
180
|
-
break
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// There are fewer visible items than we want, so we will try to nudge the offset
|
|
186
|
-
// to show more items.
|
|
187
|
-
if (missing >= 1) {
|
|
188
|
-
setInnerOffset((existingOffset) => {
|
|
189
|
-
let newInnerOffset =
|
|
190
|
-
elementHeight * missing - // `missing` amount of `elementHeight`
|
|
191
|
-
elementAmountVisible + // The amount of the last item that is visible
|
|
192
|
-
scrollPaddingBottom // The scroll padding to ensure the UI looks good
|
|
193
|
-
|
|
194
|
-
// Nudged enough already, no need to continue
|
|
195
|
-
if (existingOffset >= newInnerOffset) {
|
|
196
|
-
return existingOffset
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return newInnerOffset
|
|
200
|
-
})
|
|
201
|
-
}
|
|
202
|
-
},
|
|
203
|
-
})*/
|
|
204
|
-
: null,
|
|
205
|
-
// The `size` middleware will ensure the panel is never bigger than the viewport minus the
|
|
206
|
-
// provided `padding` that we want.
|
|
207
|
-
sizeMiddleware({
|
|
208
|
-
padding,
|
|
209
|
-
apply({ availableWidth, availableHeight, elements }) {
|
|
210
|
-
Object.assign(elements.floating.style, {
|
|
211
|
-
overflow: "auto",
|
|
212
|
-
maxWidth: `${availableWidth}px`,
|
|
213
|
-
maxHeight: `min(var(--anchor-max-height, 100vh), ${availableHeight}px)`,
|
|
214
|
-
});
|
|
215
|
-
},
|
|
216
|
-
}),
|
|
217
|
-
].filter(Boolean),
|
|
218
|
-
}).then((res) => {
|
|
219
|
-
if (currentComputeId === computeId) {
|
|
220
|
-
// Ensure only the last compute updates the context if multiple are running in parallel
|
|
221
|
-
context = res;
|
|
222
|
-
const { x, y } = res;
|
|
223
|
-
floatingStyles = `position: absolute; left: ${x}px; top: ${y}px;`;
|
|
224
|
-
}
|
|
82
|
+
untrack(() => {
|
|
83
|
+
let observer = new MutationObserver(() => {
|
|
84
|
+
let maxHeight = window.getComputedStyle(element).maxHeight;
|
|
85
|
+
let maxHeightFloat = parseFloat(maxHeight);
|
|
86
|
+
if (isNaN(maxHeightFloat))
|
|
87
|
+
return;
|
|
88
|
+
let maxHeightInt = parseInt(maxHeight);
|
|
89
|
+
if (isNaN(maxHeightInt))
|
|
90
|
+
return;
|
|
91
|
+
if (maxHeightFloat !== maxHeightInt) {
|
|
92
|
+
element.style.maxHeight = `${Math.ceil(maxHeightFloat)}px`;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
observer.observe(element, {
|
|
96
|
+
attributes: true,
|
|
97
|
+
attributeFilter: ["style"],
|
|
98
|
+
});
|
|
99
|
+
return () => {
|
|
100
|
+
observer.disconnect();
|
|
101
|
+
};
|
|
225
102
|
});
|
|
226
103
|
});
|
|
227
|
-
// Calculate placement information to expose as data attributes
|
|
228
|
-
let [exposedTo = to, exposedAlign = align] = context?.placement.split("-") ?? [];
|
|
229
|
-
// If user-land code is using custom styles specifically for `bottom`, but
|
|
230
|
-
// they chose `selection`, then we want to make sure to map it to selection
|
|
231
|
-
// again otherwise styles could be wrong.
|
|
232
|
-
if (to === "selection")
|
|
233
|
-
exposedTo = "selection";
|
|
234
|
-
const data = $derived({
|
|
235
|
-
anchor: [exposedTo, exposedAlign].filter(Boolean).join(" "),
|
|
236
|
-
});
|
|
237
|
-
/*let innerOffsetConfig = useInnerOffset(context, {
|
|
238
|
-
overflowRef,
|
|
239
|
-
onChange: setInnerOffset,
|
|
240
|
-
})*/
|
|
241
|
-
const getReferenceProps = () => ({});
|
|
242
|
-
const getFloatingProps = () => ({});
|
|
243
|
-
/*let { getReferenceProps, getFloatingProps } = useInteractions([
|
|
244
|
-
innerOffsetConfig
|
|
245
|
-
])*/
|
|
246
|
-
const floatingContext = {
|
|
247
|
-
setFloating: (floating) => {
|
|
248
|
-
floatingEl = floating || null;
|
|
249
|
-
},
|
|
250
|
-
setReference: (reference) => {
|
|
251
|
-
referenceEl = reference || null;
|
|
252
|
-
},
|
|
253
|
-
get styles() {
|
|
254
|
-
return floatingStyles;
|
|
255
|
-
},
|
|
256
|
-
getReferenceProps,
|
|
257
|
-
getFloatingProps,
|
|
258
|
-
get slot() {
|
|
259
|
-
return data;
|
|
260
|
-
},
|
|
261
|
-
};
|
|
262
|
-
setContext("FloatingContext", floatingContext);
|
|
263
|
-
setContext("PlacementContext", (value) => {
|
|
264
|
-
config = value;
|
|
265
|
-
});
|
|
266
|
-
return floatingContext;
|
|
267
|
-
};
|
|
268
|
-
function useFixScrollingPixel(element) {
|
|
269
|
-
if (!element)
|
|
270
|
-
return;
|
|
271
|
-
let observer = new MutationObserver(() => {
|
|
272
|
-
let maxHeight = window.getComputedStyle(element).maxHeight;
|
|
273
|
-
let maxHeightFloat = parseFloat(maxHeight);
|
|
274
|
-
if (isNaN(maxHeightFloat))
|
|
275
|
-
return;
|
|
276
|
-
let maxHeightInt = parseInt(maxHeight);
|
|
277
|
-
if (isNaN(maxHeightInt))
|
|
278
|
-
return;
|
|
279
|
-
if (maxHeightFloat !== maxHeightInt) {
|
|
280
|
-
element.style.maxHeight = `${Math.ceil(maxHeightFloat)}px`;
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
observer.observe(element, {
|
|
284
|
-
attributes: true,
|
|
285
|
-
attributeFilter: ["style"],
|
|
286
|
-
});
|
|
287
|
-
return () => {
|
|
288
|
-
observer.disconnect();
|
|
289
|
-
};
|
|
290
104
|
}
|
|
291
|
-
function useResolvedConfig(
|
|
105
|
+
export function useResolvedConfig(options) {
|
|
106
|
+
const { config, element } = $derived(options);
|
|
292
107
|
const gap = useResolvePxValue({
|
|
293
108
|
get input() {
|
|
294
109
|
return config?.gap ?? "var(--anchor-gap, 0)";
|
|
@@ -299,7 +114,7 @@ function useResolvedConfig({ config, element, }) {
|
|
|
299
114
|
});
|
|
300
115
|
const offset = useResolvePxValue({
|
|
301
116
|
get input() {
|
|
302
|
-
return config?.
|
|
117
|
+
return config?.offset ?? "var(--anchor-offset, 0)";
|
|
303
118
|
},
|
|
304
119
|
get element() {
|
|
305
120
|
return element;
|
|
@@ -307,7 +122,7 @@ function useResolvedConfig({ config, element, }) {
|
|
|
307
122
|
});
|
|
308
123
|
const padding = useResolvePxValue({
|
|
309
124
|
get input() {
|
|
310
|
-
return config?.
|
|
125
|
+
return config?.padding ?? "var(--anchor-padding, 0)";
|
|
311
126
|
},
|
|
312
127
|
get element() {
|
|
313
128
|
return element;
|
|
@@ -331,7 +146,8 @@ function useResolvedConfig({ config, element, }) {
|
|
|
331
146
|
},
|
|
332
147
|
};
|
|
333
148
|
}
|
|
334
|
-
function useResolvePxValue(
|
|
149
|
+
function useResolvePxValue(options) {
|
|
150
|
+
const { input, element, defaultValue } = $derived(options);
|
|
335
151
|
let d = useDisposables();
|
|
336
152
|
const computeValue = (value, element) => {
|
|
337
153
|
// Nullish
|
|
@@ -415,14 +231,16 @@ function useResolvePxValue({ input, element, defaultValue, }) {
|
|
|
415
231
|
};
|
|
416
232
|
// Calculate the value immediately when the input or element changes. Later we can setup a watcher
|
|
417
233
|
// to track the value changes over time.
|
|
418
|
-
const immediateValue = computeValue(input, element)[0];
|
|
419
|
-
let
|
|
234
|
+
const immediateValue = $derived(computeValue(input, element)[0]);
|
|
235
|
+
let explicitValue = $state();
|
|
236
|
+
const setValue = (value) => (explicitValue = value);
|
|
237
|
+
const value = explicitValue ?? immediateValue;
|
|
420
238
|
$effect(() => {
|
|
421
|
-
|
|
422
|
-
value
|
|
239
|
+
const [value, watcher] = computeValue(input, element);
|
|
240
|
+
setValue(value);
|
|
423
241
|
if (!watcher)
|
|
424
242
|
return;
|
|
425
|
-
return watcher(
|
|
243
|
+
return watcher(setValue);
|
|
426
244
|
});
|
|
427
245
|
return {
|
|
428
246
|
get value() {
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { type DetectOverflowOptions, type Middleware, type SideObject, type Derivable } from "@floating-ui/dom";
|
|
2
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
3
|
+
import type { MutableRefObject } from "../utils/ref.svelte.js";
|
|
4
|
+
export declare function warn(...messages: string[]): void;
|
|
5
|
+
export declare function error(...messages: string[]): void;
|
|
6
|
+
export interface ElementProps {
|
|
7
|
+
reference?: HTMLAttributes<Element>;
|
|
8
|
+
floating?: HTMLAttributes<HTMLElement>;
|
|
9
|
+
item?: HTMLAttributes<HTMLElement> | ((props: Record<string, any>) => HTMLAttributes<HTMLElement>);
|
|
10
|
+
}
|
|
11
|
+
export declare function getUserAgent(): string;
|
|
12
|
+
export interface InnerProps extends DetectOverflowOptions {
|
|
13
|
+
/**
|
|
14
|
+
* A ref which contains an array of HTML elements.
|
|
15
|
+
* @default empty list
|
|
16
|
+
*/
|
|
17
|
+
listRef: MutableRefObject<Array<HTMLElement | null>>;
|
|
18
|
+
/**
|
|
19
|
+
* The index of the active (focused or highlighted) item in the list.
|
|
20
|
+
* @default 0
|
|
21
|
+
*/
|
|
22
|
+
index: number;
|
|
23
|
+
/**
|
|
24
|
+
* Callback invoked when the fallback state changes.
|
|
25
|
+
*/
|
|
26
|
+
onFallbackChange?: null | ((fallback: boolean) => void);
|
|
27
|
+
/**
|
|
28
|
+
* The offset to apply to the floating element.
|
|
29
|
+
* @default 0
|
|
30
|
+
*/
|
|
31
|
+
offset?: number;
|
|
32
|
+
/**
|
|
33
|
+
* A ref which contains the overflow of the floating element.
|
|
34
|
+
*/
|
|
35
|
+
overflowRef?: MutableRefObject<SideObject | null>;
|
|
36
|
+
/**
|
|
37
|
+
* An optional ref containing an HTMLElement. This may be used as the
|
|
38
|
+
* scrolling container instead of the floating element — for instance,
|
|
39
|
+
* to position inner elements as direct children without being interfered by
|
|
40
|
+
* scrolling layout.
|
|
41
|
+
*/
|
|
42
|
+
scrollRef?: MutableRefObject<HTMLElement | null>;
|
|
43
|
+
/**
|
|
44
|
+
* The minimum number of items that should be visible in the list.
|
|
45
|
+
* @default 4
|
|
46
|
+
*/
|
|
47
|
+
minItemsVisible?: number;
|
|
48
|
+
/**
|
|
49
|
+
* The threshold for the reference element's overflow in pixels.
|
|
50
|
+
* @default 0
|
|
51
|
+
*/
|
|
52
|
+
referenceOverflowThreshold?: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Positions the floating element such that an inner element inside of it is
|
|
56
|
+
* anchored to the reference element.
|
|
57
|
+
* @see https://floating-ui.com/docs/inner
|
|
58
|
+
*/
|
|
59
|
+
export declare const inner: (props: InnerProps | Derivable<InnerProps>) => Middleware;
|
|
60
|
+
export interface UseInnerOffsetProps {
|
|
61
|
+
/**
|
|
62
|
+
* Whether the Hook is enabled, including all internal Effects and event
|
|
63
|
+
* handlers.
|
|
64
|
+
* @default true
|
|
65
|
+
*/
|
|
66
|
+
enabled?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* A ref which contains the overflow of the floating element.
|
|
69
|
+
*/
|
|
70
|
+
overflowRef: MutableRefObject<SideObject | null>;
|
|
71
|
+
/**
|
|
72
|
+
* An optional ref containing an HTMLElement. This may be used as the
|
|
73
|
+
* scrolling container instead of the floating element — for instance,
|
|
74
|
+
* to position inner elements as direct children without being interfered by
|
|
75
|
+
* scrolling layout.
|
|
76
|
+
*/
|
|
77
|
+
scrollRef?: MutableRefObject<HTMLElement | null>;
|
|
78
|
+
/**
|
|
79
|
+
* Callback invoked when the offset changes.
|
|
80
|
+
*/
|
|
81
|
+
onChange: (offset: number | ((offset: number) => number)) => void;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Changes the `inner` middleware's `offset` upon a `wheel` event to
|
|
85
|
+
* expand the floating element's height, revealing more list items.
|
|
86
|
+
* @see https://floating-ui.com/docs/inner
|
|
87
|
+
*/
|
|
88
|
+
export declare function useInnerOffset(options: {
|
|
89
|
+
context: FloatingRootContext;
|
|
90
|
+
props: UseInnerOffsetProps;
|
|
91
|
+
}): ElementProps;
|