@pzerelles/headlessui-svelte 2.1.2-next.3 → 2.1.2-next.30

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 (197) hide show
  1. package/dist/button/Button.svelte +1 -1
  2. package/dist/button/Button.svelte.d.ts +9 -11
  3. package/dist/checkbox/Checkbox.svelte +4 -4
  4. package/dist/checkbox/Checkbox.svelte.d.ts +10 -14
  5. package/dist/close-button/CloseButton.svelte.d.ts +16 -18
  6. package/dist/data-interactive/DataInteractive.svelte.d.ts +8 -11
  7. package/dist/description/Description.svelte +19 -14
  8. package/dist/description/Description.svelte.d.ts +9 -11
  9. package/dist/description/context.svelte.js +14 -16
  10. package/dist/dialog/Dialog.svelte +245 -17
  11. package/dist/dialog/Dialog.svelte.d.ts +12 -14
  12. package/dist/dialog/DialogBackdrop.svelte +1 -1
  13. package/dist/dialog/DialogBackdrop.svelte.d.ts +9 -11
  14. package/dist/dialog/DialogPanel.svelte +1 -2
  15. package/dist/dialog/DialogPanel.svelte.d.ts +9 -11
  16. package/dist/dialog/DialogTitle.svelte.d.ts +8 -10
  17. package/dist/dialog/context.svelte.js +1 -1
  18. package/dist/field/Field.svelte +24 -12
  19. package/dist/field/Field.svelte.d.ts +9 -11
  20. package/dist/fieldset/Fieldset.svelte +1 -1
  21. package/dist/fieldset/Fieldset.svelte.d.ts +9 -11
  22. package/dist/focus-trap/FocusTrap.svelte +7 -14
  23. package/dist/focus-trap/FocusTrap.svelte.d.ts +11 -25
  24. package/dist/focus-trap/FocusTrapFeatures.d.ts +14 -0
  25. package/dist/focus-trap/FocusTrapFeatures.js +15 -0
  26. package/dist/hooks/use-controllable.svelte.js +2 -1
  27. package/dist/hooks/use-did-element-move.svelte.js +5 -10
  28. package/dist/hooks/use-disabled.d.ts +6 -1
  29. package/dist/hooks/use-disabled.js +10 -5
  30. package/dist/hooks/use-event-listener.svelte.d.ts +1 -1
  31. package/dist/hooks/use-event-listener.svelte.js +3 -1
  32. package/dist/hooks/use-root-containers.svelte.d.ts +2 -2
  33. package/dist/hooks/use-root-containers.svelte.js +5 -5
  34. package/dist/hooks/use-tab-direction.svelte.js +1 -1
  35. package/dist/index.d.ts +4 -2
  36. package/dist/index.js +4 -2
  37. package/dist/input/Input.svelte +3 -3
  38. package/dist/input/Input.svelte.d.ts +10 -14
  39. package/dist/internal/FloatingProvider.svelte +12 -0
  40. package/dist/internal/FloatingProvider.svelte.d.ts +6 -0
  41. package/dist/internal/FocusSentinel.svelte.d.ts +2 -18
  42. package/dist/internal/ForcePortalRoot.svelte.d.ts +2 -18
  43. package/dist/internal/FormFields.svelte +22 -19
  44. package/dist/internal/FormFields.svelte.d.ts +2 -18
  45. package/dist/internal/FormFieldsProvider.svelte +13 -0
  46. package/dist/internal/FormFieldsProvider.svelte.d.ts +5 -0
  47. package/dist/internal/FormResolver.svelte.d.ts +2 -18
  48. package/dist/internal/Hidden.svelte +18 -8
  49. package/dist/internal/Hidden.svelte.d.ts +11 -16
  50. package/dist/internal/HiddenFeatures.d.ts +5 -0
  51. package/dist/internal/HiddenFeatures.js +9 -0
  52. package/dist/internal/MainTreeProvider.svelte.d.ts +2 -18
  53. package/dist/internal/Portal.svelte.d.ts +2 -18
  54. package/dist/internal/floating-provider.svelte.d.ts +3 -0
  55. package/dist/internal/floating-provider.svelte.js +206 -0
  56. package/dist/internal/floating.svelte.d.ts +48 -23
  57. package/dist/internal/floating.svelte.js +91 -272
  58. package/dist/internal/form-fields.svelte.d.ts +10 -0
  59. package/dist/internal/form-fields.svelte.js +23 -0
  60. package/dist/label/Label.svelte +6 -5
  61. package/dist/label/Label.svelte.d.ts +9 -11
  62. package/dist/label/context.svelte.js +1 -1
  63. package/dist/legend/Legend.svelte +2 -2
  64. package/dist/legend/Legend.svelte.d.ts +4 -32
  65. package/dist/listbox/Listbox.svelte +47 -68
  66. package/dist/listbox/Listbox.svelte.d.ts +18 -80
  67. package/dist/listbox/ListboxButton.svelte +10 -10
  68. package/dist/listbox/ListboxButton.svelte.d.ts +10 -15
  69. package/dist/listbox/ListboxOption.svelte +10 -6
  70. package/dist/listbox/ListboxOption.svelte.d.ts +9 -12
  71. package/dist/listbox/ListboxOptions.svelte +108 -54
  72. package/dist/listbox/ListboxOptions.svelte.d.ts +9 -12
  73. package/dist/listbox/ListboxSelectedOption.svelte +2 -4
  74. package/dist/listbox/ListboxSelectedOption.svelte.d.ts +14 -16
  75. package/dist/listbox/context.svelte.d.ts +76 -0
  76. package/dist/listbox/context.svelte.js +36 -0
  77. package/dist/listbox/index.d.ts +4 -4
  78. package/dist/listbox/index.js +1 -1
  79. package/dist/menu/Menu.svelte +9 -187
  80. package/dist/menu/Menu.svelte.d.ts +9 -12
  81. package/dist/menu/MenuButton.svelte +4 -2
  82. package/dist/menu/MenuButton.svelte.d.ts +9 -12
  83. package/dist/menu/MenuHeading.svelte.d.ts +9 -12
  84. package/dist/menu/MenuItem.svelte.d.ts +11 -16
  85. package/dist/menu/MenuItems.svelte +15 -11
  86. package/dist/menu/MenuItems.svelte.d.ts +9 -12
  87. package/dist/menu/MenuSection.svelte.d.ts +8 -11
  88. package/dist/menu/MenuSeparator.svelte.d.ts +8 -12
  89. package/dist/menu/context.svelte.d.ts +2 -1
  90. package/dist/menu/context.svelte.js +212 -2
  91. package/dist/menu/index.d.ts +7 -7
  92. package/dist/popover/Popover.svelte +161 -0
  93. package/dist/popover/Popover.svelte.d.ts +39 -0
  94. package/dist/popover/PopoverBackdrop.svelte +56 -0
  95. package/dist/popover/PopoverBackdrop.svelte.d.ts +43 -0
  96. package/dist/popover/PopoverButton.svelte +246 -0
  97. package/dist/popover/PopoverButton.svelte.d.ts +42 -0
  98. package/dist/popover/PopoverGroup.svelte +43 -0
  99. package/dist/popover/PopoverGroup.svelte.d.ts +31 -0
  100. package/dist/popover/PopoverPanel.svelte +274 -0
  101. package/dist/popover/PopoverPanel.svelte.d.ts +51 -0
  102. package/dist/popover/context.svelte.d.ts +51 -0
  103. package/dist/popover/context.svelte.js +108 -0
  104. package/dist/popover/index.d.ts +5 -0
  105. package/dist/popover/index.js +5 -0
  106. package/dist/portal/InternalPortal.svelte.d.ts +9 -11
  107. package/dist/portal/Portal.svelte.d.ts +2 -6
  108. package/dist/portal/PortalGroup.svelte.d.ts +9 -11
  109. package/dist/select/Select.svelte +74 -0
  110. package/dist/select/Select.svelte.d.ts +46 -0
  111. package/dist/select/index.d.ts +1 -0
  112. package/dist/select/index.js +1 -0
  113. package/dist/switch/Switch.svelte +30 -20
  114. package/dist/switch/Switch.svelte.d.ts +10 -12
  115. package/dist/switch/SwitchGroup.svelte.d.ts +8 -10
  116. package/dist/tabs/Tab.svelte +8 -9
  117. package/dist/tabs/Tab.svelte.d.ts +9 -11
  118. package/dist/tabs/TabGroup.svelte +27 -190
  119. package/dist/tabs/TabGroup.svelte.d.ts +9 -31
  120. package/dist/tabs/TabList.svelte +4 -4
  121. package/dist/tabs/TabList.svelte.d.ts +8 -10
  122. package/dist/tabs/TabPanel.svelte +4 -5
  123. package/dist/tabs/TabPanel.svelte.d.ts +9 -11
  124. package/dist/tabs/TabPanels.svelte +3 -3
  125. package/dist/tabs/TabPanels.svelte.d.ts +8 -10
  126. package/dist/tabs/context.svelte.d.ts +31 -0
  127. package/dist/tabs/context.svelte.js +134 -0
  128. package/dist/textarea/Textarea.svelte +4 -4
  129. package/dist/textarea/Textarea.svelte.d.ts +21 -20
  130. package/dist/transition/InternalTransitionChild.svelte.d.ts +9 -11
  131. package/dist/transition/Transition.svelte.d.ts +9 -11
  132. package/dist/transition/TransitionChild.svelte.d.ts +9 -11
  133. package/dist/transition/context.svelte.js +2 -2
  134. package/dist/utils/DisabledProvider.svelte +6 -0
  135. package/dist/utils/DisabledProvider.svelte.d.ts +6 -0
  136. package/dist/utils/ElementOrComponent.svelte +2 -2
  137. package/dist/utils/ElementOrComponent.svelte.d.ts +12 -11
  138. package/dist/utils/Generic.svelte +10 -8
  139. package/dist/utils/Generic.svelte.d.ts +12 -15
  140. package/dist/utils/StableCollection.svelte.d.ts +2 -18
  141. package/dist/utils/alternative-types.d.ts +1 -2
  142. package/dist/utils/floating-ui/svelte/components/FloatingNode.svelte +17 -0
  143. package/dist/utils/floating-ui/svelte/components/FloatingNode.svelte.d.ts +7 -0
  144. package/dist/utils/floating-ui/svelte/components/FloatingTree.svelte +50 -0
  145. package/dist/utils/floating-ui/svelte/components/FloatingTree.svelte.d.ts +25 -0
  146. package/dist/utils/floating-ui/svelte/hooks/useFloating.svelte.d.ts +6 -0
  147. package/dist/utils/floating-ui/svelte/hooks/useFloating.svelte.js +158 -0
  148. package/dist/utils/floating-ui/svelte/hooks/useFloatingRootContext.svelte.d.ts +11 -0
  149. package/dist/utils/floating-ui/svelte/hooks/useFloatingRootContext.svelte.js +53 -0
  150. package/dist/utils/floating-ui/svelte/hooks/useId.svelte.d.ts +9 -0
  151. package/dist/utils/floating-ui/svelte/hooks/useId.svelte.js +28 -0
  152. package/dist/utils/floating-ui/svelte/hooks/useInteractions.svelte.d.ts +23 -0
  153. package/dist/utils/floating-ui/svelte/hooks/useInteractions.svelte.js +72 -0
  154. package/dist/utils/floating-ui/svelte/index.d.ts +5 -0
  155. package/dist/utils/floating-ui/svelte/index.js +5 -0
  156. package/dist/utils/floating-ui/svelte/inner.svelte.d.ts +83 -0
  157. package/dist/utils/floating-ui/svelte/inner.svelte.js +178 -0
  158. package/dist/utils/floating-ui/svelte/types.d.ts +114 -0
  159. package/dist/utils/floating-ui/svelte/types.js +1 -0
  160. package/dist/utils/floating-ui/svelte/utils/createPubSub.d.ts +5 -0
  161. package/dist/utils/floating-ui/svelte/utils/createPubSub.js +14 -0
  162. package/dist/utils/floating-ui/svelte/utils/getFloatingFocusElement.d.ts +2 -0
  163. package/dist/utils/floating-ui/svelte/utils/getFloatingFocusElement.js +13 -0
  164. package/dist/utils/floating-ui/svelte/utils/log.d.ts +2 -0
  165. package/dist/utils/floating-ui/svelte/utils/log.js +19 -0
  166. package/dist/utils/floating-ui/svelte/utils.d.ts +19 -0
  167. package/dist/utils/floating-ui/svelte/utils.js +136 -0
  168. package/dist/utils/floating-ui/svelte-dom/arrow.d.ts +22 -0
  169. package/dist/utils/floating-ui/svelte-dom/arrow.js +29 -0
  170. package/dist/utils/floating-ui/svelte-dom/index.d.ts +2 -0
  171. package/dist/utils/floating-ui/svelte-dom/index.js +2 -0
  172. package/dist/utils/floating-ui/svelte-dom/types.d.ts +80 -0
  173. package/dist/utils/floating-ui/svelte-dom/types.js +3 -0
  174. package/dist/utils/floating-ui/svelte-dom/useFloating.svelte.d.ts +6 -0
  175. package/dist/utils/floating-ui/svelte-dom/useFloating.svelte.js +182 -0
  176. package/dist/utils/floating-ui/svelte-dom/utils/deepEqual.d.ts +1 -0
  177. package/dist/utils/floating-ui/svelte-dom/utils/deepEqual.js +50 -0
  178. package/dist/utils/floating-ui/svelte-dom/utils/getDPR.d.ts +1 -0
  179. package/dist/utils/floating-ui/svelte-dom/utils/getDPR.js +7 -0
  180. package/dist/utils/floating-ui/svelte-dom/utils/roundByDPR.d.ts +1 -0
  181. package/dist/utils/floating-ui/svelte-dom/utils/roundByDPR.js +5 -0
  182. package/dist/utils/floating-ui/svelte-dom/utils/useLatestRef.d.ts +4 -0
  183. package/dist/utils/floating-ui/svelte-dom/utils/useLatestRef.js +7 -0
  184. package/dist/utils/id.d.ts +1 -1
  185. package/dist/utils/id.js +1 -1
  186. package/dist/utils/index.d.ts +3 -0
  187. package/dist/utils/index.js +3 -0
  188. package/dist/utils/style.d.ts +2 -0
  189. package/dist/utils/style.js +6 -0
  190. package/dist/utils/types.d.ts +9 -13
  191. package/package.json +27 -26
  192. package/dist/dialog/InternalDialog.svelte +0 -233
  193. package/dist/dialog/InternalDialog.svelte.d.ts +0 -42
  194. package/dist/internal/HoistFormFields.svelte +0 -11
  195. package/dist/internal/HoistFormFields.svelte.d.ts +0 -21
  196. package/dist/internal/id.d.ts +0 -8
  197. package/dist/internal/id.js +0 -11
