@pzerelles/headlessui-svelte 2.1.2-next.29 → 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 (67) hide show
  1. package/dist/button/Button.svelte +54 -84
  2. package/dist/checkbox/Checkbox.svelte +120 -173
  3. package/dist/checkbox/Checkbox.svelte.d.ts +1 -1
  4. package/dist/close-button/CloseButton.svelte +6 -12
  5. package/dist/combobox/Combobox.svelte +3 -50
  6. package/dist/data-interactive/DataInteractive.svelte +29 -55
  7. package/dist/description/Description.svelte +21 -31
  8. package/dist/dialog/Dialog.svelte +228 -320
  9. package/dist/dialog/DialogBackdrop.svelte +12 -29
  10. package/dist/dialog/DialogPanel.svelte +25 -48
  11. package/dist/dialog/DialogTitle.svelte +23 -38
  12. package/dist/field/Field.svelte +25 -47
  13. package/dist/fieldset/Fieldset.svelte +29 -50
  14. package/dist/focus-trap/FocusTrap.svelte +283 -419
  15. package/dist/input/Input.svelte +53 -84
  16. package/dist/internal/FloatingProvider.svelte +9 -14
  17. package/dist/internal/FocusSentinel.svelte +8 -16
  18. package/dist/internal/ForcePortalRoot.svelte +3 -7
  19. package/dist/internal/FormFields.svelte +34 -47
  20. package/dist/internal/FormFieldsProvider.svelte +5 -9
  21. package/dist/internal/FormResolver.svelte +15 -20
  22. package/dist/internal/Hidden.svelte +29 -50
  23. package/dist/internal/MainTreeProvider.svelte +36 -89
  24. package/dist/internal/Portal.svelte +14 -18
  25. package/dist/label/Label.svelte +58 -93
  26. package/dist/legend/Legend.svelte +3 -12
  27. package/dist/listbox/Listbox.svelte +387 -525
  28. package/dist/listbox/Listbox.svelte.d.ts +1 -1
  29. package/dist/listbox/ListboxButton.svelte +127 -173
  30. package/dist/listbox/ListboxOption.svelte +129 -170
  31. package/dist/listbox/ListboxOptions.svelte +304 -400
  32. package/dist/listbox/ListboxSelectedOption.svelte +15 -38
  33. package/dist/menu/Menu.svelte +51 -78
  34. package/dist/menu/MenuButton.svelte +117 -157
  35. package/dist/menu/MenuHeading.svelte +14 -32
  36. package/dist/menu/MenuItem.svelte +107 -142
  37. package/dist/menu/MenuItems.svelte +229 -301
  38. package/dist/menu/MenuSection.svelte +9 -24
  39. package/dist/menu/MenuSeparator.svelte +4 -17
  40. package/dist/popover/Popover.svelte +150 -216
  41. package/dist/popover/PopoverBackdrop.svelte +41 -67
  42. package/dist/popover/PopoverButton.svelte +212 -292
  43. package/dist/popover/PopoverGroup.svelte +35 -62
  44. package/dist/popover/PopoverPanel.svelte +229 -311
  45. package/dist/portal/InternalPortal.svelte +85 -141
  46. package/dist/portal/Portal.svelte +2 -5
  47. package/dist/portal/PortalGroup.svelte +9 -30
  48. package/dist/select/Select.svelte +68 -98
  49. package/dist/switch/Switch.svelte +132 -179
  50. package/dist/switch/SwitchGroup.svelte +31 -44
  51. package/dist/tabs/Tab.svelte +142 -194
  52. package/dist/tabs/TabGroup.svelte +56 -86
  53. package/dist/tabs/TabGroup.svelte.d.ts +1 -1
  54. package/dist/tabs/TabList.svelte +11 -31
  55. package/dist/tabs/TabPanel.svelte +42 -67
  56. package/dist/tabs/TabPanels.svelte +7 -18
  57. package/dist/textarea/Textarea.svelte +53 -84
  58. package/dist/transition/InternalTransitionChild.svelte +170 -259
  59. package/dist/transition/Transition.svelte +66 -96
  60. package/dist/transition/TransitionChild.svelte +11 -31
  61. package/dist/utils/DisabledProvider.svelte +3 -7
  62. package/dist/utils/ElementOrComponent.svelte +23 -43
  63. package/dist/utils/Generic.svelte +16 -27
  64. package/dist/utils/StableCollection.svelte +36 -54
  65. package/dist/utils/floating-ui/svelte/components/FloatingNode.svelte +12 -27
  66. package/dist/utils/floating-ui/svelte/components/FloatingTree.svelte +44 -88
  67. package/package.json +4 -4
