@pzerelles/headlessui-svelte 2.1.2-next.23 → 2.1.2-next.24

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 (127) hide show
  1. package/dist/button/Button.svelte +84 -54
  2. package/dist/button/Button.svelte.d.ts +7 -4
  3. package/dist/checkbox/Checkbox.svelte +173 -120
  4. package/dist/checkbox/Checkbox.svelte.d.ts +7 -4
  5. package/dist/close-button/CloseButton.svelte +12 -6
  6. package/dist/close-button/CloseButton.svelte.d.ts +13 -10
  7. package/dist/combobox/Combobox.svelte +50 -3
  8. package/dist/data-interactive/DataInteractive.svelte +55 -29
  9. package/dist/data-interactive/DataInteractive.svelte.d.ts +7 -5
  10. package/dist/description/Description.svelte +31 -21
  11. package/dist/description/Description.svelte.d.ts +7 -4
  12. package/dist/dialog/Dialog.svelte +358 -38
  13. package/dist/dialog/Dialog.svelte.d.ts +10 -7
  14. package/dist/dialog/DialogBackdrop.svelte +30 -13
  15. package/dist/dialog/DialogBackdrop.svelte.d.ts +7 -4
  16. package/dist/dialog/DialogPanel.svelte +49 -26
  17. package/dist/dialog/DialogPanel.svelte.d.ts +7 -4
  18. package/dist/dialog/DialogTitle.svelte +38 -23
  19. package/dist/dialog/DialogTitle.svelte.d.ts +7 -4
  20. package/dist/field/Field.svelte +50 -28
  21. package/dist/field/Field.svelte.d.ts +7 -4
  22. package/dist/fieldset/Fieldset.svelte +50 -29
  23. package/dist/fieldset/Fieldset.svelte.d.ts +7 -4
  24. package/dist/focus-trap/FocusTrap.svelte +419 -283
  25. package/dist/focus-trap/FocusTrap.svelte.d.ts +7 -4
  26. package/dist/input/Input.svelte +84 -53
  27. package/dist/input/Input.svelte.d.ts +7 -4
  28. package/dist/internal/FloatingProvider.svelte +14 -9
  29. package/dist/internal/FocusSentinel.svelte +16 -8
  30. package/dist/internal/ForcePortalRoot.svelte +7 -3
  31. package/dist/internal/FormFields.svelte +47 -34
  32. package/dist/internal/FormFieldsProvider.svelte +9 -5
  33. package/dist/internal/FormResolver.svelte +20 -15
  34. package/dist/internal/Hidden.svelte +50 -29
  35. package/dist/internal/Hidden.svelte.d.ts +7 -4
  36. package/dist/internal/MainTreeProvider.svelte +89 -36
  37. package/dist/internal/Portal.svelte +18 -14
  38. package/dist/internal/floating-provider.svelte.js +1 -1
  39. package/dist/internal/floating.svelte.d.ts +5 -5
  40. package/dist/internal/floating.svelte.js +17 -17
  41. package/dist/label/Label.svelte +93 -58
  42. package/dist/label/Label.svelte.d.ts +7 -4
  43. package/dist/legend/Legend.svelte +12 -3
  44. package/dist/listbox/Listbox.svelte +525 -387
  45. package/dist/listbox/Listbox.svelte.d.ts +7 -5
  46. package/dist/listbox/ListboxButton.svelte +173 -127
  47. package/dist/listbox/ListboxButton.svelte.d.ts +7 -5
  48. package/dist/listbox/ListboxOption.svelte +170 -129
  49. package/dist/listbox/ListboxOption.svelte.d.ts +7 -5
  50. package/dist/listbox/ListboxOptions.svelte +400 -304
  51. package/dist/listbox/ListboxOptions.svelte.d.ts +7 -5
  52. package/dist/listbox/ListboxSelectedOption.svelte +38 -15
  53. package/dist/listbox/ListboxSelectedOption.svelte.d.ts +7 -4
  54. package/dist/listbox/index.d.ts +4 -4
  55. package/dist/listbox/index.js +1 -1
  56. package/dist/menu/Menu.svelte +78 -51
  57. package/dist/menu/Menu.svelte.d.ts +7 -5
  58. package/dist/menu/MenuButton.svelte +157 -117
  59. package/dist/menu/MenuButton.svelte.d.ts +7 -5
  60. package/dist/menu/MenuHeading.svelte +32 -14
  61. package/dist/menu/MenuHeading.svelte.d.ts +7 -5
  62. package/dist/menu/MenuItem.svelte +142 -107
  63. package/dist/menu/MenuItem.svelte.d.ts +8 -8
  64. package/dist/menu/MenuItems.svelte +301 -229
  65. package/dist/menu/MenuItems.svelte.d.ts +7 -5
  66. package/dist/menu/MenuSection.svelte +24 -9
  67. package/dist/menu/MenuSection.svelte.d.ts +7 -5
  68. package/dist/menu/MenuSeparator.svelte +17 -4
  69. package/dist/menu/MenuSeparator.svelte.d.ts +7 -6
  70. package/dist/menu/index.d.ts +7 -7
  71. package/dist/popover/Popover.svelte +216 -150
  72. package/dist/popover/Popover.svelte.d.ts +7 -4
  73. package/dist/popover/PopoverBackdrop.svelte +67 -41
  74. package/dist/popover/PopoverBackdrop.svelte.d.ts +7 -4
  75. package/dist/popover/PopoverButton.svelte +292 -212
  76. package/dist/popover/PopoverButton.svelte.d.ts +7 -4
  77. package/dist/popover/PopoverGroup.svelte +62 -35
  78. package/dist/popover/PopoverGroup.svelte.d.ts +7 -4
  79. package/dist/popover/PopoverPanel.svelte +311 -229
  80. package/dist/popover/PopoverPanel.svelte.d.ts +7 -4
  81. package/dist/portal/InternalPortal.svelte +141 -85
  82. package/dist/portal/InternalPortal.svelte.d.ts +7 -4
  83. package/dist/portal/Portal.svelte +5 -2
  84. package/dist/portal/PortalGroup.svelte +30 -9
  85. package/dist/portal/PortalGroup.svelte.d.ts +7 -4
  86. package/dist/select/Select.svelte +98 -68
  87. package/dist/select/Select.svelte.d.ts +7 -4
  88. package/dist/switch/Switch.svelte +179 -132
  89. package/dist/switch/Switch.svelte.d.ts +7 -4
  90. package/dist/switch/SwitchGroup.svelte +44 -31
  91. package/dist/switch/SwitchGroup.svelte.d.ts +7 -4
  92. package/dist/tabs/Tab.svelte +194 -143
  93. package/dist/tabs/Tab.svelte.d.ts +7 -4
  94. package/dist/tabs/TabGroup.svelte +81 -214
  95. package/dist/tabs/TabGroup.svelte.d.ts +7 -24
  96. package/dist/tabs/TabList.svelte +31 -11
  97. package/dist/tabs/TabList.svelte.d.ts +7 -4
  98. package/dist/tabs/TabPanel.svelte +67 -43
  99. package/dist/tabs/TabPanel.svelte.d.ts +7 -4
  100. package/dist/tabs/TabPanels.svelte +18 -7
  101. package/dist/tabs/TabPanels.svelte.d.ts +7 -4
  102. package/dist/tabs/context.svelte.d.ts +31 -0
  103. package/dist/tabs/context.svelte.js +134 -0
  104. package/dist/textarea/Textarea.svelte +84 -53
  105. package/dist/textarea/Textarea.svelte.d.ts +7 -4
  106. package/dist/transition/InternalTransitionChild.svelte +259 -170
  107. package/dist/transition/InternalTransitionChild.svelte.d.ts +7 -4
  108. package/dist/transition/Transition.svelte +96 -66
  109. package/dist/transition/Transition.svelte.d.ts +7 -4
  110. package/dist/transition/TransitionChild.svelte +31 -11
  111. package/dist/transition/TransitionChild.svelte.d.ts +7 -4
  112. package/dist/utils/ElementOrComponent.svelte +43 -23
  113. package/dist/utils/ElementOrComponent.svelte.d.ts +10 -4
  114. package/dist/utils/Generic.svelte +36 -22
  115. package/dist/utils/Generic.svelte.d.ts +7 -4
  116. package/dist/utils/StableCollection.svelte +54 -36
  117. package/dist/utils/floating-ui/svelte/components/FloatingNode.svelte +27 -12
  118. package/dist/utils/floating-ui/svelte/components/FloatingTree.svelte +88 -44
  119. package/dist/utils/floating-ui/svelte/hooks/useFloating.svelte.js +7 -7
  120. package/dist/utils/floating-ui/svelte/hooks/useFloatingRootContext.svelte.js +1 -1
  121. package/dist/utils/floating-ui/svelte/types.d.ts +4 -4
  122. package/dist/utils/floating-ui/svelte-dom/types.d.ts +2 -2
  123. package/dist/utils/floating-ui/svelte-dom/useFloating.svelte.js +6 -6
  124. package/dist/utils/types.d.ts +11 -4
  125. package/package.json +1 -1
  126. package/dist/dialog/InternalDialog.svelte +0 -233
  127. package/dist/dialog/InternalDialog.svelte.d.ts +0 -42