@@ -1,47 +1,54 @@
1
- /* eslint-disable @typescript-eslint/no-unused-expressions */
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 { computePosition } from "@floating-ui/dom";
6
- import { flip as flipMiddleware,
7
- //inner as innerMiddleware,
8
- offset as offsetMiddleware, shift as shiftMiddleware, size as sizeMiddleware, } from "@floating-ui/core";
9
- /*import {
10
- autoUpdate,
11
- useFloating as _useFloating,
12
- //useInnerOffset,
13
- useInteractions,
14
- //type InnerProps,
15
- type UseFloatingReturn,
16
- } from "@skeletonlabs/floating-ui-svelte"*/
17
- import { getContext, setContext, untrack } from "svelte";
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 useFloating() {
26
- 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
+ };
27
32
  }
28
33
  export function useFloatingPanelProps() {
29
- const { getFloatingProps, slot } = getContext("FloatingContext");
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.by(() => {
38
- if (options.placement === false)
39
- return null; // Disable entirely
40
- if (typeof options.placement === "string")
41
- return { to: options.placement }; // Simple string based value
42
- return options.placement;
43
- });
44
- const updatePlacementConfig = getContext("PlacementContext");
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) {
@@ -51,6 +58,7 @@ export function useFloatingPanel(options) {
51
58
  }
52
59
  : undefined));
