@pzerelles/headlessui-svelte 2.1.1-next.1 → 2.1.2-next.11
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/button/Button.svelte +6 -10
- package/dist/button/Button.svelte.d.ts +34 -26
- package/dist/checkbox/Checkbox.svelte +43 -25
- package/dist/checkbox/Checkbox.svelte.d.ts +42 -28
- package/dist/close-button/CloseButton.svelte +5 -4
- package/dist/close-button/CloseButton.svelte.d.ts +36 -13
- package/dist/combobox/Combobox.svelte +2 -2
- package/dist/combobox/Combobox.svelte.d.ts +9 -9
- package/dist/data-interactive/DataInteractive.svelte +41 -0
- package/dist/data-interactive/DataInteractive.svelte.d.ts +39 -0
- package/dist/data-interactive/index.d.ts +1 -0
- package/dist/data-interactive/index.js +1 -0
- package/dist/description/Description.svelte +10 -53
- package/dist/description/Description.svelte.d.ts +15 -32
- package/dist/description/context.svelte.d.ts +17 -0
- package/dist/description/context.svelte.js +51 -0
- package/dist/dialog/Dialog.svelte +51 -0
- package/dist/dialog/Dialog.svelte.d.ts +60 -0
- package/dist/dialog/DialogBackdrop.svelte +39 -0
- package/dist/dialog/DialogBackdrop.svelte.d.ts +38 -0
- package/dist/dialog/DialogPanel.svelte +46 -0
- package/dist/dialog/DialogPanel.svelte.d.ts +40 -0
- package/dist/dialog/DialogTitle.svelte +29 -0
- package/dist/dialog/DialogTitle.svelte.d.ts +34 -0
- package/dist/dialog/InternalDialog.svelte +233 -0
- package/dist/dialog/InternalDialog.svelte.d.ts +42 -0
- package/dist/dialog/context.svelte.d.ts +15 -0
- package/dist/dialog/context.svelte.js +16 -0
- package/dist/dialog/index.d.ts +4 -0
- package/dist/dialog/index.js +4 -0
- package/dist/field/Field.svelte +8 -11
- package/dist/field/Field.svelte.d.ts +21 -17
- package/dist/fieldset/Fieldset.svelte +11 -9
- package/dist/fieldset/Fieldset.svelte.d.ts +21 -17
- package/dist/focus-trap/FocusTrap.svelte +325 -0
- package/dist/focus-trap/FocusTrap.svelte.d.ts +46 -0
- package/dist/focus-trap/FocusTrapFeatures.d.ts +14 -0
- package/dist/focus-trap/FocusTrapFeatures.js +15 -0
- package/dist/hooks/use-controllable.svelte.d.ts +1 -1
- package/dist/hooks/use-controllable.svelte.js +3 -3
- package/dist/hooks/use-did-element-move.svelte.js +5 -10
- package/dist/hooks/use-escape.svelte.d.ts +5 -0
- package/dist/hooks/use-escape.svelte.js +26 -0
- package/dist/hooks/use-event-listener.svelte.d.ts +6 -0
- package/dist/hooks/use-event-listener.svelte.js +12 -0
- package/dist/hooks/use-inert-others.svelte.d.ts +2 -2
- package/dist/hooks/use-inert-others.svelte.js +3 -3
- package/dist/hooks/use-is-mounted.svelte.d.ts +3 -0
- package/dist/hooks/use-is-mounted.svelte.js +14 -0
- package/dist/hooks/use-is-touch-device.svelte.d.ts +3 -0
- package/dist/hooks/use-is-touch-device.svelte.js +20 -0
- package/dist/hooks/use-root-containers.svelte.d.ts +9 -0
- package/dist/hooks/use-root-containers.svelte.js +50 -0
- package/dist/hooks/use-tab-direction.svelte.d.ts +7 -0
- package/dist/hooks/use-tab-direction.svelte.js +25 -0
- package/dist/hooks/use-transition.svelte.js +14 -13
- package/dist/hooks/use-tree-walker.svelte.d.ts +8 -0
- package/dist/hooks/use-tree-walker.svelte.js +19 -0
- package/dist/hooks/use-watch.svelte.d.ts +4 -0
- package/dist/hooks/use-watch.svelte.js +16 -0
- package/dist/hooks/use-window-event.svelte.d.ts +6 -0
- package/dist/hooks/use-window-event.svelte.js +12 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/input/Input.svelte +59 -0
- package/dist/input/Input.svelte.d.ts +50 -0
- package/dist/input/index.d.ts +1 -0
- package/dist/input/index.js +1 -0
- package/dist/internal/FloatingProvider.svelte +12 -0
- package/dist/internal/FloatingProvider.svelte.d.ts +22 -0
- package/dist/internal/FocusSentinel.svelte.d.ts +4 -1
- package/dist/internal/ForcePortalRoot.svelte +6 -0
- package/dist/internal/ForcePortalRoot.svelte.d.ts +22 -0
- package/dist/internal/FormFields.svelte.d.ts +4 -1
- package/dist/internal/FormResolver.svelte.d.ts +4 -1
- package/dist/internal/Hidden.svelte +6 -14
- package/dist/internal/Hidden.svelte.d.ts +19 -15
- package/dist/internal/HiddenFeatures.d.ts +5 -0
- package/dist/internal/HiddenFeatures.js +9 -0
- package/dist/internal/HoistFormFields.svelte.d.ts +4 -1
- package/dist/internal/MainTreeProvider.svelte +45 -0
- package/dist/internal/MainTreeProvider.svelte.d.ts +31 -0
- package/dist/internal/Portal.svelte.d.ts +4 -1
- package/dist/internal/close-provider.d.ts +7 -0
- package/dist/internal/close-provider.js +7 -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 +50 -20
- package/dist/internal/floating.svelte.js +100 -271
- package/dist/internal/inner.svelte.d.ts +91 -0
- package/dist/internal/inner.svelte.js +202 -0
- package/dist/internal/open-closed.d.ts +1 -1
- package/dist/internal/open-closed.js +1 -1
- package/dist/label/Label.svelte +17 -65
- package/dist/label/Label.svelte.d.ts +19 -32
- package/dist/label/context.svelte.d.ts +17 -0
- package/dist/label/context.svelte.js +56 -0
- package/dist/legend/Legend.svelte +4 -3
- package/dist/legend/Legend.svelte.d.ts +33 -15
- package/dist/listbox/Listbox.svelte +40 -74
- package/dist/listbox/Listbox.svelte.d.ts +30 -72
- package/dist/listbox/ListboxButton.svelte +16 -18
- package/dist/listbox/ListboxButton.svelte.d.ts +16 -7
- package/dist/listbox/ListboxOption.svelte +10 -10
- package/dist/listbox/ListboxOption.svelte.d.ts +22 -11
- package/dist/listbox/ListboxOptions.svelte +62 -60
- package/dist/listbox/ListboxOptions.svelte.d.ts +23 -7
- package/dist/listbox/ListboxSelectedOption.svelte +15 -7
- package/dist/listbox/ListboxSelectedOption.svelte.d.ts +24 -14
- package/dist/listbox/context.svelte.d.ts +75 -0
- package/dist/listbox/context.svelte.js +36 -0
- package/dist/menu/Menu.svelte +235 -0
- package/dist/menu/Menu.svelte.d.ts +42 -0
- package/dist/menu/MenuButton.svelte +129 -0
- package/dist/menu/MenuButton.svelte.d.ts +52 -0
- package/dist/menu/MenuHeading.svelte +19 -0
- package/dist/menu/MenuHeading.svelte.d.ts +39 -0
- package/dist/menu/MenuItem.svelte +114 -0
- package/dist/menu/MenuItem.svelte.d.ts +49 -0
- package/dist/menu/MenuItems.svelte +248 -0
- package/dist/menu/MenuItems.svelte.d.ts +55 -0
- package/dist/menu/MenuSection.svelte +14 -0
- package/dist/menu/MenuSection.svelte.d.ts +35 -0
- package/dist/menu/MenuSeparator.svelte +9 -0
- package/dist/menu/MenuSeparator.svelte.d.ts +35 -0
- package/dist/menu/context.svelte.d.ts +47 -0
- package/dist/menu/context.svelte.js +21 -0
- package/dist/menu/index.d.ts +7 -0
- package/dist/menu/index.js +7 -0
- package/dist/portal/InternalPortal.svelte +22 -33
- package/dist/portal/InternalPortal.svelte.d.ts +16 -7
- package/dist/portal/Portal.svelte +4 -8
- package/dist/portal/Portal.svelte.d.ts +6 -6
- package/dist/portal/PortalGroup.svelte +5 -6
- package/dist/portal/PortalGroup.svelte.d.ts +16 -7
- package/dist/switch/Switch.svelte +41 -37
- package/dist/switch/Switch.svelte.d.ts +24 -7
- package/dist/switch/SwitchGroup.svelte +7 -8
- package/dist/switch/SwitchGroup.svelte.d.ts +14 -7
- package/dist/tabs/Tab.svelte +9 -14
- package/dist/tabs/Tab.svelte.d.ts +18 -6
- package/dist/tabs/TabGroup.svelte +20 -23
- package/dist/tabs/TabGroup.svelte.d.ts +19 -6
- package/dist/tabs/TabList.svelte +5 -7
- package/dist/tabs/TabList.svelte.d.ts +13 -6
- package/dist/tabs/TabPanel.svelte +30 -32
- package/dist/tabs/TabPanel.svelte.d.ts +19 -6
- package/dist/tabs/TabPanels.svelte +5 -6
- package/dist/tabs/TabPanels.svelte.d.ts +13 -6
- package/dist/textarea/Textarea.svelte +67 -0
- package/dist/textarea/Textarea.svelte.d.ts +50 -0
- package/dist/textarea/index.d.ts +1 -0
- package/dist/textarea/index.js +1 -0
- package/dist/transition/InternalTransitionChild.svelte +178 -0
- package/dist/transition/InternalTransitionChild.svelte.d.ts +55 -0
- package/dist/transition/Transition.svelte +89 -0
- package/dist/transition/Transition.svelte.d.ts +42 -0
- package/dist/transition/TransitionChild.svelte +16 -0
- package/dist/transition/TransitionChild.svelte.d.ts +44 -0
- package/dist/transition/context.svelte.d.ts +64 -0
- package/dist/transition/context.svelte.js +120 -0
- package/dist/transition/index.d.ts +2 -0
- package/dist/transition/index.js +2 -0
- package/dist/utils/ElementOrComponent.svelte +26 -0
- package/dist/utils/ElementOrComponent.svelte.d.ts +56 -0
- package/dist/utils/Generic.svelte +44 -0
- package/dist/utils/Generic.svelte.d.ts +35 -0
- package/dist/utils/StableCollection.svelte +1 -1
- package/dist/utils/StableCollection.svelte.d.ts +4 -1
- package/dist/utils/active-element-history.d.ts +1 -0
- package/dist/utils/active-element-history.js +35 -0
- package/dist/utils/alternative-types.d.ts +21 -0
- package/dist/utils/alternative-types.js +1 -0
- package/dist/utils/class-names.d.ts +1 -0
- package/dist/utils/class-names.js +10 -0
- 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 +183 -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/focus-management.d.ts +2 -1
- package/dist/utils/focus-management.js +13 -13
- package/dist/utils/id.d.ts +1 -1
- package/dist/utils/id.js +1 -1
- package/dist/utils/on-document-ready.d.ts +1 -0
- package/dist/utils/on-document-ready.js +12 -0
- package/dist/utils/render.d.ts +3 -0
- package/dist/utils/render.js +63 -0
- package/dist/utils/state.d.ts +7 -1
- package/dist/utils/state.js +10 -6
- package/dist/utils/style.d.ts +2 -0
- package/dist/utils/style.js +6 -0
- package/dist/utils/types.d.ts +14 -17
- package/dist/utils/types.js +0 -5
- package/package.json +33 -31
- package/dist/internal/id.d.ts +0 -8
- package/dist/internal/id.js +0 -11
- package/dist/tabs/Button.svelte +0 -65
- package/dist/tabs/Button.svelte.d.ts +0 -39
- package/dist/utils/close.d.ts +0 -2
- package/dist/utils/close.js +0 -3
|
@@ -1,288 +1,109 @@
|
|
|
1
|
+
import { useInteractions } from "../utils/floating-ui/svelte/index.js";
|
|
1
2
|
import { useDisposables } from "../utils/disposables.js";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
};
|
|
15
16
|
}
|
|
16
|
-
export function
|
|
17
|
-
|
|
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
|
+
};
|
|
18
32
|
}
|
|
19
33
|
export function useFloatingPanelProps() {
|
|
20
|
-
|
|
34
|
+
const context = getContext("FloatingContext");
|
|
35
|
+
const { getFloatingProps, slot } = $derived(context);
|
|
21
36
|
return (...args) => {
|
|
22
37
|
return Object.assign({}, getFloatingProps(...args), {
|
|
23
38
|
"data-anchor": slot.anchor,
|
|
24
39
|
});
|
|
25
40
|
};
|
|
26
41
|
}
|
|
27
|
-
export function useFloatingPanel(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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);
|
|
52
|
+
const trigger = $derived(JSON.stringify(placement, typeof HTMLElement !== "undefined"
|
|
53
|
+
? (_, v) => {
|
|
54
|
+
if (v instanceof HTMLElement) {
|
|
55
|
+
return v.outerHTML;
|
|
56
|
+
}
|
|
57
|
+
return v;
|
|
58
|
+
}
|
|
59
|
+
: undefined));
|
|
60
|
+
const stablePlacement = $derived.by(() => {
|
|
61
|
+
trigger;
|
|
62
|
+
return untrack(() => placement);
|
|
63
|
+
});
|
|
64
|
+
$effect(() => {
|
|
65
|
+
updatePlacementConfig?.(stablePlacement ?? null);
|
|
66
|
+
});
|
|
50
67
|
const context = getContext("FloatingContext");
|
|
51
68
|
return {
|
|
52
69
|
get setFloating() {
|
|
53
70
|
return context.setFloating;
|
|
54
71
|
},
|
|
55
|
-
get
|
|
72
|
+
get styles() {
|
|
56
73
|
return placement ? context.styles : undefined;
|
|
57
74
|
},
|
|
58
75
|
};
|
|
59
76
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
export const createFloatingContext = ({ enabled = true } = {}) => {
|
|
63
|
-
let config = $state(null);
|
|
64
|
-
let innerOffset = $state(0);
|
|
65
|
-
let overflowRef = useRef(null);
|
|
66
|
-
let floatingEl = $state(null);
|
|
67
|
-
$effect(() => useFixScrollingPixel(floatingEl));
|
|
68
|
-
const isEnabled = $derived(enabled && config !== null && floatingEl !== null);
|
|
69
|
-
let { to: placement = "bottom", gap = 0, offset = 0, padding = 0, inner, } = useResolvedConfig({
|
|
70
|
-
get config() {
|
|
71
|
-
return config;
|
|
72
|
-
},
|
|
73
|
-
get element() {
|
|
74
|
-
return floatingEl;
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
let [to, align = "center"] = placement.split(" ");
|
|
78
|
-
// Reset
|
|
77
|
+
export function useFixScrollingPixel(options) {
|
|
78
|
+
const { element } = $derived(options);
|
|
79
79
|
$effect(() => {
|
|
80
|
-
if (!
|
|
81
|
-
return;
|
|
82
|
-
innerOffset = 0;
|
|
83
|
-
});
|
|
84
|
-
const { elements, floatingStyles, context } = $derived(_useFloating({
|
|
85
|
-
open: isEnabled,
|
|
86
|
-
placement: to === "selection"
|
|
87
|
-
? align === "center"
|
|
88
|
-
? "bottom"
|
|
89
|
-
: `bottom-${align}`
|
|
90
|
-
: align === "center"
|
|
91
|
-
? `${to}`
|
|
92
|
-
: `${to}-${align}`,
|
|
93
|
-
// This component will be used in combination with a `Portal`, which means the floating
|
|
94
|
-
// element will be rendered outside of the current DOM tree.
|
|
95
|
-
strategy: "absolute",
|
|
96
|
-
// We use the panel in a `Dialog` which is making the page inert, therefore no re-positioning is
|
|
97
|
-
// needed when scrolling changes.
|
|
98
|
-
transform: false,
|
|
99
|
-
middleware: [
|
|
100
|
-
// - The `mainAxis` is set to `gap` which defines the gap between the panel and the
|
|
101
|
-
// trigger/reference.
|
|
102
|
-
// - The `crossAxis` is set to `offset` which nudges the panel from its original position.
|
|
103
|
-
//
|
|
104
|
-
// When we are showing the panel on top of the selected item, we don't want a gap between the
|
|
105
|
-
// reference and the panel, therefore setting the `mainAxis` to `0`.
|
|
106
|
-
offsetMiddleware({
|
|
107
|
-
mainAxis: to === "selection" ? 0 : gap,
|
|
108
|
-
crossAxis: offset,
|
|
109
|
-
}),
|
|
110
|
-
// When the panel overflows the viewport, we will try to nudge the panel to the other side to
|
|
111
|
-
// ensure it's not clipped. We use the `padding` to define the minimum space between the
|
|
112
|
-
// panel and the viewport.
|
|
113
|
-
shiftMiddleware({ padding }),
|
|
114
|
-
// The `flip` middleware will swap the `placement` of the panel if there is not enough room.
|
|
115
|
-
// This is not compatible with the `inner` middleware (which is only enabled when `to` is set
|
|
116
|
-
// to "selection").
|
|
117
|
-
to !== "selection" && flipMiddleware({ padding }),
|
|
118
|
-
// The `inner` middleware will ensure the panel is always fully visible on screen and
|
|
119
|
-
// positioned on top of the reference and moved to the currently selected item.
|
|
120
|
-
to === "selection" && inner
|
|
121
|
-
? null /* TODO: use inner when available: innerMiddleware({
|
|
122
|
-
...inner,
|
|
123
|
-
padding, // For overflow detection
|
|
124
|
-
overflowRef,
|
|
125
|
-
offset: innerOffset,
|
|
126
|
-
minItemsVisible: MINIMUM_ITEMS_VISIBLE,
|
|
127
|
-
referenceOverflowThreshold: padding,
|
|
128
|
-
onFallbackChange(fallback) {
|
|
129
|
-
if (!fallback) return
|
|
130
|
-
let parent = context.elements.floating
|
|
131
|
-
if (!parent) return
|
|
132
|
-
let scrollPaddingBottom =
|
|
133
|
-
parseFloat(getComputedStyle(parent!).scrollPaddingBottom) || 0
|
|
134
|
-
|
|
135
|
-
// We want at least X visible items, but if there are less than X items in the list,
|
|
136
|
-
// we want to show as many as possible.
|
|
137
|
-
let missing = Math.min(MINIMUM_ITEMS_VISIBLE, parent.childElementCount)
|
|
138
|
-
|
|
139
|
-
let elementHeight = 0
|
|
140
|
-
let elementAmountVisible = 0
|
|
141
|
-
|
|
142
|
-
for (let child of context.elements.floating?.childNodes ?? []) {
|
|
143
|
-
if (child instanceof HTMLElement) {
|
|
144
|
-
let childTop = child.offsetTop
|
|
145
|
-
// It can be that the child is fully visible, but we also want to keep the scroll
|
|
146
|
-
// padding into account to ensure the UI looks good. Therefore we fake that the
|
|
147
|
-
// bottom of the child is actually `scrollPaddingBottom` amount of pixels lower.
|
|
148
|
-
let childBottom = childTop + child.clientHeight + scrollPaddingBottom
|
|
149
|
-
|
|
150
|
-
let parentTop = parent.scrollTop
|
|
151
|
-
let parentBottom = parentTop + parent.clientHeight
|
|
152
|
-
|
|
153
|
-
// Figure out if the child is fully visible in the scroll parent.
|
|
154
|
-
if (childTop >= parentTop && childBottom <= parentBottom) {
|
|
155
|
-
missing--
|
|
156
|
-
} else {
|
|
157
|
-
// Not fully visible, so we will use this child to calculate the height of
|
|
158
|
-
// each item. We will also use this to calculate how much of the item is
|
|
159
|
-
// already visible.
|
|
160
|
-
elementAmountVisible = Math.max(
|
|
161
|
-
0,
|
|
162
|
-
Math.min(childBottom, parentBottom) - Math.max(childTop, parentTop)
|
|
163
|
-
)
|
|
164
|
-
elementHeight = child.clientHeight
|
|
165
|
-
break
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// There are fewer visible items than we want, so we will try to nudge the offset
|
|
171
|
-
// to show more items.
|
|
172
|
-
if (missing >= 1) {
|
|
173
|
-
setInnerOffset((existingOffset) => {
|
|
174
|
-
let newInnerOffset =
|
|
175
|
-
elementHeight * missing - // `missing` amount of `elementHeight`
|
|
176
|
-
elementAmountVisible + // The amount of the last item that is visible
|
|
177
|
-
scrollPaddingBottom // The scroll padding to ensure the UI looks good
|
|
178
|
-
|
|
179
|
-
// Nudged enough already, no need to continue
|
|
180
|
-
if (existingOffset >= newInnerOffset) {
|
|
181
|
-
return existingOffset
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return newInnerOffset
|
|
185
|
-
})
|
|
186
|
-
}
|
|
187
|
-
},
|
|
188
|
-
})*/
|
|
189
|
-
: null,
|
|
190
|
-
// The `size` middleware will ensure the panel is never bigger than the viewport minus the
|
|
191
|
-
// provided `padding` that we want.
|
|
192
|
-
sizeMiddleware({
|
|
193
|
-
padding,
|
|
194
|
-
apply({ availableWidth, availableHeight, elements }) {
|
|
195
|
-
Object.assign(elements.floating.style, {
|
|
196
|
-
overflow: "auto",
|
|
197
|
-
maxWidth: `${availableWidth}px`,
|
|
198
|
-
maxHeight: `min(var(--anchor-max-height, 100vh), ${availableHeight}px)`,
|
|
199
|
-
});
|
|
200
|
-
},
|
|
201
|
-
}),
|
|
202
|
-
].filter(Boolean),
|
|
203
|
-
whileElementsMounted: autoUpdate,
|
|
204
|
-
}));
|
|
205
|
-
// Calculate placement information to expose as data attributes
|
|
206
|
-
let [exposedTo = to, exposedAlign = align] = context.placement.split("-");
|
|
207
|
-
// If user-land code is using custom styles specifically for `bottom`, but
|
|
208
|
-
// they chose `selection`, then we want to make sure to map it to selection
|
|
209
|
-
// again otherwise styles could be wrong.
|
|
210
|
-
if (to === "selection")
|
|
211
|
-
exposedTo = "selection";
|
|
212
|
-
const data = $derived({
|
|
213
|
-
anchor: [exposedTo, exposedAlign].filter(Boolean).join(" "),
|
|
214
|
-
});
|
|
215
|
-
/*let innerOffsetConfig = useInnerOffset(context, {
|
|
216
|
-
overflowRef,
|
|
217
|
-
onChange: setInnerOffset,
|
|
218
|
-
})*/
|
|
219
|
-
let { getReferenceProps, getFloatingProps } = useInteractions([
|
|
220
|
-
/*innerOffsetConfig*/
|
|
221
|
-
]);
|
|
222
|
-
let setFloatingRef = (el) => {
|
|
223
|
-
floatingEl = el || null;
|
|
224
|
-
elements.floating = el;
|
|
225
|
-
};
|
|
226
|
-
/*
|
|
227
|
-
|
|
228
|
-
return (
|
|
229
|
-
<PlacementContext.Provider value={setConfig}>
|
|
230
|
-
<FloatingContext.Provider
|
|
231
|
-
value={{
|
|
232
|
-
setFloating: setFloatingRef,
|
|
233
|
-
setReference: refs.setReference,
|
|
234
|
-
styles: floatingStyles,
|
|
235
|
-
getReferenceProps,
|
|
236
|
-
getFloatingProps,
|
|
237
|
-
slot: data,
|
|
238
|
-
}}
|
|
239
|
-
>
|
|
240
|
-
{children}
|
|
241
|
-
</FloatingContext.Provider>
|
|
242
|
-
</PlacementContext.Provider>
|
|
243
|
-
)*/
|
|
244
|
-
const floatingContext = {
|
|
245
|
-
setFloating: setFloatingRef,
|
|
246
|
-
setReference: (reference) => {
|
|
247
|
-
elements.reference = reference;
|
|
248
|
-
},
|
|
249
|
-
get styles() {
|
|
250
|
-
return floatingStyles;
|
|
251
|
-
},
|
|
252
|
-
getReferenceProps,
|
|
253
|
-
getFloatingProps,
|
|
254
|
-
get slot() {
|
|
255
|
-
return data;
|
|
256
|
-
},
|
|
257
|
-
};
|
|
258
|
-
setContext("FloatingContext", floatingContext);
|
|
259
|
-
setContext("PlacementContext", null);
|
|
260
|
-
return floatingContext;
|
|
261
|
-
};
|
|
262
|
-
function useFixScrollingPixel(element) {
|
|
263
|
-
if (!element)
|
|
264
|
-
return;
|
|
265
|
-
let observer = new MutationObserver(() => {
|
|
266
|
-
let maxHeight = window.getComputedStyle(element).maxHeight;
|
|
267
|
-
let maxHeightFloat = parseFloat(maxHeight);
|
|
268
|
-
if (isNaN(maxHeightFloat))
|
|
269
|
-
return;
|
|
270
|
-
let maxHeightInt = parseInt(maxHeight);
|
|
271
|
-
if (isNaN(maxHeightInt))
|
|
80
|
+
if (!element)
|
|
272
81
|
return;
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
+
};
|
|
102
|
+
});
|
|
280
103
|
});
|
|
281
|
-
return () => {
|
|
282
|
-
observer.disconnect();
|
|
283
|
-
};
|
|
284
104
|
}
|
|
285
|
-
function useResolvedConfig(
|
|
105
|
+
export function useResolvedConfig(options) {
|
|
106
|
+
const { config, element } = $derived(options);
|
|
286
107
|
const gap = useResolvePxValue({
|
|
287
108
|
get input() {
|
|
288
109
|
return config?.gap ?? "var(--anchor-gap, 0)";
|
|
@@ -293,7 +114,7 @@ function useResolvedConfig({ config, element, }) {
|
|
|
293
114
|
});
|
|
294
115
|
const offset = useResolvePxValue({
|
|
295
116
|
get input() {
|
|
296
|
-
return config?.
|
|
117
|
+
return config?.offset ?? "var(--anchor-offset, 0)";
|
|
297
118
|
},
|
|
298
119
|
get element() {
|
|
299
120
|
return element;
|
|
@@ -301,14 +122,16 @@ function useResolvedConfig({ config, element, }) {
|
|
|
301
122
|
});
|
|
302
123
|
const padding = useResolvePxValue({
|
|
303
124
|
get input() {
|
|
304
|
-
return config?.
|
|
125
|
+
return config?.padding ?? "var(--anchor-padding, 0)";
|
|
305
126
|
},
|
|
306
127
|
get element() {
|
|
307
128
|
return element;
|
|
308
129
|
},
|
|
309
130
|
});
|
|
310
131
|
return {
|
|
311
|
-
|
|
132
|
+
get to() {
|
|
133
|
+
return config?.to;
|
|
134
|
+
},
|
|
312
135
|
get gap() {
|
|
313
136
|
return gap.value;
|
|
314
137
|
},
|
|
@@ -318,9 +141,13 @@ function useResolvedConfig({ config, element, }) {
|
|
|
318
141
|
get padding() {
|
|
319
142
|
return padding.value;
|
|
320
143
|
},
|
|
144
|
+
get inner() {
|
|
145
|
+
return config?.inner;
|
|
146
|
+
},
|
|
321
147
|
};
|
|
322
148
|
}
|
|
323
|
-
function useResolvePxValue(
|
|
149
|
+
function useResolvePxValue(options) {
|
|
150
|
+
const { input, element, defaultValue } = $derived(options);
|
|
324
151
|
let d = useDisposables();
|
|
325
152
|
const computeValue = (value, element) => {
|
|
326
153
|
// Nullish
|
|
@@ -404,14 +231,16 @@ function useResolvePxValue({ input, element, defaultValue, }) {
|
|
|
404
231
|
};
|
|
405
232
|
// Calculate the value immediately when the input or element changes. Later we can setup a watcher
|
|
406
233
|
// to track the value changes over time.
|
|
407
|
-
const immediateValue = computeValue(input, element)[0];
|
|
408
|
-
let
|
|
234
|
+
const immediateValue = $derived(computeValue(input, element)[0]);
|
|
235
|
+
let explicitValue = $state();
|
|
236
|
+
const setValue = (value) => (explicitValue = value);
|
|
237
|
+
const value = explicitValue ?? immediateValue;
|
|
409
238
|
$effect(() => {
|
|
410
|
-
|
|
411
|
-
value
|
|
239
|
+
const [value, watcher] = computeValue(input, element);
|
|
240
|
+
setValue(value);
|
|
412
241
|
if (!watcher)
|
|
413
242
|
return;
|
|
414
|
-
return watcher(
|
|
243
|
+
return watcher(setValue);
|
|
415
244
|
});
|
|
416
245
|
return {
|
|
417
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;
|