@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.
Files changed (238) hide show
  1. package/dist/button/Button.svelte +6 -10
  2. package/dist/button/Button.svelte.d.ts +34 -26
  3. package/dist/checkbox/Checkbox.svelte +43 -25
  4. package/dist/checkbox/Checkbox.svelte.d.ts +42 -28
  5. package/dist/close-button/CloseButton.svelte +5 -4
  6. package/dist/close-button/CloseButton.svelte.d.ts +36 -13
  7. package/dist/combobox/Combobox.svelte +2 -2
  8. package/dist/combobox/Combobox.svelte.d.ts +9 -9
  9. package/dist/data-interactive/DataInteractive.svelte +41 -0
  10. package/dist/data-interactive/DataInteractive.svelte.d.ts +39 -0
  11. package/dist/data-interactive/index.d.ts +1 -0
  12. package/dist/data-interactive/index.js +1 -0
  13. package/dist/description/Description.svelte +10 -53
  14. package/dist/description/Description.svelte.d.ts +15 -32
  15. package/dist/description/context.svelte.d.ts +17 -0
  16. package/dist/description/context.svelte.js +51 -0
  17. package/dist/dialog/Dialog.svelte +51 -0
  18. package/dist/dialog/Dialog.svelte.d.ts +60 -0
  19. package/dist/dialog/DialogBackdrop.svelte +39 -0
  20. package/dist/dialog/DialogBackdrop.svelte.d.ts +38 -0
  21. package/dist/dialog/DialogPanel.svelte +46 -0
  22. package/dist/dialog/DialogPanel.svelte.d.ts +40 -0
  23. package/dist/dialog/DialogTitle.svelte +29 -0
  24. package/dist/dialog/DialogTitle.svelte.d.ts +34 -0
  25. package/dist/dialog/InternalDialog.svelte +233 -0
  26. package/dist/dialog/InternalDialog.svelte.d.ts +42 -0
  27. package/dist/dialog/context.svelte.d.ts +15 -0
  28. package/dist/dialog/context.svelte.js +16 -0
  29. package/dist/dialog/index.d.ts +4 -0
  30. package/dist/dialog/index.js +4 -0
  31. package/dist/field/Field.svelte +8 -11
  32. package/dist/field/Field.svelte.d.ts +21 -17
  33. package/dist/fieldset/Fieldset.svelte +11 -9
  34. package/dist/fieldset/Fieldset.svelte.d.ts +21 -17
  35. package/dist/focus-trap/FocusTrap.svelte +325 -0
  36. package/dist/focus-trap/FocusTrap.svelte.d.ts +46 -0
  37. package/dist/focus-trap/FocusTrapFeatures.d.ts +14 -0
  38. package/dist/focus-trap/FocusTrapFeatures.js +15 -0
  39. package/dist/hooks/use-controllable.svelte.d.ts +1 -1
  40. package/dist/hooks/use-controllable.svelte.js +3 -3
  41. package/dist/hooks/use-did-element-move.svelte.js +5 -10
  42. package/dist/hooks/use-escape.svelte.d.ts +5 -0
  43. package/dist/hooks/use-escape.svelte.js +26 -0
  44. package/dist/hooks/use-event-listener.svelte.d.ts +6 -0
  45. package/dist/hooks/use-event-listener.svelte.js +12 -0
  46. package/dist/hooks/use-inert-others.svelte.d.ts +2 -2
  47. package/dist/hooks/use-inert-others.svelte.js +3 -3
  48. package/dist/hooks/use-is-mounted.svelte.d.ts +3 -0
  49. package/dist/hooks/use-is-mounted.svelte.js +14 -0
  50. package/dist/hooks/use-is-touch-device.svelte.d.ts +3 -0
  51. package/dist/hooks/use-is-touch-device.svelte.js +20 -0
  52. package/dist/hooks/use-root-containers.svelte.d.ts +9 -0
  53. package/dist/hooks/use-root-containers.svelte.js +50 -0
  54. package/dist/hooks/use-tab-direction.svelte.d.ts +7 -0
  55. package/dist/hooks/use-tab-direction.svelte.js +25 -0
  56. package/dist/hooks/use-transition.svelte.js +14 -13
  57. package/dist/hooks/use-tree-walker.svelte.d.ts +8 -0
  58. package/dist/hooks/use-tree-walker.svelte.js +19 -0
  59. package/dist/hooks/use-watch.svelte.d.ts +4 -0
  60. package/dist/hooks/use-watch.svelte.js +16 -0
  61. package/dist/hooks/use-window-event.svelte.d.ts +6 -0
  62. package/dist/hooks/use-window-event.svelte.js +12 -0
  63. package/dist/index.d.ts +10 -0
  64. package/dist/index.js +10 -0
  65. package/dist/input/Input.svelte +59 -0
  66. package/dist/input/Input.svelte.d.ts +50 -0
  67. package/dist/input/index.d.ts +1 -0
  68. package/dist/input/index.js +1 -0
  69. package/dist/internal/FloatingProvider.svelte +12 -0
  70. package/dist/internal/FloatingProvider.svelte.d.ts +22 -0
  71. package/dist/internal/FocusSentinel.svelte.d.ts +4 -1
  72. package/dist/internal/ForcePortalRoot.svelte +6 -0
  73. package/dist/internal/ForcePortalRoot.svelte.d.ts +22 -0
  74. package/dist/internal/FormFields.svelte.d.ts +4 -1
  75. package/dist/internal/FormResolver.svelte.d.ts +4 -1
  76. package/dist/internal/Hidden.svelte +6 -14
  77. package/dist/internal/Hidden.svelte.d.ts +19 -15
  78. package/dist/internal/HiddenFeatures.d.ts +5 -0
  79. package/dist/internal/HiddenFeatures.js +9 -0
  80. package/dist/internal/HoistFormFields.svelte.d.ts +4 -1
  81. package/dist/internal/MainTreeProvider.svelte +45 -0
  82. package/dist/internal/MainTreeProvider.svelte.d.ts +31 -0
  83. package/dist/internal/Portal.svelte.d.ts +4 -1
  84. package/dist/internal/close-provider.d.ts +7 -0
  85. package/dist/internal/close-provider.js +7 -0
  86. package/dist/internal/floating-provider.svelte.d.ts +3 -0
  87. package/dist/internal/floating-provider.svelte.js +206 -0
  88. package/dist/internal/floating.svelte.d.ts +50 -20
  89. package/dist/internal/floating.svelte.js +100 -271
  90. package/dist/internal/inner.svelte.d.ts +91 -0
  91. package/dist/internal/inner.svelte.js +202 -0
  92. package/dist/internal/open-closed.d.ts +1 -1
  93. package/dist/internal/open-closed.js +1 -1
  94. package/dist/label/Label.svelte +17 -65
  95. package/dist/label/Label.svelte.d.ts +19 -32
  96. package/dist/label/context.svelte.d.ts +17 -0
  97. package/dist/label/context.svelte.js +56 -0
  98. package/dist/legend/Legend.svelte +4 -3
  99. package/dist/legend/Legend.svelte.d.ts +33 -15
  100. package/dist/listbox/Listbox.svelte +40 -74
  101. package/dist/listbox/Listbox.svelte.d.ts +30 -72
  102. package/dist/listbox/ListboxButton.svelte +16 -18
  103. package/dist/listbox/ListboxButton.svelte.d.ts +16 -7
  104. package/dist/listbox/ListboxOption.svelte +10 -10
  105. package/dist/listbox/ListboxOption.svelte.d.ts +22 -11
  106. package/dist/listbox/ListboxOptions.svelte +62 -60
  107. package/dist/listbox/ListboxOptions.svelte.d.ts +23 -7
  108. package/dist/listbox/ListboxSelectedOption.svelte +15 -7
  109. package/dist/listbox/ListboxSelectedOption.svelte.d.ts +24 -14
  110. package/dist/listbox/context.svelte.d.ts +75 -0
  111. package/dist/listbox/context.svelte.js +36 -0
  112. package/dist/menu/Menu.svelte +235 -0
  113. package/dist/menu/Menu.svelte.d.ts +42 -0
  114. package/dist/menu/MenuButton.svelte +129 -0
  115. package/dist/menu/MenuButton.svelte.d.ts +52 -0
  116. package/dist/menu/MenuHeading.svelte +19 -0
  117. package/dist/menu/MenuHeading.svelte.d.ts +39 -0
  118. package/dist/menu/MenuItem.svelte +114 -0
  119. package/dist/menu/MenuItem.svelte.d.ts +49 -0
  120. package/dist/menu/MenuItems.svelte +248 -0
  121. package/dist/menu/MenuItems.svelte.d.ts +55 -0
  122. package/dist/menu/MenuSection.svelte +14 -0
  123. package/dist/menu/MenuSection.svelte.d.ts +35 -0
  124. package/dist/menu/MenuSeparator.svelte +9 -0
  125. package/dist/menu/MenuSeparator.svelte.d.ts +35 -0
  126. package/dist/menu/context.svelte.d.ts +47 -0
  127. package/dist/menu/context.svelte.js +21 -0
  128. package/dist/menu/index.d.ts +7 -0
  129. package/dist/menu/index.js +7 -0
  130. package/dist/portal/InternalPortal.svelte +22 -33
  131. package/dist/portal/InternalPortal.svelte.d.ts +16 -7
  132. package/dist/portal/Portal.svelte +4 -8
  133. package/dist/portal/Portal.svelte.d.ts +6 -6
  134. package/dist/portal/PortalGroup.svelte +5 -6
  135. package/dist/portal/PortalGroup.svelte.d.ts +16 -7
  136. package/dist/switch/Switch.svelte +41 -37
  137. package/dist/switch/Switch.svelte.d.ts +24 -7
  138. package/dist/switch/SwitchGroup.svelte +7 -8
  139. package/dist/switch/SwitchGroup.svelte.d.ts +14 -7
  140. package/dist/tabs/Tab.svelte +9 -14
  141. package/dist/tabs/Tab.svelte.d.ts +18 -6
  142. package/dist/tabs/TabGroup.svelte +20 -23
  143. package/dist/tabs/TabGroup.svelte.d.ts +19 -6
  144. package/dist/tabs/TabList.svelte +5 -7
  145. package/dist/tabs/TabList.svelte.d.ts +13 -6
  146. package/dist/tabs/TabPanel.svelte +30 -32
  147. package/dist/tabs/TabPanel.svelte.d.ts +19 -6
  148. package/dist/tabs/TabPanels.svelte +5 -6
  149. package/dist/tabs/TabPanels.svelte.d.ts +13 -6
  150. package/dist/textarea/Textarea.svelte +67 -0
  151. package/dist/textarea/Textarea.svelte.d.ts +50 -0
  152. package/dist/textarea/index.d.ts +1 -0
  153. package/dist/textarea/index.js +1 -0
  154. package/dist/transition/InternalTransitionChild.svelte +178 -0
  155. package/dist/transition/InternalTransitionChild.svelte.d.ts +55 -0
  156. package/dist/transition/Transition.svelte +89 -0
  157. package/dist/transition/Transition.svelte.d.ts +42 -0
  158. package/dist/transition/TransitionChild.svelte +16 -0
  159. package/dist/transition/TransitionChild.svelte.d.ts +44 -0
  160. package/dist/transition/context.svelte.d.ts +64 -0
  161. package/dist/transition/context.svelte.js +120 -0
  162. package/dist/transition/index.d.ts +2 -0
  163. package/dist/transition/index.js +2 -0
  164. package/dist/utils/ElementOrComponent.svelte +26 -0
  165. package/dist/utils/ElementOrComponent.svelte.d.ts +56 -0
  166. package/dist/utils/Generic.svelte +44 -0
  167. package/dist/utils/Generic.svelte.d.ts +35 -0
  168. package/dist/utils/StableCollection.svelte +1 -1
  169. package/dist/utils/StableCollection.svelte.d.ts +4 -1
  170. package/dist/utils/active-element-history.d.ts +1 -0
  171. package/dist/utils/active-element-history.js +35 -0
  172. package/dist/utils/alternative-types.d.ts +21 -0
  173. package/dist/utils/alternative-types.js +1 -0
  174. package/dist/utils/class-names.d.ts +1 -0
  175. package/dist/utils/class-names.js +10 -0
  176. package/dist/utils/floating-ui/svelte/components/FloatingNode.svelte +17 -0
  177. package/dist/utils/floating-ui/svelte/components/FloatingNode.svelte.d.ts +23 -0
  178. package/dist/utils/floating-ui/svelte/components/FloatingTree.svelte +50 -0
  179. package/dist/utils/floating-ui/svelte/components/FloatingTree.svelte.d.ts +41 -0
  180. package/dist/utils/floating-ui/svelte/hooks/useFloating.svelte.d.ts +6 -0
  181. package/dist/utils/floating-ui/svelte/hooks/useFloating.svelte.js +158 -0
  182. package/dist/utils/floating-ui/svelte/hooks/useFloatingRootContext.svelte.d.ts +11 -0
  183. package/dist/utils/floating-ui/svelte/hooks/useFloatingRootContext.svelte.js +53 -0
  184. package/dist/utils/floating-ui/svelte/hooks/useId.svelte.d.ts +9 -0
  185. package/dist/utils/floating-ui/svelte/hooks/useId.svelte.js +28 -0
  186. package/dist/utils/floating-ui/svelte/hooks/useInteractions.svelte.d.ts +23 -0
  187. package/dist/utils/floating-ui/svelte/hooks/useInteractions.svelte.js +72 -0
  188. package/dist/utils/floating-ui/svelte/index.d.ts +5 -0
  189. package/dist/utils/floating-ui/svelte/index.js +5 -0
  190. package/dist/utils/floating-ui/svelte/inner.svelte.d.ts +83 -0
  191. package/dist/utils/floating-ui/svelte/inner.svelte.js +178 -0
  192. package/dist/utils/floating-ui/svelte/types.d.ts +114 -0
  193. package/dist/utils/floating-ui/svelte/types.js +1 -0
  194. package/dist/utils/floating-ui/svelte/utils/createPubSub.d.ts +5 -0
  195. package/dist/utils/floating-ui/svelte/utils/createPubSub.js +14 -0
  196. package/dist/utils/floating-ui/svelte/utils/getFloatingFocusElement.d.ts +2 -0
  197. package/dist/utils/floating-ui/svelte/utils/getFloatingFocusElement.js +13 -0
  198. package/dist/utils/floating-ui/svelte/utils/log.d.ts +2 -0
  199. package/dist/utils/floating-ui/svelte/utils/log.js +19 -0
  200. package/dist/utils/floating-ui/svelte/utils.d.ts +19 -0
  201. package/dist/utils/floating-ui/svelte/utils.js +136 -0
  202. package/dist/utils/floating-ui/svelte-dom/arrow.d.ts +22 -0
  203. package/dist/utils/floating-ui/svelte-dom/arrow.js +29 -0
  204. package/dist/utils/floating-ui/svelte-dom/index.d.ts +2 -0
  205. package/dist/utils/floating-ui/svelte-dom/index.js +2 -0
  206. package/dist/utils/floating-ui/svelte-dom/types.d.ts +80 -0
  207. package/dist/utils/floating-ui/svelte-dom/types.js +3 -0
  208. package/dist/utils/floating-ui/svelte-dom/useFloating.svelte.d.ts +6 -0
  209. package/dist/utils/floating-ui/svelte-dom/useFloating.svelte.js +183 -0
  210. package/dist/utils/floating-ui/svelte-dom/utils/deepEqual.d.ts +1 -0
  211. package/dist/utils/floating-ui/svelte-dom/utils/deepEqual.js +50 -0
  212. package/dist/utils/floating-ui/svelte-dom/utils/getDPR.d.ts +1 -0
  213. package/dist/utils/floating-ui/svelte-dom/utils/getDPR.js +7 -0
  214. package/dist/utils/floating-ui/svelte-dom/utils/roundByDPR.d.ts +1 -0
  215. package/dist/utils/floating-ui/svelte-dom/utils/roundByDPR.js +5 -0
  216. package/dist/utils/floating-ui/svelte-dom/utils/useLatestRef.d.ts +4 -0
  217. package/dist/utils/floating-ui/svelte-dom/utils/useLatestRef.js +7 -0
  218. package/dist/utils/focus-management.d.ts +2 -1
  219. package/dist/utils/focus-management.js +13 -13
  220. package/dist/utils/id.d.ts +1 -1
  221. package/dist/utils/id.js +1 -1
  222. package/dist/utils/on-document-ready.d.ts +1 -0
  223. package/dist/utils/on-document-ready.js +12 -0
  224. package/dist/utils/render.d.ts +3 -0
  225. package/dist/utils/render.js +63 -0
  226. package/dist/utils/state.d.ts +7 -1
  227. package/dist/utils/state.js +10 -6
  228. package/dist/utils/style.d.ts +2 -0
  229. package/dist/utils/style.js +6 -0
  230. package/dist/utils/types.d.ts +14 -17
  231. package/dist/utils/types.js +0 -5
  232. package/package.json +33 -31
  233. package/dist/internal/id.d.ts +0 -8
  234. package/dist/internal/id.js +0 -11
  235. package/dist/tabs/Button.svelte +0 -65
  236. package/dist/tabs/Button.svelte.d.ts +0 -39
  237. package/dist/utils/close.d.ts +0 -2
  238. 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 { useRef } from "../utils/ref.svelte.js";