@@ -1,156 +1,207 @@
1
- <script lang="ts" module>const DEFAULT_TAB_TAG = "button";
2
- </script>
1
+ <script lang="ts" module>
2
+ import type { ElementType, Props } from "../utils/types.js"
3
3
 
4
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_TAB_TAG">import { useId } from "../hooks/use-id.js";
5
- import { useActions, useData } from "./TabGroup.svelte";
6
- import { useStableCollectionIndex } from "../utils/StableCollection.svelte";
7
- import { Focus, focusIn, FocusResult } from "../utils/focus-management.js";
8
- import { getOwnerDocument } from "../utils/owner.js";
9
- import { match } from "../utils/match.js";
10
- import { microTask } from "../utils/microTask.js";
11
- import { useActivePress } from "../hooks/use-active-press.svelte.js";
12
- import { useFocusRing } from "../hooks/use-focus-ring.svelte.js";
13
- import { useResolveButtonType } from "../hooks/use-resolve-button-type.svelte.js";
14
- import { onMount } from "svelte";
15
- import { useHover } from "../hooks/use-hover.svelte.js";
16
- import { mergeProps } from "../utils/render.js";
17
- import ElementOrComponent from "../utils/ElementOrComponent.svelte";
18
- const internalId = useId();
19
- let {
20
- ref = $bindable(),
21
- id = `headlessui-tabs-tab-${internalId}`,
22
- disabled = false,
23
- autofocus = false,
24
- ...theirProps
25
- } = $props();
26
- const data = useData("Tab");
27
- const { orientation, activation, selectedIndex, tabs, panels } = $derived(data);
28
- const actions = useActions("Tab");
29
- const tabRef = $derived({ current: ref });
30
- onMount(() => actions.registerTab(tabRef));
31
- const mySSRIndex = useStableCollectionIndex("tabs");
32
- const myIndex = $derived.by(() => {
33
- const index = tabs.findIndex((tab) => tab === tabRef);
34
- return index === -1 ? mySSRIndex : index;
35
- });
36
- const selected = $derived(myIndex === selectedIndex);
37
- const activateUsing = $derived((cb) => {
38
- let result = cb();
39
- if (result === FocusResult.Success && activation === "auto") {
40
- let newTab = getOwnerDocument(ref)?.activeElement;
41
- let idx = data.tabs.findIndex((tab) => tab.current === newTab);
42
- if (idx !== -1) actions.change(idx);
43
- }
44
- return result;
45
- });
46
- const handleKeyDown = (event) => {
47
- let list = tabs.map((tab) => tab.current).filter(Boolean);
48
- if (event.key === " " || event.key === "Enter") {
49
- event.preventDefault();
50
- event.stopPropagation();
51
- actions.change(myIndex);
52
- return;
53
- }
54
- switch (event.key) {
55
- case "Home":
56
- case "PageUp":
57
- event.preventDefault();
58
- event.stopPropagation();
59
- return activateUsing(() => focusIn(list, Focus.First));
60
- case "End":
61
- case "PageDown":
62
- event.preventDefault();
63
- event.stopPropagation();
64
- return activateUsing(() => focusIn(list, Focus.Last));
4
+ const DEFAULT_TAB_TAG = "button" as const
5
+ type TabRenderPropArg = {
6
+ hover: boolean
7
+ focus: boolean
8
+ active: boolean
9
+ autofocus: boolean
10
+ selected: boolean
11
+ disabled: boolean
65
12
  }
66
- let result = activateUsing(() => {
67
- return match(orientation, {
68
- vertical() {
69
- if (event.key === "ArrowUp") return focusIn(list, Focus.Previous | Focus.WrapAround);
70
- if (event.key === "ArrowDown") return focusIn(list, Focus.Next | Focus.WrapAround);
71
- return FocusResult.Error;
72
- },
73
- horizontal() {
74
- if (event.key === "ArrowLeft") return focusIn(list, Focus.Previous | Focus.WrapAround);
75
- if (event.key === "ArrowRight") return focusIn(list, Focus.Next | Focus.WrapAround);
76
- return FocusResult.Error;
77
- }
78
- });
79
- });
80
- if (result === FocusResult.Success) {
81
- return event.preventDefault();
82
- }
83
- };
84
- let ready = $state(false);
85
- const handleSelection = () => {
86
- if (ready) return;
87
- ready = true;
88
- ref?.focus({ preventScroll: true });
89
- actions.change(myIndex);
90
- microTask(() => {
91
- ready = false;
92
- });
93
- };
94
- const handleMouseDown = (event) => {
95
- event.preventDefault();
96
- };
97
- const { isHovered: hover, hoverProps } = $derived(
98
- useHover({
99
- get disabled() {
100
- return disabled;
13
+ type TabPropsWeControl = "aria-controls" | "aria-selected" | "role" | "tabIndex"
14
+
15
+ export type TabProps<TTag extends ElementType = typeof DEFAULT_TAB_TAG> = Props<
16
+ TTag,
17
+ TabRenderPropArg,
18
+ TabPropsWeControl,
19
+ {
20
+ id?: string
21
+ autofocus?: boolean
22
+ disabled?: boolean
101
23
  }
24
+ >
25
+ </script>
26
+
27
+ <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_TAB_TAG">
28
+ import { useId } from "../hooks/use-id.js"
29
+ import { useStableCollectionIndex } from "../utils/StableCollection.svelte"
30
+ import { Focus, focusIn, FocusResult } from "../utils/focus-management.js"
31
+ import { getOwnerDocument } from "../utils/owner.js"
32
+ import { match } from "../utils/match.js"
33
+ import { microTask } from "../utils/microTask.js"
34
+ import { useActivePress } from "../hooks/use-active-press.svelte.js"
35
+ import { useFocusRing } from "../hooks/use-focus-ring.svelte.js"
36
+ import { useResolveButtonType } from "../hooks/use-resolve-button-type.svelte.js"
37
+ import type { MutableRefObject } from "../utils/ref.svelte.js"
38
+ import { onMount } from "svelte"
39
+ import { useHover } from "../hooks/use-hover.svelte.js"
40
+ import { mergeProps } from "../utils/render.js"
41
+ import ElementOrComponent from "../utils/ElementOrComponent.svelte"
42
+ import { useTabs } from "./context.svelte.js"
43
+
44
+ const internalId = useId()
45
+ let {
46
+ ref = $bindable(),
47
+ id = `headlessui-tabs-tab-${internalId}`,
48
+ disabled = false,
49
+ autofocus = false,
50
+ ...theirProps
51
+ }: { as?: TTag } & TabProps<TTag> = $props()
52
+
53
+ const context = useTabs("Tab")
54
+ const { orientation, activation, selectedIndex, tabs, panels, registerTab, change } = $derived(context)
55
+
56
+ const tabRef = $derived<MutableRefObject<HTMLElement | undefined>>({ current: ref })
57
+
58
+ onMount(() => registerTab(tabRef))
59
+
60
+ const mySSRIndex = useStableCollectionIndex("tabs")
61
+
62
+ const myIndex = $derived.by(() => {
63
+ const index = tabs.findIndex((tab) => tab === tabRef)
64
+ return index === -1 ? mySSRIndex : index
102
65
  })
103
- );
104
- const { pressed: active, pressProps } = $derived(
105
- useActivePress({
106
- get disabled() {
107
- return disabled;
66
+ const selected = $derived(myIndex === selectedIndex)
67
+
68
+ const activateUsing = $derived((cb: () => FocusResult) => {
69
+ let result = cb()
70
+ if (result === FocusResult.Success && activation === "auto") {
71
+ let newTab = getOwnerDocument(ref)?.activeElement
72
+ let idx = context.tabs.findIndex((tab) => tab.current === newTab)
73
+ if (idx !== -1) change(idx)
108
74
  }
75
+ return result
109
76
  })
110
- );
111
- const { isFocusVisible: focus, focusProps } = $derived(
112
- useFocusRing({
113
- get autofocus() {
114
- return autofocus;
77
+
78
+ const handleKeyDown = (event: KeyboardEvent) => {
79
+ let list = tabs.map((tab) => tab.current).filter(Boolean) as HTMLElement[]
80
+
81
+ if (event.key === " " || event.key === "Enter") {
82
+ event.preventDefault()
83
+ event.stopPropagation()
84
+
85
+ change(myIndex)
86
+ return
87
+ }
88
+
89
+ switch (event.key) {
90
+ case "Home":
91
+ case "PageUp":
92
+ event.preventDefault()
93
+ event.stopPropagation()
94
+
95
+ return activateUsing(() => focusIn(list, Focus.First))
96
+
97
+ case "End":
98
+ case "PageDown":
99
+ event.preventDefault()
100
+ event.stopPropagation()
101
+
102
+ return activateUsing(() => focusIn(list, Focus.Last))
103
+ }
104
+
105
+ let result = activateUsing(() => {
106
+ return match(orientation, {
107
+ vertical() {
108
+ if (event.key === "ArrowUp") return focusIn(list, Focus.Previous | Focus.WrapAround)
109
+ if (event.key === "ArrowDown") return focusIn(list, Focus.Next | Focus.WrapAround)
110
+ return FocusResult.Error
111
+ },
112
+ horizontal() {
113
+ if (event.key === "ArrowLeft") return focusIn(list, Focus.Previous | Focus.WrapAround)
114
+ if (event.key === "ArrowRight") return focusIn(list, Focus.Next | Focus.WrapAround)
115
+ return FocusResult.Error
116
+ },
117
+ })
118
+ })
119
+
120
+ if (result === FocusResult.Success) {
121
+ return event.preventDefault()
115
122
  }
116
- })
117
- );
118
- const slot = $derived({
119
- selected,
120
- hover,
121
- active,
122
- focus,
123
- autofocus,
124
- disabled
125
- });
126
- const resolvedType = useResolveButtonType({
127
- get props() {
128
- return { type: theirProps.type, as: theirProps.as };
129
- },
130
- get ref() {
131
- return tabRef;
132
123
  }
133
- });
134
- const ourProps = $derived(
135
- mergeProps(
136
- {
137
- onkeydown: handleKeyDown,
138
- onmousedown: handleMouseDown,
139
- onclick: handleSelection,
140
- id,
141
- role: "tab",
142
- type: resolvedType.type,
143
- "aria-controls": panels[myIndex]?.current?.id,
144
- "aria-selected": selected,
145
- tabIndex: selected ? 0 : -1,
146
- disabled: disabled || void 0,
147
- autofocus
124
+
125
+ let ready = $state(false)
126
+ const handleSelection = () => {
127
+ if (ready) return
128
+ ready = true
129
+
130
+ ref?.focus({ preventScroll: true })
131
+ change(myIndex)
132
+
133
+ microTask(() => {
134
+ ready = false
135
+ })
136
+ }
137
+
138
+ // This is important because we want to only focus the tab when it gets focus
139
+ // OR it finished the click event (mouseup). However, if you perform a `click`,
140
+ // then you will first get the `focus` and then get the `click` event.
141
+ const handleMouseDown = (event: MouseEvent) => {
142
+ event.preventDefault()
143
+ }
144
+
145
+ const { isHovered: hover, hoverProps } = $derived(
146
+ useHover({
147
+ get disabled() {
148
+ return disabled
149
+ },
150
+ })
151
+ )
152
+ const { pressed: active, pressProps } = $derived(
153
+ useActivePress({
154
+ get disabled() {
155
+ return disabled
156
+ },
157
+ })
158
+ )
159
+ const { isFocusVisible: focus, focusProps } = $derived(
160
+ useFocusRing({
161
+ get autofocus() {
162
+ return autofocus
163
+ },
164
+ })
165
+ )
166
+
167
+ const slot = $derived({
168
+ selected,
169
+ hover,
170
+ active,
171
+ focus,
172
+ autofocus,
173
+ disabled,
174
+ } satisfies TabRenderPropArg)
175
+
176
+ const resolvedType = useResolveButtonType({
177
+ get props() {
178
+ return { type: theirProps.type, as: theirProps.as }
179
+ },
180
+ get ref() {
181
+ return tabRef
148
182
  },
149
- focusProps,
150
- hoverProps,
151
- pressProps
183
+ })
184
+
185
+ const ourProps = $derived(
186
+ mergeProps(
187
+ {
188
+ onkeydown: handleKeyDown,
189
+ onmousedown: handleMouseDown,
190
+ onclick: handleSelection,
191
+ id,
192
+ role: "tab",
193
+ type: resolvedType.type,
194
+ "aria-controls": panels[myIndex]?.current?.id,
195
+ "aria-selected": selected,
196
+ tabIndex: selected ? 0 : -1,
197
+ disabled: disabled || undefined,
198
+ autofocus,
199
+ },
200
+ focusProps,
201
+ hoverProps,
202
+ pressProps
203
+ )
152
204
  )
153
- );
154
205
  </script>
155
206
 
156
207
  <ElementOrComponent {ourProps} {theirProps} {slot} defaultTag={DEFAULT_TAB_TAG} name="Tab" bind:ref />
@@ -17,11 +17,14 @@ export type TabProps<TTag extends ElementType = typeof DEFAULT_TAB_TAG> = Props<
17
17
  declare class __sveltets_Render<TTag extends ElementType = typeof DEFAULT_TAB_TAG> {
18
18
  props(): {
19
19
  as?: TTag | undefined;
20
- } & (Exclude<keyof import("../utils/types.js").PropsOf<TTag>, ("as" | "children" | "refName" | "class") | "disabled" | "autofocus" | "id" | TabPropsWeControl> extends infer T extends keyof import("../utils/types.js").PropsOf<TTag> ? { [P in T]: import("../utils/types.js").PropsOf<TTag>[P]; } : never) & {
21
- children?: import("svelte").Snippet<[TabRenderPropArg, Record<string, any>]> | undefined;
20
+ } & (Exclude<keyof import("../utils/types.js").PropsOf<TTag>, ("as" | "children" | "class") | "disabled" | "autofocus" | "id" | TabPropsWeControl> extends infer T extends keyof import("../utils/types.js").PropsOf<TTag> ? { [P in T]: import("../utils/types.js").PropsOf<TTag>[P]; } : never) & {
21
+ children?: import("svelte").Snippet<[{
22
+ slot: TabRenderPropArg;
23
+ props: Record<string, any>;
24
+ }]> | undefined;
22
25
  ref?: HTMLElement;
23
- } & (true extends (import("../utils/types.js").PropsOf<TTag> extends infer T_1 ? T_1 extends import("../utils/types.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) ? {
24
- class?: import("../utils/types.js").PropsOf<TTag>["class"] | ((bag: TabRenderPropArg) => string) | undefined;
26
+ } & (true extends (import("svelte/elements.js").SvelteHTMLElements[TTag] extends infer T_1 ? T_1 extends import("svelte/elements.js").SvelteHTMLElements[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) ? {
27
+ class?: string | ((bag: TabRenderPropArg) => string) | null | undefined;
25
28
  } : {}) & {
26
29
  id?: string;
27
30
  autofocus?: boolean;