@@ -1,151 +1,95 @@
1
- <script lang="ts" module>
2
- import { usePortalRoot } from "../internal/portal-force-root.svelte.js"
3
- import { getOwnerDocument } from "../utils/owner.js"
4
- import { getContext, onMount, setContext } from "svelte"
5
- import { env } from "../utils/env.js"
6
- import type { ElementType, Props } from "../utils/types.js"
7
- import type { PortalGroupContext } from "./PortalGroup.svelte"
8
-
9
- function usePortalTarget(options: { element: HTMLElement | null }): { readonly target: HTMLElement | null } {
10
- const { element } = $derived(options)
11
- const forceInRoot = usePortalRoot()
12
- const portalGroupContext = getContext<PortalGroupContext>("PortalGroupContext")
13
- const { target: groupTarget } = $derived(portalGroupContext ?? {})
14
-
15
- const ownerDocument = $derived(getOwnerDocument(element))
16
-
17
- const initialTarget = () => {
18
- // Group context is used, but still null
19
- if (!forceInRoot?.force && groupTarget) return groupTarget ?? null
20
-
21
- // No group context is used, let's create a default portal root
22
- if (env.isServer) return null
23
- let existingRoot = ownerDocument?.getElementById("headlessui-portal-root")
24
- if (existingRoot) return existingRoot
25
-
26
- if (ownerDocument === null) return null
27
-
28
- let root = ownerDocument.createElement("div")
29
- root.setAttribute("id", "headlessui-portal-root")
30
- return ownerDocument.body.appendChild(root)
31
- }
32
-
33
- let target = $state(initialTarget())
34
-
35
- // Ensure the portal root is always in the DOM
36
- $effect(() => {
37
- if (!target) return
38
-
39
- if (!ownerDocument?.body.contains(target)) {
40
- ownerDocument?.body.appendChild(target)
41
- }
42
- })
43
-
44
- $effect(() => {
45
- if (forceInRoot?.force) return
46
- if (!groupTarget) return
47
- target = groupTarget
48
- })
49
-
50
- return {
51
- get target() {
52
- return target
53
- },
54
- }
55
- }
56
-
57
- // ---
58
-
59
- type PortalParentContext = {
60
- register: (portal: HTMLElement) => () => void
61
- unregister: (portal: HTMLElement) => void
62
- readonly portals: HTMLElement[]
63
- }
64
-
65
- export function useNestedPortals() {
66
- const parent = getContext<PortalParentContext>("PortalParentContext")
67
- const portals = $state<HTMLElement[]>([])
68
-
69
- const register = (portal: HTMLElement) => {
70
- portals.push(portal)
71
- if (parent) parent.register(portal)
72
- return () => unregister(portal)
73
- }
74
-
75
- const unregister = (portal: HTMLElement) => {
76
- let idx = portals.indexOf(portal)
77
- if (idx !== -1) portals.splice(idx, 1)
78
- if (parent) parent.unregister(portal)
1
+ <script lang="ts" module>import { usePortalRoot } from "../internal/portal-force-root.svelte.js";
2
+ import { getOwnerDocument } from "../utils/owner.js";
3
+ import { getContext, onMount, setContext } from "svelte";
4
+ import { env } from "../utils/env.js";
5
+ function usePortalTarget(options) {
6
+ const { element } = $derived(options);
7
+ const forceInRoot = usePortalRoot();
8
+ const portalGroupContext = getContext("PortalGroupContext");
9
+ const { target: groupTarget } = $derived(portalGroupContext ?? {});
10
+ const ownerDocument = $derived(getOwnerDocument(element));
11
+ const initialTarget = () => {
12
+ if (!forceInRoot?.force && groupTarget) return groupTarget ?? null;
13
+ if (env.isServer) return null;
14
+ let existingRoot = ownerDocument?.getElementById("headlessui-portal-root");
15
+ if (existingRoot) return existingRoot;
16
+ if (ownerDocument === null) return null;
17
+ let root = ownerDocument.createElement("div");
18
+ root.setAttribute("id", "headlessui-portal-root");
19
+ return ownerDocument.body.appendChild(root);
20
+ };
21
+ let target = $state(initialTarget());
22
+ $effect(() => {
23
+ if (!target) return;
24
+ if (!ownerDocument?.body.contains(target)) {
25
+ ownerDocument?.body.appendChild(target);
79
26
  }
80
-
81
- const context: PortalParentContext = {
82
- register,
83
- unregister,
84
- get portals() {
85
- return portals
86
- },
27
+ });
28
+ $effect(() => {
29
+ if (forceInRoot?.force) return;
30
+ if (!groupTarget) return;
31
+ target = groupTarget;
32
+ });
33
+ return {
34
+ get target() {
35
+ return target;
87
36
  }
88
- setContext("PortalParentContext", context)
89
-
90
- return context
91
- }
92
-
93
- // ---
94
-
95
- export const DEFAULT_PORTAL_TAG = "div"
96
- type PortalRenderPropArg = {}
97
- type PortalPropsWeControl = never
98
-
99
- export type PortalProps<TTag extends ElementType = typeof DEFAULT_PORTAL_TAG> = Props<
100
- TTag,
101
- PortalRenderPropArg,
102
- PortalPropsWeControl,
103
- {
104
- enabled?: boolean
37
+ };
38
+ }
39
+ export function useNestedPortals() {
40
+ const parent = getContext("PortalParentContext");
41
+ const portals = $state([]);
42
+ const register = (portal) => {
43
+ portals.push(portal);
44
+ if (parent) parent.register(portal);
45
+ return () => unregister(portal);
46
+ };
47
+ const unregister = (portal) => {
48
+ let idx = portals.indexOf(portal);
49
+ if (idx !== -1) portals.splice(idx, 1);
50
+ if (parent) parent.unregister(portal);
51
+ };
52
+ const context = {
53
+ register,
54
+ unregister,
55
+ get portals() {
56
+ return portals;
105
57
  }
106
- >
58
+ };
59
+ setContext("PortalParentContext", context);
60
+ return context;
61
+ }
62
+ export const DEFAULT_PORTAL_TAG = "div";
107
63
  </script>
108
64
 
109
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_PORTAL_TAG">
110
- import ElementOrComponent from "../utils/ElementOrComponent.svelte"
111
-
112
- let { ref = $bindable(), ...theirProps }: { as?: TTag } & PortalProps<TTag> = $props()
113
-
114
- const portalTarget = usePortalTarget({
115
- get element() {
116
- return ref ?? null
117
- },
118
- })
119
- const { target } = $derived(portalTarget)
120
- const parent = getContext<PortalParentContext>("PortalParentContext")
121
- //const ready = useServerHandoffComplete()
122
-
123
- $effect(() => {
124
- if (!target || !ref) return
125
-
126
- // Element already exists in target, always calling target.appendChild(element) will cause a
127
- // brief unmount/remount.
128
- if (ref.parentNode !== target) {
129
- ref.setAttribute("data-headlessui-portal", "")
130
- target.appendChild(ref)
65
+ <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_PORTAL_TAG">import ElementOrComponent from "../utils/ElementOrComponent.svelte";
66
+ let { ref = $bindable(), ...theirProps } = $props();
67
+ const portalTarget = usePortalTarget({
68
+ get element() {
69
+ return ref ?? null;
70
+ }
71
+ });
72
+ const { target } = $derived(portalTarget);
73
+ const parent = getContext("PortalParentContext");
74
+ $effect(() => {
75
+ if (!target || !ref) return;
76
+ if (ref.parentNode !== target) {
77
+ ref.setAttribute("data-headlessui-portal", "");
78
+ target.appendChild(ref);
79
+ }
80
+ });
81
+ onMount(() => {
82
+ if (parent) parent.register(ref);
83
+ return () => {
84
+ if (!target || !ref) return;
85
+ if (ref instanceof Node && target.contains(ref)) {
86
+ target.removeChild(ref);
131
87
  }
132
- })
133
-
134
- onMount(() => {
135
- if (parent) parent.register(ref!)
136
-
137
- return () => {
138
- if (!target || !ref) return
139
-
140
- if (ref instanceof Node && target.contains(ref)) {
141
- target.removeChild(ref)
142
- }
143
-
144
- if (target.childNodes.length <= 0) {
145
- target.parentElement?.removeChild(target)
146
- }
88
+ if (target.childNodes.length <= 0) {
89
+ target.parentElement?.removeChild(target);
147
90
  }
148
- })
91
+ };
92
+ });
149
93
  </script>
150
94
 
151
95
  {#if target}
@@ -1,8 +1,5 @@
1
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_PORTAL_TAG">
2
- import type { ElementType } from "../utils/types.js"
3
- import InternalPortal, { DEFAULT_PORTAL_TAG, type PortalProps } from "./InternalPortal.svelte"
4
-
5
- let { ref = $bindable(), enabled = true, ...theirProps }: PortalProps<TTag> = $props()
1
+ <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_PORTAL_TAG">import InternalPortal, { DEFAULT_PORTAL_TAG } from "./InternalPortal.svelte";
2
+ let { ref = $bindable(), enabled = true, ...theirProps } = $props();
6
3
  </script>
7
4
 
8
5
  {#if enabled}
@@ -1,35 +1,14 @@
1
- <script lang="ts" module>
2
- import type { ElementType, Props } from "../utils/types.js"
3
-
4
- const DEFAULT_GROUP_TAG = "svelte:fragment"
5
- type GroupRenderPropArg = {}
6
- type GroupPropsWeControl = never
7
-
8
- export type PortalGroupContext = {
9
- readonly target: HTMLElement | null
10
- }
11
-
12
- export type PortalGroupProps<TTag extends ElementType = typeof DEFAULT_GROUP_TAG> = Props<
13
- TTag,
14
- GroupRenderPropArg,
15
- GroupPropsWeControl,
16
- {
17
- target: HTMLElement | null
18
- }
19
- >
1
+ <script lang="ts" module>const DEFAULT_GROUP_TAG = "svelte:fragment";
20
2
  </script>
21
3
 
22
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_GROUP_TAG">
23
- import ElementOrComponent from "../utils/ElementOrComponent.svelte"
24
- import { setContext } from "svelte"
25
-
26
- let { ref = $bindable(), target, ...theirProps }: { as?: TTag } & PortalGroupProps<TTag> = $props()
27
-
28
- setContext("PortalGroupContext", {
29
- get target() {
30
- return target
31
- },
32
- })
4
+ <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_GROUP_TAG">import ElementOrComponent from "../utils/ElementOrComponent.svelte";
5
+ import { setContext } from "svelte";
6
+ let { ref = $bindable(), target, ...theirProps } = $props();
7
+ setContext("PortalGroupContext", {
8
+ get target() {
9
+ return target;
10
+ }
11
+ });
33
12
  </script>
34
13
 
35
14
  <ElementOrComponent {theirProps} defaultTag={DEFAULT_GROUP_TAG} name="PortalGroup" bind:ref />
@@ -1,104 +1,74 @@
1
- <script lang="ts" module>
2
- import type { ElementType, Props, PropsOf } from "../utils/types.js"
3
-
4
- let DEFAULT_SELECT_TAG = "select" as const
5
-
6
- type SelectRenderPropArg = {
7
- disabled: boolean
8
- hover: boolean
9
- focus: boolean
10
- active: boolean
11
- autofocus: boolean
12
- invalid: boolean
13
- }
14
- type SelectPropsWeControl = "aria-labelledby" | "aria-describedby"
15
-
16
- export type SelectProps<TTag extends ElementType = typeof DEFAULT_SELECT_TAG> = Props<
17
- TTag,
18
- SelectRenderPropArg,
19
- SelectPropsWeControl,
20
- {
21
- disabled?: boolean
22
- invalid?: boolean
23
- autofocus?: boolean
24
- }
25
- >
1
+ <script lang="ts" module>let DEFAULT_SELECT_TAG = "select";
26
2
  </script>
27
3
 
28
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_SELECT_TAG">
29
- import { useId } from "../hooks/use-id.js"
30
- import { useProvidedId } from "../utils/id.js"
31
- import { useDisabled } from "../hooks/use-disabled.js"
32
- import { useFocusRing } from "../hooks/use-focus-ring.svelte.js"
33
- import { useHover } from "../hooks/use-hover.svelte.js"
34
- import { useActivePress } from "../hooks/use-active-press.svelte.js"
35
- import { useLabelledBy } from "../label/context.svelte.js"
36
- import { useDescribedBy } from "../description/context.svelte.js"
37
- import { mergeProps } from "../utils/render.js"
38
- import ElementOrComponent from "../utils/ElementOrComponent.svelte"
39
-
40
- const internalId = useId()
41
- const providedId = useProvidedId()
42
- const providedDisabled = useDisabled()
43
- let {
44
- ref = $bindable(),
45
- id = (providedId || `headlessui-select-${internalId}`) as PropsOf<TTag>["id"],
46
- disabled: theirDisabled = false,
47
- invalid = false,
48
- autofocus = false,
49
- ...theirProps
50
- }: { as?: TTag } & SelectProps<TTag> = $props()
51
-
52
- const disabled = $derived(providedDisabled.current ?? theirDisabled)
53
- const labelledBy = useLabelledBy()
54
- const describedBy = useDescribedBy()
55
-
56
- const { isFocusVisible: focus, focusProps } = $derived(
57
- useFocusRing({
58
- get autofocus() {
59
- return autofocus
60
- },
61
- })
62
- )
63
- const { isHovered: hover, hoverProps } = $derived(
64
- useHover({
65
- get disabled() {
66
- return disabled
67
- },
68
- })
69
- )
70
- const { pressed: active, pressProps } = $derived(
71
- useActivePress({
72
- get disabled() {
73
- return disabled
74
- },
75
- })
76
- )
77
-
78
- const ourProps = $derived(
79
- mergeProps(
80
- {
81
- id,
82
- "aria-labelledby": labelledBy.value,
83
- "aria-describedby": describedBy.value,
84
- "aria-invalid": invalid ? "" : undefined,
85
- disabled: disabled || undefined,
86
- autofocus,
87
- },
88
- focusProps,
89
- hoverProps,
90
- pressProps
91
- )
4
+ <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_SELECT_TAG">import { useId } from "../hooks/use-id.js";
5
+ import { useProvidedId } from "../utils/id.js";
6
+ import { useDisabled } from "../hooks/use-disabled.js";
7
+ import { useFocusRing } from "../hooks/use-focus-ring.svelte.js";
8
+ import { useHover } from "../hooks/use-hover.svelte.js";
9
+ import { useActivePress } from "../hooks/use-active-press.svelte.js";
10
+ import { useLabelledBy } from "../label/context.svelte.js";
11
+ import { useDescribedBy } from "../description/context.svelte.js";
12
+ import { mergeProps } from "../utils/render.js";
13
+ import ElementOrComponent from "../utils/ElementOrComponent.svelte";
14
+ const internalId = useId();
15
+ const providedId = useProvidedId();
16
+ const providedDisabled = useDisabled();
17
+ let {
18
+ ref = $bindable(),
19
+ id = providedId || `headlessui-select-${internalId}`,
20
+ disabled: theirDisabled = false,
21
+ invalid = false,
22
+ autofocus = false,
23
+ ...theirProps
24
+ } = $props();
25
+ const disabled = $derived(providedDisabled.current ?? theirDisabled);
26
+ const labelledBy = useLabelledBy();
27
+ const describedBy = useDescribedBy();
28
+ const { isFocusVisible: focus, focusProps } = $derived(
29
+ useFocusRing({
30
+ get autofocus() {
31
+ return autofocus;
32
+ }
33
+ })
34
+ );
35
+ const { isHovered: hover, hoverProps } = $derived(
36
+ useHover({
37
+ get disabled() {
38
+ return disabled;
39
+ }
40
+ })
41
+ );
42
+ const { pressed: active, pressProps } = $derived(
43
+ useActivePress({
44
+ get disabled() {
45
+ return disabled;
46
+ }
47
+ })
48
+ );
49
+ const ourProps = $derived(
50
+ mergeProps(
51
+ {
52
+ id,
53
+ "aria-labelledby": labelledBy.value,
54
+ "aria-describedby": describedBy.value,
55
+ "aria-invalid": invalid ? "" : void 0,
56
+ disabled: disabled || void 0,
57
+ autofocus
58
+ },
59
+ focusProps,
60
+ hoverProps,
61
+ pressProps
92
62
  )
93
-
94
- const slot = $derived({
95
- disabled,
96
- invalid,
97
- hover,
98
- focus,
99
- active,
100
- autofocus,
101
- } satisfies SelectRenderPropArg)
63
+ );
64
+ const slot = $derived({
65
+ disabled,
66
+ invalid,
67
+ hover,
68
+ focus,
69
+ active,
70
+ autofocus
71
+ });
102
72
  </script>
103
73
 
104
74
  <ElementOrComponent {ourProps} {theirProps} {slot} defaultTag={DEFAULT_SELECT_TAG} name="Select" bind:ref />