3
- import { autoUpdate, flip as flipMiddleware,
4
- //inner as innerMiddleware,
5
- offset as offsetMiddleware, shift as shiftMiddleware, size as sizeMiddleware, useFloating as _useFloating,
6
- //useInnerOffset,
7
- useInteractions, } from "@skeletonlabs/floating-ui-svelte";
8
- import { getContext, setContext } from "svelte";
9
- export function useResolvedAnchor(anchor) {
10
- if (!anchor)
11
- return null; // Disable entirely
12
- if (typeof anchor === "string")
13
- return { to: anchor }; // Simple string based value,
14
- 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
+ };
15
16
  }
16
- export function useFloating() {
17
- return getContext("FloatingContext");
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
- let { getFloatingProps, slot } = getContext("FloatingContext");
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(placement = null) {
28
- if (placement === false)
29
- placement = null; // Disable entirely
30
- if (typeof placement === "string")
31
- placement = { to: placement }; // Simple string based value
32
- const updatePlacementConfig = getContext("PlacementContext");
33
- /*let stablePlacement = useMemo(
34
- () => placement,
35
- [
36
- JSON.stringify(
37
- placement,
38
- typeof HTMLElement !== 'undefined'
39
- ? (_, v) => {
40
- if (v instanceof HTMLElement) {
41
- return v.outerHTML
42
- }
43
- return v
44
- }
45
- : undefined
46
- ),
47
- ]
48
- )*/
49
- updatePlacementConfig?.(placement ?? null);
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 style() {
72
+ get styles() {
56
73
  return placement ? context.styles : undefined;
57
74
  },
58
75
  };
59
76
  }
60
- // TODO: Make this a config part of the `config`. Just need to decide on a name.
61
- let MINIMUM_ITEMS_VISIBLE = 4;
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 (!isEnabled)
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
- if (maxHeightFloat !== maxHeightInt) {
274
- element.style.maxHeight = `${Math.ceil(maxHeightFloat)}px`;
275
- }
276
- });
277
- observer.observe(element, {
278
- attributes: true,
279
- attributeFilter: ["style"],
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({ config, element, }) {
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?.gap ?? "var(--anchor-offset, 0)";
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?.gap ?? "var(--anchor-padding, 0)";
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
- ...config,
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({ input, element, defaultValue, }) {
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 value = $state(immediateValue);
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
- let [newValue, watcher] = computeValue(input, element);
411
- value = newValue;
239
+ const [value, watcher] = computeValue(input, element);
240
+ setValue(value);
412
241
  if (!watcher)
413
242
  return;
414
- return watcher((_value) => (value = _value));
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;