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

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 +46 -22
  57. package/dist/internal/floating.svelte.js +90 -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 +13 -191
  80. package/dist/menu/Menu.svelte.d.ts +9 -13
  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
@@ -11,6 +11,7 @@ import { match } from "../utils/match.js";
11
11
  import { useDisposables } from "../utils/disposables.js";
12
12
  import Hidden, { HiddenFeatures } from "../internal/Hidden.svelte";
13
13
  import ElementOrComponent from "../utils/ElementOrComponent.svelte";
14
+ import { FocusTrapFeatures } from "./FocusTrapFeatures.js";
14
15
  function resolveContainers(containers) {
15
16
  if (!containers) return /* @__PURE__ */ new Set();
16
17
  if (typeof containers === "function") return new Set(containers());
@@ -23,15 +24,7 @@ function resolveContainers(containers) {
23
24
  return all;
24
25
  }
25
26
  let DEFAULT_FOCUS_TRAP_TAG = "div";
26
- export var FocusTrapFeatures = /* @__PURE__ */ ((FocusTrapFeatures2) => {
27
- FocusTrapFeatures2[FocusTrapFeatures2["None"] = 0] = "None";
28
- FocusTrapFeatures2[FocusTrapFeatures2["InitialFocus"] = 1] = "InitialFocus";
29
- FocusTrapFeatures2[FocusTrapFeatures2["TabLock"] = 2] = "TabLock";
30
- FocusTrapFeatures2[FocusTrapFeatures2["FocusLock"] = 4] = "FocusLock";
31
- FocusTrapFeatures2[FocusTrapFeatures2["RestoreFocus"] = 8] = "RestoreFocus";
32
- FocusTrapFeatures2[FocusTrapFeatures2["AutoFocus"] = 16] = "AutoFocus";
33
- return FocusTrapFeatures2;
34
- })(FocusTrapFeatures || {});
27
+ export * from "./FocusTrapFeatures.js";
35
28
  function useRestoreElement(options) {
36
29
  const { enabled } = $derived(options ?? { enabled: true });
37
30
  let localHistory = $state(history.slice());
@@ -58,7 +51,7 @@ function useRestoreElement(options) {
58
51
  }
59
52
  function useRestoreFocus(options) {
60
53
  const { features, ownerDocument } = $derived(options);
61
- const enabled = $derived(Boolean(features & 8 /* RestoreFocus */));
54
+ const enabled = $derived(Boolean(features & FocusTrapFeatures.RestoreFocus));
62
55
  const restoreElement = useRestoreElement({
63
56
  get enabled() {
64
57
  return enabled;
@@ -85,14 +78,14 @@ function useInitialFocus(options) {
85
78
  let previousActiveElement = $state(null);
86
79
  let enabled = useIsTopLayer({
87
80
  get enabled() {
88
- return Boolean(features & 1 /* InitialFocus */);
81
+ return Boolean(features & FocusTrapFeatures.InitialFocus);
89
82
  },
90
83
  scope: "focus-trap#initial-focus"
91
84
  });
92
85
  let mounted = useIsMounted();
93
86
  useWatch({
94
87
  action: () => {
95
- if (features === 0 /* None */) {
88
+ if (features === FocusTrapFeatures.None) {
96
89
  return;
97
90
  }
98
91
  if (!enabled) {
@@ -120,7 +113,7 @@ function useInitialFocus(options) {
120
113
  if (initialFocus) {
121
114
  focusElement(initialFocus);
122
115
  } else {
123
- if (features & 16 /* AutoFocus */) {
116
+ if (features & FocusTrapFeatures.AutoFocus) {
124
117
  if (focusIn(containerElement, Focus.First | Focus.AutoFocus) !== FocusResult.Error) {
125
118
  return;
126
119
  }
@@ -154,7 +147,7 @@ function useInitialFocus(options) {
154
147
  function useFocusLock(options) {
155
148
  let { features, ownerDocument, container, containers, previousActiveElement } = $derived(options);
156
149
  const mounted = useIsMounted();
157
- const enabled = $derived(Boolean(features & 4 /* FocusLock */));
150
+ const enabled = $derived(Boolean(features & FocusTrapFeatures.FocusLock));
158
151
  useEventListener({
159
152
  get element() {
160
153
  return ownerDocument?.defaultView;
@@ -1,20 +1,8 @@
1
1
  import type { ElementType, Props } from "../utils/types.js";
2
+ import { FocusTrapFeatures } from "./FocusTrapFeatures.js";
2
3
  type Containers = (() => Iterable<HTMLElement>) | Iterable<HTMLElement>;
3
4
  declare let DEFAULT_FOCUS_TRAP_TAG: "div";
4
- export declare enum FocusTrapFeatures {
5
- /** No features enabled for the focus trap. */
6
- None = 0,
7
- /** Ensure that we move focus initially into the container. */
8
- InitialFocus = 1,
9
- /** Ensure that pressing `Tab` and `Shift+Tab` is trapped within the container. */
10
- TabLock = 2,
11
- /** Ensure that programmatically moving focus outside of the container is disallowed. */
12
- FocusLock = 4,
13
- /** Ensure that we restore the focus when unmounting the focus trap. */
14
- RestoreFocus = 8,
15
- /** Initial focus should look for the `data-autofocus` */
16
- AutoFocus = 16
17
- }
5
+ export * from "./FocusTrapFeatures.js";
18
6
  type FocusTrapRenderPropArg = {};
19
7
  type FocusTrapPropsWeControl = never;
20
8
  export type FocusTrapProps<TTag extends ElementType = typeof DEFAULT_FOCUS_TRAP_TAG> = Props<TTag, FocusTrapRenderPropArg, FocusTrapPropsWeControl, {
@@ -26,20 +14,20 @@ export type FocusTrapProps<TTag extends ElementType = typeof DEFAULT_FOCUS_TRAP_
26
14
  declare class __sveltets_Render<TTag extends ElementType = typeof DEFAULT_FOCUS_TRAP_TAG> {
27
15
  props(): {
28
16
  as?: TTag | undefined;
29
- } & (Exclude<keyof import("../utils/types.js").PropsOf<TTag>, ("as" | "children" | "refName" | "class") | "features" | "containers" | "initialFocus" | "initialFocusFallback"> extends infer T extends keyof import("../utils/types.js").PropsOf<TTag> ? { [P in T]: import("../utils/types.js").PropsOf<TTag>[P]; } : never) & {
30
- children?: import("../utils/types.js").Children<FocusTrapRenderPropArg> | undefined;
17
+ } & (Exclude<keyof import("../utils/types.js").PropsOf<TTag>, ("slot" | "as" | "children" | "class" | "ref") | "features" | "containers" | "initialFocus" | "initialFocusFallback"> extends infer T extends keyof import("../utils/types.js").PropsOf<TTag> ? { [P in T]: import("../utils/types.js").PropsOf<TTag>[P]; } : never) & {
18
+ children?: import("svelte").Snippet<[{
19
+ slot: FocusTrapRenderPropArg;
20
+ props: Record<string, any>;
21
+ }]> | undefined;
22
+ class?: string | ((bag: FocusTrapRenderPropArg) => string) | null | undefined;
31
23
  ref?: HTMLElement;
32
- } & (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) ? {
33
- class?: import("../utils/types.js").PropsOf<TTag>["class"] | ((bag: FocusTrapRenderPropArg) => string) | undefined;
34
- } : {}) & {
24
+ } & {
35
25
  initialFocus?: HTMLElement;
36
26
  initialFocusFallback?: HTMLElement;
37
27
  features?: FocusTrapFeatures;
38
28
  containers?: Containers;
39
29
  };
40
- events(): {} & {
41
- [evt: string]: CustomEvent<any>;
42
- };
30
+ events(): {};
43
31
  slots(): {};
44
32
  bindings(): "ref";
45
33
  exports(): {};
@@ -48,9 +36,7 @@ interface $$IsomorphicComponent {
48
36
  new <TTag extends ElementType = typeof DEFAULT_FOCUS_TRAP_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']>> & {
49
37
  $$bindings?: ReturnType<__sveltets_Render<TTag>['bindings']>;
50
38
  } & ReturnType<__sveltets_Render<TTag>['exports']>;
51
- <TTag extends ElementType = typeof DEFAULT_FOCUS_TRAP_TAG>(internal: unknown, props: ReturnType<__sveltets_Render<TTag>['props']> & {
52
- $$events?: ReturnType<__sveltets_Render<TTag>['events']>;
53
- }): ReturnType<__sveltets_Render<TTag>['exports']>;
39
+ <TTag extends ElementType = typeof DEFAULT_FOCUS_TRAP_TAG>(internal: unknown, props: ReturnType<__sveltets_Render<TTag>['props']> & {}): ReturnType<__sveltets_Render<TTag>['exports']>;
54
40
  z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
55
41
  }
56
42
  declare const FocusTrap: $$IsomorphicComponent;
@@ -0,0 +1,14 @@
1
+ export declare enum FocusTrapFeatures {
2
+ /** No features enabled for the focus trap. */
3
+ None = 0,
4
+ /** Ensure that we move focus initially into the container. */
5
+ InitialFocus = 1,
6
+ /** Ensure that pressing `Tab` and `Shift+Tab` is trapped within the container. */
7
+ TabLock = 2,
8
+ /** Ensure that programmatically moving focus outside of the container is disallowed. */
9
+ FocusLock = 4,
10
+ /** Ensure that we restore the focus when unmounting the focus trap. */
11
+ RestoreFocus = 8,
12
+ /** Initial focus should look for the `data-autofocus` */
13
+ AutoFocus = 16
14
+ }
@@ -0,0 +1,15 @@
1
+ export var FocusTrapFeatures;
2
+ (function (FocusTrapFeatures) {
3
+ /** No features enabled for the focus trap. */
4
+ FocusTrapFeatures[FocusTrapFeatures["None"] = 0] = "None";
5
+ /** Ensure that we move focus initially into the container. */
6
+ FocusTrapFeatures[FocusTrapFeatures["InitialFocus"] = 1] = "InitialFocus";
7
+ /** Ensure that pressing `Tab` and `Shift+Tab` is trapped within the container. */
8
+ FocusTrapFeatures[FocusTrapFeatures["TabLock"] = 2] = "TabLock";
9
+ /** Ensure that programmatically moving focus outside of the container is disallowed. */
10
+ FocusTrapFeatures[FocusTrapFeatures["FocusLock"] = 4] = "FocusLock";
11
+ /** Ensure that we restore the focus when unmounting the focus trap. */
12
+ FocusTrapFeatures[FocusTrapFeatures["RestoreFocus"] = 8] = "RestoreFocus";
13
+ /** Initial focus should look for the `data-autofocus` */
14
+ FocusTrapFeatures[FocusTrapFeatures["AutoFocus"] = 16] = "AutoFocus";
15
+ })(FocusTrapFeatures || (FocusTrapFeatures = {}));
@@ -27,7 +27,8 @@ export function useControllable(input, onchange, defaultValue) {
27
27
  }
28
28
  else {
29
29
  internalValue = value;
30
- input.controlledValue = value;
30
+ if (isControlled)
31
+ input.controlledValue = value;
31
32
  }
32
33
  },
33
34
  };
@@ -1,23 +1,18 @@
1
1
  export function useDidElementMove(options) {
2
2
  const { enabled, element } = $derived(options);
3
- let elementPosition = $state({ left: 0, top: 0 });
3
+ let elementPosition = $state();
4
4
  $effect(() => {
5
5
  if (!element)
6
6
  return;
7
- let DOMRect = element.getBoundingClientRect();
7
+ const DOMRect = element.getBoundingClientRect();
8
8
  if (DOMRect)
9
9
  elementPosition = DOMRect;
10
10
  });
11
11
  const value = $derived.by(() => {
12
- if (element == null)
12
+ if (element == null || !enabled || element === document.activeElement || elementPosition === undefined)
13
13
  return false;
14
- if (!enabled)
15
- return false;
16
- if (element === document.activeElement)
17
- return false;
18
- let buttonRect = element.getBoundingClientRect();
19
- let didElementMove = buttonRect.top !== elementPosition.top || buttonRect.left !== elementPosition.left;
20
- return didElementMove;
14
+ const buttonRect = element.getBoundingClientRect();
15
+ return buttonRect.top !== elementPosition.top || buttonRect.left !== elementPosition.left;
21
16
  });
22
17
  return {
23
18
  get value() {
@@ -1,3 +1,8 @@
1
1
  export declare const useDisabled: () => {
2
- readonly value: boolean;
2
+ readonly current: boolean;
3
+ };
4
+ export declare const provideDisabled: (disabled: () => boolean, options?: {
5
+ ignoreParent?: boolean;
6
+ }) => {
7
+ readonly current: boolean;
3
8
  };
@@ -1,9 +1,14 @@
1
- import { getContext } from "svelte";
1
+ import { getContext, setContext } from "svelte";
2
2
  export const useDisabled = () => {
3
- const context = getContext("DisabledContext");
4
- return {
5
- get value() {
6
- return context?.value ?? false;
3
+ return getContext("DisabledContext") ?? { current: false };
4
+ };
5
+ export const provideDisabled = (disabled, options) => {
6
+ const parentDisabled = options?.ignoreParent ? { current: false } : useDisabled();
7
+ const context = {
8
+ get current() {
9
+ return disabled() || parentDisabled.current;
7
10
  },
8
11
  };
12
+ setContext("DisabledContext", context);
13
+ return context;
9
14
  };
@@ -1,6 +1,6 @@
1
1
  export declare function useEventListener<TType extends keyof WindowEventMap>(params: {
2
2
  element: HTMLElement | Document | Window | EventTarget | null | undefined;
3
3
  type: TType;
4
- listener: (event: WindowEventMap[TType]) => any;
4
+ listener: (event: WindowEventMap[TType]) => unknown;
5
5
  options?: boolean | AddEventListenerOptions;
6
6
  }): void;
@@ -1,5 +1,7 @@
1
1
  export function useEventListener(params) {
2
- let { element = window, type, listener, options } = $derived(params);
2
+ if (typeof window === "undefined")
3
+ return;
4
+ const { element = window, type, listener, options } = $derived(params);
3
5
  $effect(() => {
4
6
  if (!element)
5
7
  return;
@@ -1,8 +1,8 @@
1
1
  export { default as MainTreeProvider, useMainTreeNode } from "../internal/MainTreeProvider.svelte";
2
2
  export declare function useRootContainers(options?: {
3
- defaultContainers?: (HTMLElement | null)[];
3
+ defaultContainers?: (HTMLElement | undefined | null)[];
4
4
  portals?: HTMLElement[];
5
- mainTreeNode?: HTMLElement | null;
5
+ mainTreeNode?: HTMLElement | undefined | null;
6
6
  }): {
7
7
  readonly resolvedContainers: HTMLElement[];
8
8
  contains: (element: HTMLElement) => boolean;
@@ -6,21 +6,21 @@ export function useRootContainers(options = {}) {
6
6
  mainTreeNode, } = $derived(options);
7
7
  const ownerDocument = $derived(getOwnerDocument(mainTreeNode));
8
8
  const resolvedContainers = $derived.by(() => {
9
- let containers = [];
9
+ const containers = [];
10
10
  // Resolve default containers
11
- for (let container of defaultContainers) {
12
- if (container === null)
11
+ for (const container of defaultContainers) {
12
+ if (!container)
13
13
  continue;
14
14
  containers.push(container);
15
15
  }
16
16
  // Resolve portal containers
17
17
  if (portals) {
18
- for (let portal of portals) {
18
+ for (const portal of portals) {
19
19
  containers.push(portal);
20
20
  }
21
21
  }
22
22
  // Resolve third party (root) containers
23
- for (let container of ownerDocument?.querySelectorAll("html > *, body > *") ?? []) {
23
+ for (const container of ownerDocument?.querySelectorAll("html > *, body > *") ?? []) {
24
24
  if (container === document.body)
25
25
  continue; // Skip `<body>`
26
26
  if (container === document.head)
@@ -6,7 +6,7 @@ export var Direction;
6
6
  })(Direction || (Direction = {}));
7
7
  export function useTabDirection() {
8
8
  let direction = $state(Direction.Forwards);
9
- let enabled = true;
9
+ const enabled = true;
10
10
  useWindowEvent({
11
11
  enabled,
12
12
  type: "keydown",
package/dist/index.d.ts CHANGED
@@ -11,10 +11,12 @@ export * from "./label/index.js";
11
11
  export * from "./legend/index.js";
12
12
  export * from "./listbox/index.js";
13
13
  export * from "./menu/index.js";
14
+ export * from "./popover/index.js";
15
+ export * from "./select/index.js";
14
16
  export * from "./switch/index.js";
15
17
  export * from "./tabs/index.js";
16
18
  export * from "./textarea/index.js";
17
19
  export * from "./transition/index.js";
20
+ export * from "./utils/index.js";
18
21
  export * from "./hooks/use-id.js";
19
- export * from "./utils/types.js";
20
- export { mergeProps } from "./utils/render.js";
22
+ export * from "./hooks/use-disabled.js";
package/dist/index.js CHANGED
@@ -11,10 +11,12 @@ export * from "./label/index.js";
11
11
  export * from "./legend/index.js";
12
12
  export * from "./listbox/index.js";
13
13
  export * from "./menu/index.js";
14
+ export * from "./popover/index.js";
15
+ export * from "./select/index.js";
14
16
  export * from "./switch/index.js";
15
17
  export * from "./tabs/index.js";
16
18
  export * from "./textarea/index.js";
17
19
  export * from "./transition/index.js";
20
+ export * from "./utils/index.js";
18
21
  export * from "./hooks/use-id.js";
19
- export * from "./utils/types.js";
20
- export { mergeProps } from "./utils/render.js";
22
+ export * from "./hooks/use-disabled.js";
@@ -3,7 +3,7 @@
3
3
 
4
4
  <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_INPUT_TAG, TValue = string">import { htmlid } from "../utils/id.js";
5
5
  import { useDisabled } from "../hooks/use-disabled.js";
6
- import { useProvidedId } from "../internal/id.js";
6
+ import { useProvidedId } from "../utils/id.js";
7
7
  import { useLabelledBy } from "../label/context.svelte.js";
8
8
  import { useDescribedBy } from "../description/context.svelte.js";
9
9
  import { useHover } from "../hooks/use-hover.svelte.js";
@@ -16,13 +16,13 @@ const providedDisabled = useDisabled();
16
16
  let {
17
17
  ref = $bindable(),
18
18
  value = $bindable(),
19
- id = providedId?.value || `headlessui-input-${internalId}`,
19
+ id = providedId || `headlessui-input-${internalId}`,
20
20
  disabled: theirDisabled = false,
21
21
  autofocus = false,
22
22
  invalid = false,
23
23
  ...theirProps
24
24
  } = $props();
25
- const disabled = $derived(providedDisabled?.value ?? theirDisabled);
25
+ const disabled = $derived(providedDisabled.current || theirDisabled);
26
26
  const labelledBy = useLabelledBy();
27
27
  const describedBy = useDescribedBy();
28
28
  const { isHovered: hover, hoverProps } = $derived(
@@ -1,4 +1,4 @@
1
- import type { ElementType, Props } from "../utils/types.js";
1
+ import type { ElementType, Props, PropsOf } from "../utils/types.js";
2
2
  declare const DEFAULT_INPUT_TAG: "input";
3
3
  type InputRenderPropArg = {
4
4
  disabled: boolean;
@@ -9,7 +9,6 @@ type InputRenderPropArg = {
9
9
  };
10
10
  type InputPropsWeControl = "aria-labelledby" | "aria-describedby";
11
11
  export type InputProps<TTag extends ElementType = typeof DEFAULT_INPUT_TAG, TValue = string> = Props<TTag, InputRenderPropArg, InputPropsWeControl, {
12
- id?: string;
13
12
  value?: TValue;
14
13
  disabled?: boolean;
15
14
  invalid?: boolean;
@@ -19,21 +18,20 @@ declare class __sveltets_Render<TTag extends ElementType = typeof DEFAULT_INPUT_
19
18
  props(): {
20
19
  as?: TTag | undefined;
21
20
  value?: TValue | undefined;
22
- } & (Exclude<keyof import("../utils/types.js").PropsOf<TTag>, ("as" | "children" | "refName" | "class") | "invalid" | "disabled" | "autofocus" | "value" | "id" | InputPropsWeControl> extends infer T extends keyof import("../utils/types.js").PropsOf<TTag> ? { [P in T]: import("../utils/types.js").PropsOf<TTag>[P]; } : never) & {
23
- children?: import("../utils/types.js").Children<InputRenderPropArg> | undefined;
21
+ } & (Exclude<keyof PropsOf<TTag>, ("slot" | "as" | "children" | "class" | "ref") | "invalid" | "disabled" | "autofocus" | "value" | InputPropsWeControl> extends infer T extends keyof PropsOf<TTag> ? { [P in T]: PropsOf<TTag>[P]; } : never) & {
22
+ children?: import("svelte").Snippet<[{
23
+ slot: InputRenderPropArg;
24
+ props: Record<string, any>;
25
+ }]> | undefined;
26
+ class?: string | ((bag: InputRenderPropArg) => string) | null | undefined;
24
27
  ref?: HTMLElement;
25
- } & (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) ? {
26
- class?: import("../utils/types.js").PropsOf<TTag>["class"] | ((bag: InputRenderPropArg) => string) | undefined;
27
- } : {}) & {
28
- id?: string;
28
+ } & {
29
29
  value?: TValue | undefined;
30
30
  disabled?: boolean;
31
31
  invalid?: boolean;
32
32
  autofocus?: boolean;
33
33
  };
34
- events(): {} & {
35
- [evt: string]: CustomEvent<any>;
36
- };
34
+ events(): {};
37
35
  slots(): {};
38
36
  bindings(): "ref" | "value";
39
37
  exports(): {};
@@ -42,9 +40,7 @@ interface $$IsomorphicComponent {
42
40
  new <TTag extends ElementType = typeof DEFAULT_INPUT_TAG, TValue = string>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TTag, TValue>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TTag, TValue>['props']>, ReturnType<__sveltets_Render<TTag, TValue>['events']>, ReturnType<__sveltets_Render<TTag, TValue>['slots']>> & {
43
41
  $$bindings?: ReturnType<__sveltets_Render<TTag, TValue>['bindings']>;
44
42
  } & ReturnType<__sveltets_Render<TTag, TValue>['exports']>;
45
- <TTag extends ElementType = typeof DEFAULT_INPUT_TAG, TValue = string>(internal: unknown, props: ReturnType<__sveltets_Render<TTag, TValue>['props']> & {
46
- $$events?: ReturnType<__sveltets_Render<TTag, TValue>['events']>;
47
- }): ReturnType<__sveltets_Render<TTag, TValue>['exports']>;
43
+ <TTag extends ElementType = typeof DEFAULT_INPUT_TAG, TValue = string>(internal: unknown, props: ReturnType<__sveltets_Render<TTag, TValue>['props']> & {}): ReturnType<__sveltets_Render<TTag, TValue>['exports']>;
48
44
  z_$$bindings?: ReturnType<__sveltets_Render<any, any>['bindings']>;
49
45
  }
50
46
  declare const Input: $$IsomorphicComponent;
@@ -0,0 +1,12 @@
1
+ <script lang="ts" module></script>
2
+
3
+ <script lang="ts">import { useFloatingProvider } from "./floating-provider.svelte.js";
4
+ const { children, enabled = true } = $props();
5
+ useFloatingProvider({
6
+ get enabled() {
7
+ return enabled;
8
+ }
9
+ });
10
+ </script>
11
+
12
+ {#if children}{@render children()}{/if}
@@ -0,0 +1,6 @@
1
+ import type { Snippet } from "svelte";
2
+ declare const FloatingProvider: import("svelte").Component<{
3
+ children: Snippet;
4
+ enabled?: boolean;
5
+ }, {}, "">;
6
+ export default FloatingProvider;
@@ -1,20 +1,4 @@
1
- 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> {
2
- new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
3
- $$bindings?: Bindings;
4
- } & Exports;
5
- (internal: unknown, props: Props & {
6
- $$events?: Events;
7
- $$slots?: Slots;
8
- }): Exports & {
9
- $set?: any;
10
- $on?: any;
11
- };
12
- z_$$bindings?: Bindings;
13
- }
14
- declare const FocusSentinel: $$__sveltets_2_IsomorphicComponent<{
1
+ declare const FocusSentinel: import("svelte").Component<{
15
2
  onfocus: () => boolean;
16
- }, {
17
- [evt: string]: CustomEvent<any>;
18
- }, {}, {}, "">;
19
- type FocusSentinel = InstanceType<typeof FocusSentinel>;
3
+ }, {}, "">;
20
4
  export default FocusSentinel;
@@ -1,22 +1,6 @@
1
1
  import type { Snippet } from "svelte";
2
- 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> {
3
- new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
4
- $$bindings?: Bindings;
5
- } & Exports;
6
- (internal: unknown, props: Props & {
7
- $$events?: Events;
8
- $$slots?: Slots;
9
- }): Exports & {
10
- $set?: any;
11
- $on?: any;
12
- };
13
- z_$$bindings?: Bindings;
14
- }
15
- declare const ForcePortalRoot: $$__sveltets_2_IsomorphicComponent<{
2
+ declare const ForcePortalRoot: import("svelte").Component<{
16
3
  force: boolean;
17
4
  children: Snippet;
18
- }, {
19
- [evt: string]: CustomEvent<any>;
20
- }, {}, {}, "">;
21
- type ForcePortalRoot = InstanceType<typeof ForcePortalRoot>;
5
+ }, {}, "">;
22
6
  export default ForcePortalRoot;
@@ -1,7 +1,7 @@
1
1
  <script lang="ts">import { disposables } from "../utils/disposables.js";
2
2
  import { objectToFormEntries } from "../utils/form.js";
3
3
  import FormResolver from "./FormResolver.svelte";
4
- import HoistFormFields from "./HoistFormFields.svelte";
4
+ import { hoistFormFields } from "./form-fields.svelte.js";
5
5
  import Hidden, { HiddenFeatures } from "./Hidden.svelte";
6
6
  import { compact } from "../utils/object.js";
7
7
  let {
@@ -18,25 +18,28 @@ $effect(() => {
18
18
  if (!form) return;
19
19
  return d.addEventListener(form, "reset", onReset);
20
20
  });
21
+ const fields = $derived(
22
+ objectToFormEntries(data).map(
23
+ ([name, value]) => compact({
24
+ key: name,
25
+ as: "input",
26
+ type: "hidden",
27
+ form: formId,
28
+ disabled,
29
+ name,
30
+ value,
31
+ ...overrides
32
+ })
33
+ )
34
+ );
35
+ const hoisted = hoistFormFields(formFields);
21
36
  </script>
22
37
 
23
- <HoistFormFields>
38
+ {#snippet formFields()}
24
39
  <FormResolver setForm={(value) => (form = value)} {formId} />
25
- {#each objectToFormEntries(data) as [name, value]}
26
- <Hidden
27
- features={HiddenFeatures.Hidden}
28
- {...compact({
29
- key: name,
30
- as: "input",
31
- type: "hidden",
32
- hidden: true,
33
- readOnly: true,
34
- form: formId,
35
- disabled,
36
- name,
37
- value,
38
- ...overrides,
39
- })}
40
- />
40
+ {#each fields as props}
41
+ <Hidden features={HiddenFeatures.Hidden} {...props} />
41
42
  {/each}
42
- </HoistFormFields>
43
+ {/snippet}
44
+
45
+ {#if !hoisted}{@render formFields()}{/if}
@@ -1,24 +1,8 @@
1
- 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> {
2
- new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
3
- $$bindings?: Bindings;
4
- } & Exports;
5
- (internal: unknown, props: Props & {
6
- $$events?: Events;
7
- $$slots?: Slots;
8
- }): Exports & {
9
- $set?: any;
10
- $on?: any;
11
- };
12
- z_$$bindings?: Bindings;
13
- }
14
- declare const FormFields: $$__sveltets_2_IsomorphicComponent<{
1
+ declare const FormFields: import("svelte").Component<{
15
2
  data: Record<string, any>;
16
3
  overrides?: Record<string, any>;
17
4
  form?: string;
18
5
  disabled?: boolean;
19
6
  onReset?: (e: Event) => void;
20
- }, {
21
- [evt: string]: CustomEvent<any>;
22
- }, {}, {}, "">;
23
- type FormFields = InstanceType<typeof FormFields>;
7
+ }, {}, "">;
24
8
  export default FormFields;
@@ -0,0 +1,13 @@
1
+ <script lang="ts">import Hidden, { HiddenFeatures } from "./Hidden.svelte";
2
+ import { createFormFieldsContext } from "./form-fields.svelte.js";
3
+ const { children } = $props();
4
+ const context = createFormFieldsContext();
5
+ const { fields } = $derived(context);
6
+ </script>
7
+
8
+ {#if children}{@render children()}{/if}
9
+ <Hidden features={HiddenFeatures.Hidden}>
10
+ {#each fields as field}
11
+ {@render field()}
12
+ {/each}
13
+ </Hidden>
@@ -0,0 +1,5 @@
1
+ import type { Snippet } from "svelte";
2
+ declare const FormFieldsProvider: import("svelte").Component<{
3
+ children?: Snippet;
4
+ }, {}, "">;
5
+ export default FormFieldsProvider;
@@ -1,21 +1,5 @@
1
- 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> {
2
- new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
3
- $$bindings?: Bindings;
4
- } & Exports;
5
- (internal: unknown, props: Props & {
6
- $$events?: Events;
7
- $$slots?: Slots;
8
- }): Exports & {
9
- $set?: any;
10
- $on?: any;
11
- };
12
- z_$$bindings?: Bindings;
13
- }
14
- declare const FormResolver: $$__sveltets_2_IsomorphicComponent<{
1
+ declare const FormResolver: import("svelte").Component<{
15
2
  setForm: (form: HTMLFormElement) => void;
16
3
  formId?: string;
17
- }, {
18
- [evt: string]: CustomEvent<any>;
19
- }, {}, {}, "">;
20
- type FormResolver = InstanceType<typeof FormResolver>;
4
+ }, {}, "">;
21
5
  export default FormResolver;