53
60
  const stablePlacement = $derived.by(() => {
61
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
54
62
  trigger;
55
63
  return untrack(() => placement);
56
64
  });
@@ -62,233 +70,41 @@ export function useFloatingPanel(options) {
62
70
  get setFloating() {
63
71
  return context.setFloating;
64
72
  },
65
- get style() {
73
+ get styles() {
66
74
  return placement ? context.styles : undefined;
67
75
  },
68
76
  };
69
77
  }
70
- // TODO: Make this a config part of the `config`. Just need to decide on a name.
71
- //let MINIMUM_ITEMS_VISIBLE = 4
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);
78
+ export function useFixScrollingPixel(options) {
98
79
  $effect(() => {
99
- if (!referenceEl || !floatingEl)
80
+ const element = options.element;
81
+ if (!element)
100
82
  return;
101
- const computeId = untrack(() => currentComputeId + 1);
102
- currentComputeId = computeId;
103
- computePosition(referenceEl, floatingEl, {
104
- placement: to === "selection"
105
- ? align === "center"
106
- ? "bottom"
107
- : `bottom-${align}`
108
- : align === "center"
109
- ? `${to}`
110
- : `${to}-${align}`,
111
- // This component will be used in combination with a `Portal`, which means the floating
112
- // element will be rendered outside of the current DOM tree.
113
- strategy: "absolute",
114
- middleware: [
115
- // - The `mainAxis` is set to `gap` which defines the gap between the panel and the
116
- // trigger/reference.
117
- // - The `crossAxis` is set to `offset` which nudges the panel from its original position.
118
- //
119
- // When we are showing the panel on top of the selected item, we don't want a gap between the
120
- // reference and the panel, therefore setting the `mainAxis` to `0`.
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
- }
83
+ untrack(() => {
84
+ const observer = new MutationObserver(() => {
85
+ const maxHeight = window.getComputedStyle(element).maxHeight;
86
+ const maxHeightFloat = parseFloat(maxHeight);
87
+ if (isNaN(maxHeightFloat))
88
+ return;
89
+ const maxHeightInt = parseInt(maxHeight);
90
+ if (isNaN(maxHeightInt))
91
+ return;
92
+ if (maxHeightFloat !== maxHeightInt) {
93
+ element.style.maxHeight = `${Math.ceil(maxHeightFloat)}px`;
94
+ }
95
+ });
96
+ observer.observe(element, {
97
+ attributes: true,
98
+ attributeFilter: ["style"],
99
+ });
100
+ return () => {
101
+ observer.disconnect();
102
+ };
225
103
  });
226
104
  });
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
105
  }
291
- function useResolvedConfig({ config, element, }) {
106
+ export function useResolvedConfig(options) {
107
+ const { config, element } = $derived(options);
292
108
  const gap = useResolvePxValue({
293
109
  get input() {
294
110
  return config?.gap ?? "var(--anchor-gap, 0)";
@@ -299,7 +115,7 @@ function useResolvedConfig({ config, element, }) {
299
115
  });
300
116
  const offset = useResolvePxValue({
301
117
  get input() {
302
- return config?.gap ?? "var(--anchor-offset, 0)";
118
+ return config?.offset ?? "var(--anchor-offset, 0)";
303
119
  },
304
120
  get element() {
305
121
  return element;
@@ -307,7 +123,7 @@ function useResolvedConfig({ config, element, }) {
307
123
  });
308
124
  const padding = useResolvePxValue({
309
125
  get input() {
310
- return config?.gap ?? "var(--anchor-padding, 0)";
126
+ return config?.padding ?? "var(--anchor-padding, 0)";
311
127
  },
312
128
  get element() {
313
129
  return element;
@@ -331,8 +147,9 @@ function useResolvedConfig({ config, element, }) {
331
147
  },
332
148
  };
333
149
  }
334
- function useResolvePxValue({ input, element, defaultValue, }) {
335
- let d = useDisposables();
150
+ function useResolvePxValue(options) {
151
+ const { input, element, defaultValue } = $derived(options);
152
+ const d = useDisposables();
336
153
  const computeValue = (value, element) => {
337
154
  // Nullish
338
155
  if (value == null)
@@ -348,7 +165,7 @@ function useResolvePxValue({ input, element, defaultValue, }) {
348
165
  return [
349
166
  result,
350
167
  (setValue) => {
351
- let variables = resolveVariables(value);
168
+ const variables = resolveVariables(value);
352
169
  // TODO: Improve this part and make it work
353
170
  //
354
171
  // Observe variables themselves. Currently the browser doesn't support this, but the
@@ -380,7 +197,7 @@ function useResolvePxValue({ input, element, defaultValue, }) {
380
197
  // }
381
198
  // Works as a fallback, but not very performant because we are polling the value.
382
199
  {
383
- let history = variables.map((variable) => window.getComputedStyle(element).getPropertyValue(variable));
200
+ const history = variables.map((variable) => window.getComputedStyle(element).getPropertyValue(variable));
384
201
  d.requestAnimationFrame(function check() {
385
202
  d.nextFrame(check);
386
203
  // Fast path, detect if the value of the CSS Variable has changed before completely
@@ -389,8 +206,8 @@ function useResolvePxValue({ input, element, defaultValue, }) {
389
206
  //
390
207
  // This is a lot of work, so we want to avoid it if possible.
391
208
  let changed = false;
392
- for (let [idx, variable] of variables.entries()) {
393
- let value = window.getComputedStyle(element).getPropertyValue(variable);
209
+ for (const [idx, variable] of variables.entries()) {
210
+ const value = window.getComputedStyle(element).getPropertyValue(variable);
394
211
  if (history[idx] !== value) {
395
212
  history[idx] = value;
396
213
  changed = true;
@@ -400,7 +217,7 @@ function useResolvePxValue({ input, element, defaultValue, }) {
400
217
  // Nothing changed, no need to perform the expensive computation.
401
218
  if (!changed)
402
219
  return;
403
- let newResult = resolveCSSVariablePxValue(value, element);
220
+ const newResult = resolveCSSVariablePxValue(value, element);
404
221
  if (result !== newResult) {
405
222
  setValue(newResult);
406
223
  result = newResult;
@@ -415,14 +232,16 @@ function useResolvePxValue({ input, element, defaultValue, }) {
415
232
  };
416
233
  // Calculate the value immediately when the input or element changes. Later we can setup a watcher
417
234
  // to track the value changes over time.
418
- const immediateValue = computeValue(input, element)[0];
419
- let value = $state(immediateValue);
235
+ const immediateValue = $derived(computeValue(input, element)[0]);
236
+ let explicitValue = $state();
237
+ const setValue = (value) => (explicitValue = value);
238
+ const value = $derived(explicitValue ?? immediateValue);
420
239
  $effect(() => {
421
- let [newValue, watcher] = computeValue(input, element);
422
- value = newValue;
240
+ const [value, watcher] = computeValue(input, element);
241
+ setValue(value);
423
242
  if (!watcher)
424
243
  return;
425
- return watcher((_value) => (value = _value));
244
+ return watcher(setValue);
426
245
  });
427
246
  return {
428
247
  get value() {
@@ -431,14 +250,14 @@ function useResolvePxValue({ input, element, defaultValue, }) {
431
250
  };
432
251
  }
433
252
  function resolveVariables(value) {
434
- let matches = /var\((.*)\)/.exec(value);
253
+ const matches = /var\((.*)\)/.exec(value);
435
254
  if (matches) {
436
- let idx = matches[1].indexOf(",");
255
+ const idx = matches[1].indexOf(",");
437
256
  if (idx === -1) {
438
257
  return [matches[1]];
439
258
  }
440
- let variable = matches[1].slice(0, idx).trim();
441
- let fallback = matches[1].slice(idx + 1).trim();
259
+ const variable = matches[1].slice(0, idx).trim();
260
+ const fallback = matches[1].slice(idx + 1).trim();
442
261
  if (fallback) {
443
262
  return [variable, ...resolveVariables(fallback)];
444
263
  }
@@ -472,7 +291,7 @@ function resolveCSSVariablePxValue(input, element) {
472
291
  // ```
473
292
  //
474
293
  // Then this will result to resolved value of `2rem`, instead of `1rem`
475
- let tmpEl = document.createElement("div");
294
+ const tmpEl = document.createElement("div");
476
295
  element.appendChild(tmpEl);
477
296
  // Set the value to `0px` otherwise if an invalid value is provided later the browser will read
478
297
  // out the default value.
@@ -482,7 +301,7 @@ function resolveCSSVariablePxValue(input, element) {
482
301
  // Set the new value, if this is invalid the previous value will be used.
483
302
  tmpEl.style.setProperty("margin-top", input, "important");
484
303
  // Reading the `margin-top` will already be in pixels (e.g.: 123px).
485
- let pxValue = parseFloat(window.getComputedStyle(tmpEl).marginTop) || 0;
304
+ const pxValue = parseFloat(window.getComputedStyle(tmpEl).marginTop) || 0;
486
305
  element.removeChild(tmpEl);
487
306
  return pxValue;
488
307
  }
@@ -0,0 +1,10 @@
1
+ import { type Snippet } from "svelte";
2
+ import { SvelteSet } from "svelte/reactivity";
3
+ export type FormFieldsContext = {
4
+ registerField: (field: Snippet) => () => void;
5
+ };
6
+ export declare const createFormFieldsContext: () => {
7
+ registerField: (field: Snippet) => () => boolean;
8
+ readonly fields: SvelteSet<Snippet<[]>>;
9
+ };
10
+ export declare const hoistFormFields: (fields: Snippet) => boolean;
@@ -0,0 +1,23 @@
1
+ import { getContext, setContext } from "svelte";
2
+ import { SvelteSet } from "svelte/reactivity";
3
+ export const createFormFieldsContext = () => {
4
+ const fields = new SvelteSet();
5
+ const context = {
6
+ registerField: (field) => {
7
+ fields.add(field);
8
+ return () => fields.delete(field);
9
+ },
10
+ get fields() {
11
+ return fields;
12
+ },
13
+ };
14
+ setContext("FormFieldsContext", context);
15
+ return context;
16
+ };
17
+ export const hoistFormFields = (fields) => {
18
+ const context = getContext("FormFieldsContext");
19
+ if (!context)
20
+ return false;
21
+ $effect(() => context.registerField(fields));
22
+ return true;
23
+ };
@@ -2,14 +2,14 @@
2
2
  </script>
3
3
 
4
4
  <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_LABEL_TAG">import { onMount } from "svelte";
5
- import { getIdContext, htmlid } from "../utils/id.js";
5
+ import { useProvidedId, htmlid } from "../utils/id.js";
6
6
  import { useDisabled } from "../hooks/use-disabled.js";
7
7
  import { stateFromSlot } from "../utils/state.js";
8
8
  import ElementOrComponent from "../utils/ElementOrComponent.svelte";
9
9
  import { useLabelContext } from "./context.svelte.js";
10
10
  const internalId = htmlid();
11
11
  const context = useLabelContext();
12
- const providedHtmlFor = getIdContext();
12
+ const providedHtmlFor = useProvidedId();
13
13
  const providedDisabled = useDisabled();
14
14
  let {
15
15
  ref = $bindable(),
@@ -26,8 +26,9 @@ let handleClick = (e) => {
26
26
  if (current instanceof HTMLLabelElement) {
27
27
  e.preventDefault();
28
28
  }
29
+ console.log("click", providedHtmlFor);
29
30
  if (current instanceof HTMLLabelElement) {
30
- let target = document.getElementById(current.getAttribute("htmlFor") ?? "");
31
+ let target = document.getElementById(current.getAttribute("for") ?? "");
31
32
  if (target) {
32
33
  let actuallyDisabled = target.getAttribute("disabled");
33
34
  if (actuallyDisabled === "true" || actuallyDisabled === "") {
@@ -44,11 +45,11 @@ let handleClick = (e) => {
44
45
  }
45
46
  }
46
47
  };
47
- const disabled = $derived(providedDisabled.value ?? false);
48
+ const disabled = $derived(providedDisabled.current ?? false);
48
49
  const slot = $derived({ disabled });
49
50
  const ourProps = $derived({
50
51
  id,
51
- htmlFor: passive ? void 0 : htmlFor,
52
+ for: passive ? void 0 : htmlFor,
52
53
  onclick: passive ? void 0 : handleClick,
53
54
  ...stateFromSlot(slot)
54
55
  });
@@ -7,18 +7,18 @@ export type LabelProps<TTag extends ElementType = typeof DEFAULT_LABEL_TAG> = Pr
7
7
  declare class __sveltets_Render<TTag extends ElementType = typeof DEFAULT_LABEL_TAG> {
8
8
  props(): {
9
9
  as?: TTag | undefined;
10
- } & (Exclude<keyof PropsOf<TTag>, "as" | "children" | "refName" | "class"> extends infer T extends keyof PropsOf<TTag> ? { [P in T]: PropsOf<TTag>[P]; } : never) & {
11
- children?: import("../utils/types.js").Children<{}> | undefined;
10
+ } & (Exclude<keyof PropsOf<TTag>, "slot" | "as" | "children" | "class" | "ref"> extends infer T extends keyof PropsOf<TTag> ? { [P in T]: PropsOf<TTag>[P]; } : never) & {
11
+ children?: import("svelte").Snippet<[{
12
+ slot: {};
13
+ props: Record<string, any>;
14
+ }]> | undefined;
15
+ class?: string | ((bag: {}) => string) | null | undefined;
12
16
  ref?: HTMLElement;
13
- } & (true extends (PropsOf<TTag> extends infer T_1 ? T_1 extends PropsOf<TTag> ? T_1 extends never ? never : "class" extends infer T_2 ? T_2 extends "class" ? T_2 extends keyof T_1 ? true : never : never : never : never : never) ? {
14
- class?: PropsOf<TTag>["class"] | ((bag: {}) => string) | undefined;
15
- } : {}) & {
17
+ } & {
16
18
  passive?: boolean;
17
19
  htmlFor?: string;
18
20
  };
19
- events(): {} & {
20
- [evt: string]: CustomEvent<any>;
21
- };
21
+ events(): {};
22
22
  slots(): {};
23
23
  bindings(): "ref";
24
24
  exports(): {};
@@ -27,9 +27,7 @@ interface $$IsomorphicComponent {
27
27
  new <TTag extends ElementType = typeof DEFAULT_LABEL_TAG>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TTag>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TTag>['props']>, ReturnType<__sveltets_Render<TTag>['events']>, ReturnType<__sveltets_Render<TTag>['slots']>> & {
28
28
  $$bindings?: ReturnType<__sveltets_Render<TTag>['bindings']>;
29
29
  } & ReturnType<__sveltets_Render<TTag>['exports']>;
30
- <TTag extends ElementType = typeof DEFAULT_LABEL_TAG>(internal: unknown, props: ReturnType<__sveltets_Render<TTag>['props']> & {
31
- $$events?: ReturnType<__sveltets_Render<TTag>['events']>;
32
- }): ReturnType<__sveltets_Render<TTag>['exports']>;
30
+ <TTag extends ElementType = typeof DEFAULT_LABEL_TAG>(internal: unknown, props: ReturnType<__sveltets_Render<TTag>['props']> & {}): ReturnType<__sveltets_Render<TTag>['exports']>;
33
31
  z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
34
32
  }
35
33
  declare const Label: $$IsomorphicComponent;
@@ -1,7 +1,7 @@
1
1
  import { getContext, setContext } from "svelte";
2
2
  export function useLabelContext() {
3
3
  let context = getContext("LabelContext");
4
- if (context === null) {
4
+ if (!context) {
5
5
  let err = new Error("You used a <Label /> component, but it is not inside a relevant parent.");
6
6
  if (Error.captureStackTrace)
7
7
  Error.captureStackTrace(err, useLabelContext);
@@ -1,8 +1,8 @@
1
1
  <script lang="ts" module>import { Label } from "../index.js";
2
- const DEFAULT_LEGEND_TAG = Label;
2
+ const DEFAULT_LEGEND_TAG = "div";
3
3
  </script>
4
4
 
5
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_LEGEND_TAG">let { ...props } = $props();
5
+ <script lang="ts">let { ...props } = $props();
6
6
  </script>
7
7
 
8
8
  <Label as="div" {...props} />
@@ -1,35 +1,7 @@
1
- import { type LabelProps } from "../index.js";
2
- import type { ElementType, Props } from "../utils/types.js";
3
- import type { Component } from "svelte";
4
- declare const DEFAULT_LEGEND_TAG: Component<LabelProps, any>;
1
+ import type { Props } from "../utils/types.js";
2
+ declare const DEFAULT_LEGEND_TAG: "div";
5
3
  type LegendRenderPropArg = {};
6
4
  type LegendPropsWeControl = never;
7
- export type LegendProps<TTag extends ElementType = typeof DEFAULT_LEGEND_TAG> = Props<TTag, LegendRenderPropArg, LegendPropsWeControl, {}>;
8
- declare class __sveltets_Render<TTag extends ElementType = typeof DEFAULT_LEGEND_TAG> {
9
- props(): {
10
- as?: TTag | undefined;
11
- } & (Exclude<keyof import("../index.js").PropsOf<TTag>, "as" | "children" | "refName" | "class"> extends infer T extends keyof import("../index.js").PropsOf<TTag> ? { [P in T]: import("../index.js").PropsOf<TTag>[P]; } : never) & {
12
- children?: import("../index.js").Children<LegendRenderPropArg> | undefined;
13
- ref?: HTMLElement;
14
- } & (true extends (import("../index.js").PropsOf<TTag> extends infer T_1 ? T_1 extends import("../index.js").PropsOf<TTag> ? T_1 extends never ? never : "class" extends infer T_2 ? T_2 extends "class" ? T_2 extends keyof T_1 ? true : never : never : never : never : never) ? {
15
- class?: import("../index.js").PropsOf<TTag>["class"] | ((bag: LegendRenderPropArg) => string) | undefined;
16
- } : {});
17
- events(): {} & {
18
- [evt: string]: CustomEvent<any>;
19
- };
20
- slots(): {};
21
- bindings(): "";
22
- exports(): {};
23
- }
24
- interface $$IsomorphicComponent {
25
- new <TTag extends ElementType = typeof DEFAULT_LEGEND_TAG>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TTag>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TTag>['props']>, ReturnType<__sveltets_Render<TTag>['events']>, ReturnType<__sveltets_Render<TTag>['slots']>> & {
26
- $$bindings?: ReturnType<__sveltets_Render<TTag>['bindings']>;
27
- } & ReturnType<__sveltets_Render<TTag>['exports']>;
28
- <TTag extends ElementType = typeof DEFAULT_LEGEND_TAG>(internal: unknown, props: ReturnType<__sveltets_Render<TTag>['props']> & {
29
- $$events?: ReturnType<__sveltets_Render<TTag>['events']>;
30
- }): ReturnType<__sveltets_Render<TTag>['exports']>;
31
- z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
32
- }
33
- declare const Legend: $$IsomorphicComponent;
34
- type Legend<TTag extends ElementType = typeof DEFAULT_LEGEND_TAG> = InstanceType<typeof Legend<TTag>>;
5
+ export type LegendProps = Props<typeof DEFAULT_LEGEND_TAG, LegendRenderPropArg, LegendPropsWeControl, {}>;
6
+ declare const Legend: import("svelte").Component<LegendProps, {}, "">;
35
7
  export default Legend;