@pzerelles/headlessui-svelte 2.1.2-next.2 → 2.1.2-next.20
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.d.ts +1 -1
- package/dist/checkbox/Checkbox.svelte +4 -4
- package/dist/checkbox/Checkbox.svelte.d.ts +5 -7
- package/dist/close-button/CloseButton.svelte.d.ts +2 -2
- package/dist/data-interactive/DataInteractive.svelte.d.ts +1 -1
- package/dist/description/Description.svelte.d.ts +1 -1
- package/dist/description/context.svelte.js +1 -1
- package/dist/dialog/Dialog.svelte.d.ts +1 -1
- package/dist/dialog/DialogBackdrop.svelte.d.ts +1 -1
- package/dist/dialog/DialogPanel.svelte +0 -1
- package/dist/dialog/DialogPanel.svelte.d.ts +1 -1
- package/dist/dialog/DialogTitle.svelte.d.ts +1 -1
- package/dist/dialog/InternalDialog.svelte.d.ts +1 -1
- package/dist/dialog/context.svelte.js +1 -1
- package/dist/field/Field.svelte +21 -3
- package/dist/field/Field.svelte.d.ts +1 -1
- package/dist/fieldset/Fieldset.svelte.d.ts +1 -1
- package/dist/focus-trap/FocusTrap.svelte +7 -14
- package/dist/focus-trap/FocusTrap.svelte.d.ts +3 -15
- package/dist/focus-trap/FocusTrapFeatures.d.ts +14 -0
- package/dist/focus-trap/FocusTrapFeatures.js +15 -0
- package/dist/hooks/use-controllable.svelte.js +2 -1
- package/dist/hooks/use-did-element-move.svelte.js +5 -10
- package/dist/hooks/use-event-listener.svelte.d.ts +1 -1
- package/dist/hooks/use-event-listener.svelte.js +3 -1
- package/dist/hooks/use-root-containers.svelte.d.ts +2 -2
- package/dist/hooks/use-root-containers.svelte.js +5 -5
- package/dist/hooks/use-tab-direction.svelte.js +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/input/Input.svelte +2 -2
- package/dist/input/Input.svelte.d.ts +5 -7
- package/dist/internal/FloatingProvider.svelte +12 -0
- package/dist/internal/{HoistFormFields.svelte.d.ts → FloatingProvider.svelte.d.ts} +5 -4
- package/dist/internal/FormFields.svelte +22 -19
- package/dist/internal/FormFieldsProvider.svelte +13 -0
- package/dist/internal/FormFieldsProvider.svelte.d.ts +21 -0
- package/dist/internal/Hidden.svelte +18 -8
- package/dist/internal/Hidden.svelte.d.ts +3 -6
- package/dist/internal/HiddenFeatures.d.ts +5 -0
- package/dist/internal/HiddenFeatures.js +9 -0
- package/dist/internal/floating-provider.svelte.d.ts +3 -0
- package/dist/internal/floating-provider.svelte.js +206 -0
- package/dist/internal/floating.svelte.d.ts +48 -23
- package/dist/internal/floating.svelte.js +79 -260
- package/dist/internal/form-fields.svelte.d.ts +10 -0
- package/dist/internal/form-fields.svelte.js +23 -0
- package/dist/label/Label.svelte +5 -4
- package/dist/label/Label.svelte.d.ts +1 -1
- package/dist/label/context.svelte.js +1 -1
- package/dist/legend/Legend.svelte +2 -2
- package/dist/legend/Legend.svelte.d.ts +18 -30
- package/dist/listbox/Listbox.svelte +42 -66
- package/dist/listbox/Listbox.svelte.d.ts +6 -65
- package/dist/listbox/ListboxButton.svelte +10 -10
- package/dist/listbox/ListboxButton.svelte.d.ts +5 -7
- package/dist/listbox/ListboxOption.svelte +10 -6
- package/dist/listbox/ListboxOption.svelte.d.ts +1 -1
- package/dist/listbox/ListboxOptions.svelte +108 -54
- package/dist/listbox/ListboxOptions.svelte.d.ts +1 -1
- package/dist/listbox/ListboxSelectedOption.svelte +2 -4
- package/dist/listbox/ListboxSelectedOption.svelte.d.ts +6 -6
- package/dist/listbox/context.svelte.d.ts +76 -0
- package/dist/listbox/context.svelte.js +36 -0
- package/dist/menu/Menu.svelte +5 -177
- package/dist/menu/Menu.svelte.d.ts +1 -1
- package/dist/menu/MenuButton.svelte +4 -2
- package/dist/menu/MenuButton.svelte.d.ts +1 -1
- package/dist/menu/MenuHeading.svelte.d.ts +1 -1
- package/dist/menu/MenuItem.svelte.d.ts +6 -5
- package/dist/menu/MenuItems.svelte +15 -11
- package/dist/menu/MenuItems.svelte.d.ts +1 -1
- package/dist/menu/MenuSection.svelte.d.ts +1 -1
- package/dist/menu/MenuSeparator.svelte.d.ts +1 -1
- package/dist/menu/context.svelte.d.ts +30 -1
- package/dist/menu/context.svelte.js +208 -0
- package/dist/popover/Popover.svelte +161 -0
- package/dist/popover/Popover.svelte.d.ts +41 -0
- package/dist/popover/PopoverBackdrop.svelte +56 -0
- package/dist/popover/PopoverBackdrop.svelte.d.ts +45 -0
- package/dist/popover/PopoverButton.svelte +246 -0
- package/dist/popover/PopoverButton.svelte.d.ts +46 -0
- package/dist/popover/PopoverGroup.svelte +43 -0
- package/dist/popover/PopoverGroup.svelte.d.ts +33 -0
- package/dist/popover/PopoverPanel.svelte +274 -0
- package/dist/popover/PopoverPanel.svelte.d.ts +53 -0
- package/dist/popover/context.svelte.d.ts +51 -0
- package/dist/popover/context.svelte.js +108 -0
- package/dist/popover/index.d.ts +5 -0
- package/dist/popover/index.js +5 -0
- package/dist/portal/InternalPortal.svelte.d.ts +1 -1
- package/dist/portal/PortalGroup.svelte.d.ts +1 -1
- package/dist/select/Select.svelte +74 -0
- package/dist/select/Select.svelte.d.ts +48 -0
- package/dist/select/index.d.ts +1 -0
- package/dist/select/index.js +1 -0
- package/dist/switch/Switch.svelte +30 -20
- package/dist/switch/Switch.svelte.d.ts +5 -5
- package/dist/switch/SwitchGroup.svelte.d.ts +1 -1
- package/dist/tabs/Tab.svelte.d.ts +1 -1
- package/dist/tabs/TabGroup.svelte.d.ts +2 -2
- package/dist/tabs/TabList.svelte.d.ts +1 -1
- package/dist/tabs/TabPanel.svelte.d.ts +1 -1
- package/dist/tabs/TabPanels.svelte.d.ts +1 -1
- 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.d.ts +1 -1
- package/dist/transition/Transition.svelte.d.ts +1 -1
- package/dist/transition/TransitionChild.svelte.d.ts +1 -1
- package/dist/transition/context.svelte.js +2 -2
- package/dist/utils/ElementOrComponent.svelte +2 -2
- package/dist/utils/ElementOrComponent.svelte.d.ts +2 -2
- package/dist/utils/Generic.svelte +0 -1
- package/dist/utils/Generic.svelte.d.ts +1 -2
- package/dist/utils/alternative-types.d.ts +1 -2
- package/dist/utils/floating-ui/svelte/components/FloatingNode.svelte +17 -0
- package/dist/utils/floating-ui/svelte/components/FloatingNode.svelte.d.ts +23 -0
- package/dist/utils/floating-ui/svelte/components/FloatingTree.svelte +50 -0
- package/dist/utils/floating-ui/svelte/components/FloatingTree.svelte.d.ts +41 -0
- package/dist/utils/floating-ui/svelte/hooks/useFloating.svelte.d.ts +6 -0
- package/dist/utils/floating-ui/svelte/hooks/useFloating.svelte.js +158 -0
- package/dist/utils/floating-ui/svelte/hooks/useFloatingRootContext.svelte.d.ts +11 -0
- package/dist/utils/floating-ui/svelte/hooks/useFloatingRootContext.svelte.js +53 -0
- package/dist/utils/floating-ui/svelte/hooks/useId.svelte.d.ts +9 -0
- package/dist/utils/floating-ui/svelte/hooks/useId.svelte.js +28 -0
- package/dist/utils/floating-ui/svelte/hooks/useInteractions.svelte.d.ts +23 -0
- package/dist/utils/floating-ui/svelte/hooks/useInteractions.svelte.js +72 -0
- package/dist/utils/floating-ui/svelte/index.d.ts +5 -0
- package/dist/utils/floating-ui/svelte/index.js +5 -0
- package/dist/utils/floating-ui/svelte/inner.svelte.d.ts +83 -0
- package/dist/utils/floating-ui/svelte/inner.svelte.js +178 -0
- package/dist/utils/floating-ui/svelte/types.d.ts +114 -0
- package/dist/utils/floating-ui/svelte/types.js +1 -0
- package/dist/utils/floating-ui/svelte/utils/createPubSub.d.ts +5 -0
- package/dist/utils/floating-ui/svelte/utils/createPubSub.js +14 -0
- package/dist/utils/floating-ui/svelte/utils/getFloatingFocusElement.d.ts +2 -0
- package/dist/utils/floating-ui/svelte/utils/getFloatingFocusElement.js +13 -0
- package/dist/utils/floating-ui/svelte/utils/log.d.ts +2 -0
- package/dist/utils/floating-ui/svelte/utils/log.js +19 -0
- package/dist/utils/floating-ui/svelte/utils.d.ts +19 -0
- package/dist/utils/floating-ui/svelte/utils.js +136 -0
- package/dist/utils/floating-ui/svelte-dom/arrow.d.ts +22 -0
- package/dist/utils/floating-ui/svelte-dom/arrow.js +29 -0
- package/dist/utils/floating-ui/svelte-dom/index.d.ts +2 -0
- package/dist/utils/floating-ui/svelte-dom/index.js +2 -0
- package/dist/utils/floating-ui/svelte-dom/types.d.ts +80 -0
- package/dist/utils/floating-ui/svelte-dom/types.js +3 -0
- package/dist/utils/floating-ui/svelte-dom/useFloating.svelte.d.ts +6 -0
- package/dist/utils/floating-ui/svelte-dom/useFloating.svelte.js +182 -0
- package/dist/utils/floating-ui/svelte-dom/utils/deepEqual.d.ts +1 -0
- package/dist/utils/floating-ui/svelte-dom/utils/deepEqual.js +50 -0
- package/dist/utils/floating-ui/svelte-dom/utils/getDPR.d.ts +1 -0
- package/dist/utils/floating-ui/svelte-dom/utils/getDPR.js +7 -0
- package/dist/utils/floating-ui/svelte-dom/utils/roundByDPR.d.ts +1 -0
- package/dist/utils/floating-ui/svelte-dom/utils/roundByDPR.js +5 -0
- package/dist/utils/floating-ui/svelte-dom/utils/useLatestRef.d.ts +4 -0
- package/dist/utils/floating-ui/svelte-dom/utils/useLatestRef.js +7 -0
- package/dist/utils/id.d.ts +1 -1
- package/dist/utils/id.js +1 -1
- package/dist/utils/style.d.ts +2 -0
- package/dist/utils/style.js +6 -0
- package/dist/utils/types.d.ts +1 -2
- package/package.json +25 -24
- package/dist/internal/HoistFormFields.svelte +0 -11
- package/dist/internal/id.d.ts +0 -8
- package/dist/internal/id.js +0 -11
|
@@ -1,47 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
-
/* eslint-disable prefer-const */
|
|
1
|
+
import { useInteractions } from "../utils/floating-ui/svelte/index.js";
|
|
4
2
|
import { useDisposables } from "../utils/disposables.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function useResolvedAnchor(anchor) {
|
|
19
|
-
if (!anchor)
|
|
20
|
-
return null; // Disable entirely
|
|
21
|
-
if (typeof anchor === "string")
|
|
22
|
-
return { to: anchor }; // Simple string based value,
|
|
23
|
-
return anchor; // User-provided value
|
|
3
|
+
import { getContext, untrack } from "svelte";
|
|
4
|
+
export { useFloatingProvider } from "./floating-provider.svelte.js";
|
|
5
|
+
export function useResolvedAnchor(options) {
|
|
6
|
+
const { anchor } = $derived(options);
|
|
7
|
+
return {
|
|
8
|
+
get anchor() {
|
|
9
|
+
if (!anchor)
|
|
10
|
+
return null; // Disable entirely
|
|
11
|
+
if (typeof anchor === "string")
|
|
12
|
+
return { to: anchor }; // Simple string based value,
|
|
13
|
+
return anchor; // User-provided value
|
|
14
|
+
},
|
|
15
|
+
};
|
|
24
16
|
}
|
|
25
|
-
export function
|
|
26
|
-
|
|
17
|
+
export function useFloatingReference() {
|
|
18
|
+
const context = getContext("FloatingContext");
|
|
19
|
+
return {
|
|
20
|
+
get setReference() {
|
|
21
|
+
return context.setReference;
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function useFloatingReferenceProps() {
|
|
26
|
+
const context = getContext("FloatingContext");
|
|
27
|
+
return {
|
|
28
|
+
get getReferenceProps() {
|
|
29
|
+
return context.getReferenceProps;
|
|
30
|
+
},
|
|
31
|
+
};
|
|
27
32
|
}
|
|
28
33
|
export function useFloatingPanelProps() {
|
|
29
|
-
const
|
|
34
|
+
const context = getContext("FloatingContext");
|
|
35
|
+
const { getFloatingProps, slot } = $derived(context);
|
|
30
36
|
return (...args) => {
|
|
31
37
|
return Object.assign({}, getFloatingProps(...args), {
|
|
32
38
|
"data-anchor": slot.anchor,
|
|
33
39
|
});
|
|
34
40
|
};
|
|
35
41
|
}
|
|
36
|
-
export function useFloatingPanel(options) {
|
|
37
|
-
const placement = $derived.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
const
|
|
42
|
+
export function useFloatingPanel(options = { placement: null }) {
|
|
43
|
+
const placement = $derived(options.placement === false
|
|
44
|
+
? null
|
|
45
|
+
: typeof options.placement === "string"
|
|
46
|
+
? { to: options.placement }
|
|
47
|
+
: options.placement);
|
|
48
|
+
//if (placement === false) placement = null // Disable entirely
|
|
49
|
+
//if (typeof placement === "string") placement = { to: placement } // Simple string based value
|
|
50
|
+
const placementContext = getContext("PlacementContext");
|
|
51
|
+
const { updatePlacementConfig } = $derived(placementContext);
|
|
45
52
|
const trigger = $derived(JSON.stringify(placement, typeof HTMLElement !== "undefined"
|
|
46
53
|
? (_, v) => {
|
|
47
54
|
if (v instanceof HTMLElement) {
|
|
@@ -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
|
|
73
|
+
get styles() {
|
|
66
74
|
return placement ? context.styles : undefined;
|
|
67
75
|
},
|
|
68
76
|
};
|
|
69
77
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
export const createFloatingContext = ({ enabled = true } = {}) => {
|
|
73
|
-
let config = $state(null);
|
|
74
|
-
//let innerOffset = $state(0)
|
|
75
|
-
//let overflowRef = $state<HTMLElement | null>(null)
|
|
76
|
-
let referenceEl = $state(null);
|
|
77
|
-
let floatingEl = $state(null);
|
|
78
|
-
$effect(() => useFixScrollingPixel(floatingEl));
|
|
79
|
-
const isEnabled = $derived(enabled && config !== null && floatingEl !== null);
|
|
80
|
-
const { to: placement = "bottom", gap = 0, offset = 0, padding = 0, inner, } = $derived(useResolvedConfig({
|
|
81
|
-
get config() {
|
|
82
|
-
return config;
|
|
83
|
-
},
|
|
84
|
-
get element() {
|
|
85
|
-
return floatingEl;
|
|
86
|
-
},
|
|
87
|
-
}));
|
|
88
|
-
const [to, align = "center"] = $derived(placement.split(" "));
|
|
89
|
-
// Reset
|
|
90
|
-
$effect(() => {
|
|
91
|
-
if (!isEnabled)
|
|
92
|
-
return;
|
|
93
|
-
//innerOffset = 0
|
|
94
|
-
});
|
|
95
|
-
let floatingStyles = $state();
|
|
96
|
-
let context = $state();
|
|
97
|
-
let currentComputeId = $state(0);
|
|
78
|
+
export function useFixScrollingPixel(options) {
|
|
79
|
+
const { element } = $derived(options);
|
|
98
80
|
$effect(() => {
|
|
99
|
-
if (!
|
|
81
|
+
if (!element)
|
|
100
82
|
return;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
offsetMiddleware({
|
|
122
|
-
mainAxis: to === "selection" ? 0 : gap,
|
|
123
|
-
crossAxis: offset,
|
|
124
|
-
}),
|
|
125
|
-
// When the panel overflows the viewport, we will try to nudge the panel to the other side to
|
|
126
|
-
// ensure it's not clipped. We use the `padding` to define the minimum space between the
|
|
127
|
-
// panel and the viewport.
|
|
128
|
-
shiftMiddleware({ padding }),
|
|
129
|
-
// The `flip` middleware will swap the `placement` of the panel if there is not enough room.
|
|
130
|
-
// This is not compatible with the `inner` middleware (which is only enabled when `to` is set
|
|
131
|
-
// to "selection").
|
|
132
|
-
to !== "selection" && flipMiddleware({ padding }),
|
|
133
|
-
// The `inner` middleware will ensure the panel is always fully visible on screen and
|
|
134
|
-
// positioned on top of the reference and moved to the currently selected item.
|
|
135
|
-
to === "selection" && inner
|
|
136
|
-
? null /* TODO: use inner when available: innerMiddleware({
|
|
137
|
-
...inner,
|
|
138
|
-
padding, // For overflow detection
|
|
139
|
-
overflowRef,
|
|
140
|
-
offset: innerOffset,
|
|
141
|
-
minItemsVisible: MINIMUM_ITEMS_VISIBLE,
|
|
142
|
-
referenceOverflowThreshold: padding,
|
|
143
|
-
onFallbackChange(fallback) {
|
|
144
|
-
if (!fallback) return
|
|
145
|
-
let parent = context.elements.floating
|
|
146
|
-
if (!parent) return
|
|
147
|
-
let scrollPaddingBottom =
|
|
148
|
-
parseFloat(getComputedStyle(parent!).scrollPaddingBottom) || 0
|
|
149
|
-
|
|
150
|
-
// We want at least X visible items, but if there are less than X items in the list,
|
|
151
|
-
// we want to show as many as possible.
|
|
152
|
-
let missing = Math.min(MINIMUM_ITEMS_VISIBLE, parent.childElementCount)
|
|
153
|
-
|
|
154
|
-
let elementHeight = 0
|
|
155
|
-
let elementAmountVisible = 0
|
|
156
|
-
|
|
157
|
-
for (let child of context.elements.floating?.childNodes ?? []) {
|
|
158
|
-
if (child instanceof HTMLElement) {
|
|
159
|
-
let childTop = child.offsetTop
|
|
160
|
-
// It can be that the child is fully visible, but we also want to keep the scroll
|
|
161
|
-
// padding into account to ensure the UI looks good. Therefore we fake that the
|
|
162
|
-
// bottom of the child is actually `scrollPaddingBottom` amount of pixels lower.
|
|
163
|
-
let childBottom = childTop + child.clientHeight + scrollPaddingBottom
|
|
164
|
-
|
|
165
|
-
let parentTop = parent.scrollTop
|
|
166
|
-
let parentBottom = parentTop + parent.clientHeight
|
|
167
|
-
|
|
168
|
-
// Figure out if the child is fully visible in the scroll parent.
|
|
169
|
-
if (childTop >= parentTop && childBottom <= parentBottom) {
|
|
170
|
-
missing--
|
|
171
|
-
} else {
|
|
172
|
-
// Not fully visible, so we will use this child to calculate the height of
|
|
173
|
-
// each item. We will also use this to calculate how much of the item is
|
|
174
|
-
// already visible.
|
|
175
|
-
elementAmountVisible = Math.max(
|
|
176
|
-
0,
|
|
177
|
-
Math.min(childBottom, parentBottom) - Math.max(childTop, parentTop)
|
|
178
|
-
)
|
|
179
|
-
elementHeight = child.clientHeight
|
|
180
|
-
break
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// There are fewer visible items than we want, so we will try to nudge the offset
|
|
186
|
-
// to show more items.
|
|
187
|
-
if (missing >= 1) {
|
|
188
|
-
setInnerOffset((existingOffset) => {
|
|
189
|
-
let newInnerOffset =
|
|
190
|
-
elementHeight * missing - // `missing` amount of `elementHeight`
|
|
191
|
-
elementAmountVisible + // The amount of the last item that is visible
|
|
192
|
-
scrollPaddingBottom // The scroll padding to ensure the UI looks good
|
|
193
|
-
|
|
194
|
-
// Nudged enough already, no need to continue
|
|
195
|
-
if (existingOffset >= newInnerOffset) {
|
|
196
|
-
return existingOffset
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return newInnerOffset
|
|
200
|
-
})
|
|
201
|
-
}
|
|
202
|
-
},
|
|
203
|
-
})*/
|
|
204
|
-
: null,
|
|
205
|
-
// The `size` middleware will ensure the panel is never bigger than the viewport minus the
|
|
206
|
-
// provided `padding` that we want.
|
|
207
|
-
sizeMiddleware({
|
|
208
|
-
padding,
|
|
209
|
-
apply({ availableWidth, availableHeight, elements }) {
|
|
210
|
-
Object.assign(elements.floating.style, {
|
|
211
|
-
overflow: "auto",
|
|
212
|
-
maxWidth: `${availableWidth}px`,
|
|
213
|
-
maxHeight: `min(var(--anchor-max-height, 100vh), ${availableHeight}px)`,
|
|
214
|
-
});
|
|
215
|
-
},
|
|
216
|
-
}),
|
|
217
|
-
].filter(Boolean),
|
|
218
|
-
}).then((res) => {
|
|
219
|
-
if (currentComputeId === computeId) {
|
|
220
|
-
// Ensure only the last compute updates the context if multiple are running in parallel
|
|
221
|
-
context = res;
|
|
222
|
-
const { x, y } = res;
|
|
223
|
-
floatingStyles = `position: absolute; left: ${x}px; top: ${y}px;`;
|
|
224
|
-
}
|
|
83
|
+
untrack(() => {
|
|
84
|
+
let observer = new MutationObserver(() => {
|
|
85
|
+
let maxHeight = window.getComputedStyle(element).maxHeight;
|
|
86
|
+
let maxHeightFloat = parseFloat(maxHeight);
|
|
87
|
+
if (isNaN(maxHeightFloat))
|
|
88
|
+
return;
|
|
89
|
+
let 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(
|
|
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?.
|
|
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?.
|
|
126
|
+
return config?.padding ?? "var(--anchor-padding, 0)";
|
|
311
127
|
},
|
|
312
128
|
get element() {
|
|
313
129
|
return element;
|
|
@@ -331,7 +147,8 @@ function useResolvedConfig({ config, element, }) {
|
|
|
331
147
|
},
|
|
332
148
|
};
|
|
333
149
|
}
|
|
334
|
-
function useResolvePxValue(
|
|
150
|
+
function useResolvePxValue(options) {
|
|
151
|
+
const { input, element, defaultValue } = $derived(options);
|
|
335
152
|
let d = useDisposables();
|
|
336
153
|
const computeValue = (value, element) => {
|
|
337
154
|
// Nullish
|
|
@@ -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
|
|
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
|
-
|
|
422
|
-
value
|
|
240
|
+
const [value, watcher] = computeValue(input, element);
|
|
241
|
+
setValue(value);
|
|
423
242
|
if (!watcher)
|
|
424
243
|
return;
|
|
425
|
-
return watcher(
|
|
244
|
+
return watcher(setValue);
|
|
426
245
|
});
|
|
427
246
|
return {
|
|
428
247
|
get value() {
|
|
@@ -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
|
+
};
|
package/dist/label/Label.svelte
CHANGED
|
@@ -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 {
|
|
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 =
|
|
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("
|
|
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 === "") {
|
|
@@ -48,7 +49,7 @@ const disabled = $derived(providedDisabled.value ?? false);
|
|
|
48
49
|
const slot = $derived({ disabled });
|
|
49
50
|
const ourProps = $derived({
|
|
50
51
|
id,
|
|
51
|
-
|
|
52
|
+
for: passive ? void 0 : htmlFor,
|
|
52
53
|
onclick: passive ? void 0 : handleClick,
|
|
53
54
|
...stateFromSlot(slot)
|
|
54
55
|
});
|
|
@@ -8,7 +8,7 @@ declare class __sveltets_Render<TTag extends ElementType = typeof DEFAULT_LABEL_
|
|
|
8
8
|
props(): {
|
|
9
9
|
as?: TTag | undefined;
|
|
10
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("
|
|
11
|
+
children?: import("svelte").Snippet<[{}, Record<string, any>]> | undefined;
|
|
12
12
|
ref?: HTMLElement;
|
|
13
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
14
|
class?: PropsOf<TTag>["class"] | ((bag: {}) => string) | undefined;
|
|
@@ -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
|
|
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 =
|
|
2
|
+
const DEFAULT_LEGEND_TAG = "div";
|
|
3
3
|
</script>
|
|
4
4
|
|
|
5
|
-
<script lang="ts"
|
|
5
|
+
<script lang="ts">let { ...props } = $props();
|
|
6
6
|
</script>
|
|
7
7
|
|
|
8
8
|
<Label as="div" {...props} />
|
|
@@ -1,35 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} &
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
[evt: string]: CustomEvent<any>;
|
|
5
|
+
export type LegendProps = Props<typeof DEFAULT_LEGEND_TAG, LegendRenderPropArg, LegendPropsWeControl, {}>;
|
|
6
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
7
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
8
|
+
$$bindings?: Bindings;
|
|
9
|
+
} & Exports;
|
|
10
|
+
(internal: unknown, props: Props & {
|
|
11
|
+
$$events?: Events;
|
|
12
|
+
$$slots?: Slots;
|
|
13
|
+
}): Exports & {
|
|
14
|
+
$set?: any;
|
|
15
|
+
$on?: any;
|
|
19
16
|
};
|
|
20
|
-
|
|
21
|
-
bindings(): "";
|
|
22
|
-
exports(): {};
|
|
17
|
+
z_$$bindings?: Bindings;
|
|
23
18
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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>>;
|
|
19
|
+
declare const Legend: $$__sveltets_2_IsomorphicComponent<LegendProps, {
|
|
20
|
+
[evt: string]: CustomEvent<any>;
|
|
21
|
+
}, {}, {}, "">;
|
|
22
|
+
type Legend = InstanceType<typeof Legend>;
|
|
35
23
|
export default Legend;
|