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

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 (65) hide show
  1. package/dist/button/Button.svelte +84 -54
  2. package/dist/checkbox/Checkbox.svelte +174 -120
  3. package/dist/close-button/CloseButton.svelte +12 -6
  4. package/dist/combobox/Combobox.svelte +50 -3
  5. package/dist/data-interactive/DataInteractive.svelte +57 -29
  6. package/dist/description/Description.svelte +32 -21
  7. package/dist/dialog/Dialog.svelte +69 -34
  8. package/dist/dialog/DialogBackdrop.svelte +29 -12
  9. package/dist/dialog/DialogPanel.svelte +49 -26
  10. package/dist/dialog/DialogTitle.svelte +38 -23
  11. package/dist/dialog/InternalDialog.svelte +263 -202
  12. package/dist/field/Field.svelte +49 -26
  13. package/dist/fieldset/Fieldset.svelte +50 -29
  14. package/dist/focus-trap/FocusTrap.svelte +419 -290
  15. package/dist/focus-trap/FocusTrap.svelte.d.ts +2 -14
  16. package/dist/focus-trap/FocusTrapFeatures.d.ts +14 -0
  17. package/dist/focus-trap/FocusTrapFeatures.js +15 -0
  18. package/dist/input/Input.svelte +85 -53
  19. package/dist/internal/FocusSentinel.svelte +16 -8
  20. package/dist/internal/ForcePortalRoot.svelte +7 -3
  21. package/dist/internal/FormFields.svelte +31 -20
  22. package/dist/internal/FormResolver.svelte +20 -15
  23. package/dist/internal/Hidden.svelte +44 -27
  24. package/dist/internal/Hidden.svelte.d.ts +2 -5
  25. package/dist/internal/HiddenFeatures.d.ts +5 -0
  26. package/dist/internal/HiddenFeatures.js +9 -0
  27. package/dist/internal/HoistFormFields.svelte +7 -4
  28. package/dist/internal/MainTreeProvider.svelte +89 -36
  29. package/dist/internal/Portal.svelte +18 -14
  30. package/dist/label/Label.svelte +91 -57
  31. package/dist/legend/Legend.svelte +18 -3
  32. package/dist/listbox/Listbox.svelte +588 -409
  33. package/dist/listbox/Listbox.svelte.d.ts +2 -12
  34. package/dist/listbox/ListboxButton.svelte +176 -127
  35. package/dist/listbox/ListboxOption.svelte +166 -125
  36. package/dist/listbox/ListboxOptions.svelte +340 -244
  37. package/dist/listbox/ListboxSelectedOption.svelte +38 -15
  38. package/dist/listbox/ListboxStates.d.ts +12 -0
  39. package/dist/listbox/ListboxStates.js +15 -0
  40. package/dist/menu/Menu.svelte +307 -218
  41. package/dist/menu/MenuButton.svelte +157 -115
  42. package/dist/menu/MenuHeading.svelte +34 -14
  43. package/dist/menu/MenuItem.svelte +145 -107
  44. package/dist/menu/MenuItems.svelte +298 -224
  45. package/dist/menu/MenuSection.svelte +26 -9
  46. package/dist/menu/MenuSeparator.svelte +20 -4
  47. package/dist/portal/InternalPortal.svelte +141 -85
  48. package/dist/portal/Portal.svelte +5 -2
  49. package/dist/portal/PortalGroup.svelte +30 -9
  50. package/dist/switch/Switch.svelte +179 -122
  51. package/dist/switch/Switch.svelte.d.ts +4 -4
  52. package/dist/switch/SwitchGroup.svelte +44 -31
  53. package/dist/tabs/Tab.svelte +195 -143
  54. package/dist/tabs/TabGroup.svelte +292 -205
  55. package/dist/tabs/TabList.svelte +31 -11
  56. package/dist/tabs/TabPanel.svelte +68 -43
  57. package/dist/tabs/TabPanels.svelte +18 -7
  58. package/dist/textarea/Textarea.svelte +83 -53
  59. package/dist/transition/InternalTransitionChild.svelte +259 -170
  60. package/dist/transition/Transition.svelte +96 -66
  61. package/dist/transition/TransitionChild.svelte +31 -11
  62. package/dist/utils/ElementOrComponent.svelte +44 -23
  63. package/dist/utils/Generic.svelte +29 -17
  64. package/dist/utils/StableCollection.svelte +54 -36
  65. package/package.json +10 -10
@@ -1,26 +1,37 @@
1
- <script lang="ts" module>let DEFAULT_DESCRIPTION_TAG = "p";
1
+ <script lang="ts" module>
2
+ import type { ElementType, Props, PropsOf } from "../utils/types.js"
3
+
4
+ let DEFAULT_DESCRIPTION_TAG = "p" as const
5
+
6
+ export type DescriptionProps<TTag extends ElementType = typeof DEFAULT_DESCRIPTION_TAG> = Props<TTag>
2
7
  </script>
3
8
 
4
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_DESCRIPTION_TAG">import { htmlid } from "../utils/id.js";
5
- import { stateFromSlot } from "../utils/state.js";
6
- import { useDisabled } from "../hooks/use-disabled.js";
7
- import { onMount } from "svelte";
8
- import { useDescriptionContext } from "./context.svelte.js";
9
- const internalId = htmlid();
10
- const providedDisabled = useDisabled();
11
- let {
12
- as,
13
- id = `headlessui-description-${internalId}`,
14
- children,
15
- ...theirProps
16
- } = $props();
17
- const context = useDescriptionContext();
18
- onMount(() => {
19
- context.register(id);
20
- });
21
- const disabled = $derived(providedDisabled.value || false);
22
- const slot = $derived({ disabled });
23
- const ourProps = $derived({ id, ...stateFromSlot(slot) });
9
+ <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_DESCRIPTION_TAG">
10
+ import { htmlid } from "../utils/id.js"
11
+ import { stateFromSlot } from "../utils/state.js"
12
+ import { useDisabled } from "../hooks/use-disabled.js"
13
+ import { onMount } from "svelte"
14
+ import { useDescriptionContext } from "./context.svelte.js"
15
+
16
+ const internalId = htmlid()
17
+ const providedDisabled = useDisabled()
18
+
19
+ let {
20
+ as,
21
+ id = `headlessui-description-${internalId}` as PropsOf<TTag>["id"],
22
+ children,
23
+ ...theirProps
24
+ }: { as?: TTag } & DescriptionProps<TTag> = $props()
25
+
26
+ const context = useDescriptionContext()
27
+
28
+ onMount(() => {
29
+ context.register(id)
30
+ })
31
+
32
+ const disabled = $derived(providedDisabled.value || false)
33
+ const slot = $derived({ disabled })
34
+ const ourProps = $derived({ id, ...stateFromSlot(slot) })
24
35
  </script>
25
36
 
26
37
  <svelte:element this={as ?? DEFAULT_DESCRIPTION_TAG} {...ourProps} {...theirProps}>
@@ -1,39 +1,74 @@
1
- <script lang="ts" module>import { MainTreeProvider } from "../hooks/use-root-containers.svelte.js";
2
- import { useOpenClosed } from "../internal/open-closed.js";
3
- import { RenderFeatures } from "../utils/render.js";
4
- import { getContext } from "svelte";
5
- import InternalDialog from "./InternalDialog.svelte";
6
- import Transition from "../transition/Transition.svelte";
7
- export const DEFAULT_DIALOG_TAG = "div";
8
- export const DialogRenderFeatures = RenderFeatures.RenderStrategy | RenderFeatures.Static;
9
- </script>
1
+ <script lang="ts" module>
2
+ import { MainTreeProvider } from "../hooks/use-root-containers.svelte.js"
3
+ import { useOpenClosed } from "../internal/open-closed.js"
4
+ import { RenderFeatures, type PropsForFeatures } from "../utils/render.js"
5
+ import type { ElementType, Props } from "../utils/types.js"
6
+ import { getContext, type Component, type Snippet } from "svelte"
7
+ import InternalDialog from "./InternalDialog.svelte"
8
+ import Transition from "../transition/Transition.svelte"
10
9
 
11
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_DIALOG_TAG">let { ref = $bindable(), transition = false, open, ...rest } = $props();
12
- const usesOpenClosedState = useOpenClosed();
13
- const hasOpen = $derived(open !== void 0 || usesOpenClosedState);
14
- const hasOnClose = $derived(rest.hasOwnProperty("onclose"));
15
- $effect(() => {
16
- if (!hasOpen && !hasOnClose) {
17
- throw new Error(`You have to provide an \`open\` and an \`onclose\` prop to the \`Dialog\` component.`);
18
- }
19
- if (!hasOpen) {
20
- throw new Error(`You provided an \`onclose\` prop to the \`Dialog\`, but forgot an \`open\` prop.`);
21
- }
22
- if (!hasOnClose) {
23
- throw new Error(`You provided an \`open\` prop to the \`Dialog\`, but forgot an \`onclose\` prop.`);
24
- }
25
- if (!usesOpenClosedState && typeof open !== "boolean") {
26
- throw new Error(
27
- `You provided an \`open\` prop to the \`Dialog\`, but the value is not a boolean. Received: ${open}`
28
- );
29
- }
30
- if (typeof rest.onclose !== "function") {
31
- throw new Error(
32
- `You provided an \`onclose\` prop to the \`Dialog\`, but the value is not a function. Received: ${rest.onclose}`
33
- );
10
+ export const DEFAULT_DIALOG_TAG = "div" as const
11
+ export type DialogRenderPropArg = {
12
+ open: boolean
34
13
  }
35
- });
36
- const DialogComponent = InternalDialog;
14
+ type DialogPropsWeControl = "aria-describedby" | "aria-labelledby" | "aria-modal"
15
+
16
+ export const DialogRenderFeatures = RenderFeatures.RenderStrategy | RenderFeatures.Static
17
+
18
+ export type DialogProps<TTag extends ElementType = typeof DEFAULT_DIALOG_TAG> = Props<
19
+ TTag,
20
+ DialogRenderPropArg,
21
+ DialogPropsWeControl,
22
+ PropsForFeatures<typeof DialogRenderFeatures> & {
23
+ id?: string
24
+ open?: boolean
25
+ onclose(value: boolean): void
26
+ initialFocus?: HTMLElement
27
+ role?: "dialog" | "alertdialog"
28
+ autofocus?: boolean
29
+ transition?: boolean
30
+ __demoMode?: boolean
31
+ }
32
+ >
33
+
34
+ export type DialogChildren = Snippet<[DialogRenderPropArg]>
35
+ </script>
36
+
37
+ <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_DIALOG_TAG">
38
+ let { ref = $bindable(), transition = false, open, ...rest }: { as?: TTag } & DialogProps<TTag> = $props()
39
+
40
+ // Validations
41
+ const usesOpenClosedState = useOpenClosed()
42
+ const hasOpen = $derived(open !== undefined || usesOpenClosedState)
43
+ const hasOnClose = $derived(rest.hasOwnProperty("onclose"))
44
+
45
+ $effect(() => {
46
+ if (!hasOpen && !hasOnClose) {
47
+ throw new Error(`You have to provide an \`open\` and an \`onclose\` prop to the \`Dialog\` component.`)
48
+ }
49
+
50
+ if (!hasOpen) {
51
+ throw new Error(`You provided an \`onclose\` prop to the \`Dialog\`, but forgot an \`open\` prop.`)
52
+ }
53
+
54
+ if (!hasOnClose) {
55
+ throw new Error(`You provided an \`open\` prop to the \`Dialog\`, but forgot an \`onclose\` prop.`)
56
+ }
57
+
58
+ if (!usesOpenClosedState && typeof open !== "boolean") {
59
+ throw new Error(
60
+ `You provided an \`open\` prop to the \`Dialog\`, but the value is not a boolean. Received: ${open}`
61
+ )
62
+ }
63
+
64
+ if (typeof rest.onclose !== "function") {
65
+ throw new Error(
66
+ `You provided an \`onclose\` prop to the \`Dialog\`, but the value is not a function. Received: ${rest.onclose}`
67
+ )
68
+ }
69
+ })
70
+
71
+ const DialogComponent = InternalDialog as Component<DialogProps<TTag>, any>
37
72
  </script>
38
73
 
39
74
  {#if (open !== undefined || transition) && !rest.static}
@@ -1,17 +1,34 @@
1
- <script lang="ts" module>let DEFAULT_BACKDROP_TAG = "div";
1
+ <script lang="ts" module>
2
+ import type { ElementType, Props } from "../utils/types.js"
3
+
4
+ let DEFAULT_BACKDROP_TAG = "div" as const
5
+ type BackdropRenderPropArg = {
6
+ open: boolean
7
+ }
8
+
9
+ export type DialogBackdropProps<TTag extends ElementType = typeof DEFAULT_BACKDROP_TAG> = Props<
10
+ TTag,
11
+ BackdropRenderPropArg,
12
+ never,
13
+ { transition?: boolean }
14
+ >
2
15
  </script>
3
16
 
4
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_BACKDROP_TAG">import { DialogStates, useDialogContext } from "./context.svelte.js";
5
- import ElementOrComponent from "../utils/ElementOrComponent.svelte";
6
- import { mergeProps } from "../utils/render.js";
7
- import TransitionChild from "../transition/TransitionChild.svelte";
8
- let { ref = $bindable(), transition = false, ...theirProps } = $props();
9
- const _state = useDialogContext("Dialog.Panel");
10
- const { dialogState, unmount } = $derived(_state);
11
- const slot = $derived({ open: dialogState === DialogStates.Open });
12
- const ourProps = mergeProps({
13
- "aria-hidden": true
14
- });
17
+ <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_BACKDROP_TAG">
18
+ import { DialogStates, useDialogContext } from "./context.svelte.js"
19
+ import ElementOrComponent from "../utils/ElementOrComponent.svelte"
20
+ import { mergeProps } from "../utils/render.js"
21
+ import TransitionChild from "../transition/TransitionChild.svelte"
22
+
23
+ let { ref = $bindable(), transition = false, ...theirProps }: { as?: TTag } & DialogBackdropProps<TTag> = $props()
24
+ const _state = useDialogContext("Dialog.Panel")
25
+ const { dialogState, unmount } = $derived(_state)
26
+
27
+ const slot = $derived({ open: dialogState === DialogStates.Open } satisfies BackdropRenderPropArg)
28
+
29
+ const ourProps = mergeProps({
30
+ "aria-hidden": true,
31
+ })
15
32
  </script>
16
33
 
17
34
  {#if transition}
@@ -1,31 +1,54 @@
1
- <script lang="ts" module>let DEFAULT_PANEL_TAG = "div";
1
+ <script lang="ts" module>
2
+ import type { ElementType, Props } from "../utils/types.js"
3
+
4
+ let DEFAULT_PANEL_TAG = "div" as const
5
+ type PanelRenderPropArg = {
6
+ open: boolean
7
+ }
8
+
9
+ export type DialogPanelProps<TTag extends ElementType = typeof DEFAULT_PANEL_TAG> = Props<
10
+ TTag,
11
+ PanelRenderPropArg,
12
+ never,
13
+ {
14
+ id?: string
15
+ transition?: boolean
16
+ }
17
+ >
2
18
  </script>
3
19
 
4
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_PANEL_TAG">import { useId } from "../hooks/use-id.js";
5
- import { DialogStates, useDialogContext } from "./context.svelte.js";
6
- import ElementOrComponent from "../utils/ElementOrComponent.svelte";
7
- import { mergeProps } from "../utils/render.js";
8
- import TransitionChild from "../transition/TransitionChild.svelte";
9
- import { onMount } from "svelte";
10
- let internalId = useId();
11
- let {
12
- ref = $bindable(),
13
- id = `headlessui-dialog-panel-${internalId}`,
14
- transition = false,
15
- ...theirProps
16
- } = $props();
17
- const _state = useDialogContext("Dialog.Panel");
18
- const { dialogState, unmount } = $derived(_state);
19
- const slot = $derived({ open: dialogState === DialogStates.Open });
20
- const handleClick = (event) => {
21
- event.stopPropagation();
22
- };
23
- const ourProps = $derived(
24
- mergeProps({
25
- id,
26
- onclick: handleClick
27
- })
28
- );
20
+ <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_PANEL_TAG">
21
+ import { useId } from "../hooks/use-id.js"
22
+ import { DialogStates, useDialogContext } from "./context.svelte.js"
23
+ import ElementOrComponent from "../utils/ElementOrComponent.svelte"
24
+ import { mergeProps } from "../utils/render.js"
25
+ import TransitionChild from "../transition/TransitionChild.svelte"
26
+ import { onMount } from "svelte"
27
+
28
+ let internalId = useId()
29
+ let {
30
+ ref = $bindable(),
31
+ id = `headlessui-dialog-panel-${internalId}`,
32
+ transition = false,
33
+ ...theirProps
34
+ }: { as?: TTag } & DialogPanelProps<TTag> = $props()
35
+ const _state = useDialogContext("Dialog.Panel")
36
+ const { dialogState, unmount } = $derived(_state)
37
+
38
+ const slot = $derived({ open: dialogState === DialogStates.Open } satisfies PanelRenderPropArg)
39
+
40
+ // Prevent the click events inside the Dialog.Panel from bubbling through the React Tree which
41
+ // could submit wrapping <form> elements even if we portalled the Dialog.
42
+ const handleClick = (event: MouseEvent) => {
43
+ event.stopPropagation()
44
+ }
45
+
46
+ const ourProps = $derived(
47
+ mergeProps({
48
+ id,
49
+ onclick: handleClick,
50
+ })
51
+ )
29
52
  </script>
30
53
 
31
54
  {#if transition}
@@ -1,29 +1,44 @@
1
- <script lang="ts" module>let DEFAULT_TITLE_TAG = "h2";
1
+ <script lang="ts" module>
2
+ import type { ElementType, Props, PropsOf } from "../utils/types.js"
3
+
4
+ let DEFAULT_TITLE_TAG = "h2" as const
5
+ type TitleRenderPropArg = {
6
+ open: boolean
7
+ }
8
+
9
+ export type DialogTitleProps<TTag extends ElementType = typeof DEFAULT_TITLE_TAG> = Props<TTag, TitleRenderPropArg>
10
+
11
+ //
2
12
  </script>
3
13
 
4
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_TITLE_TAG">import { useId } from "../hooks/use-id.js";
5
- import { DialogStates, useDialogContext } from "./context.svelte.js";
6
- import { onMount } from "svelte";
7
- import ElementOrComponent from "../utils/ElementOrComponent.svelte";
8
- import { mergeProps } from "../utils/render.js";
9
- const internalId = useId();
10
- let {
11
- ref = $bindable(),
12
- id = `headlessui-dialog-title-${internalId}`,
13
- ...theirProps
14
- } = $props();
15
- const _state = useDialogContext("Dialog.Panel");
16
- const { dialogState, setTitleId } = $derived(_state);
17
- onMount(() => {
18
- setTitleId(id);
19
- return () => setTitleId(null);
20
- });
21
- const slot = $derived({ open: dialogState === DialogStates.Open });
22
- const ourProps = $derived(
23
- mergeProps({
24
- id
14
+ <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_TITLE_TAG">
15
+ import { useId } from "../hooks/use-id.js"
16
+ import { DialogStates, useDialogContext } from "./context.svelte.js"
17
+ import { onMount } from "svelte"
18
+ import ElementOrComponent from "../utils/ElementOrComponent.svelte"
19
+ import { mergeProps } from "../utils/render.js"
20
+
21
+ const internalId = useId()
22
+ let {
23
+ ref = $bindable(),
24
+ id = `headlessui-dialog-title-${internalId}` as PropsOf<TTag>[string],
25
+ ...theirProps
26
+ }: { as?: TTag } & DialogTitleProps<TTag> = $props()
27
+ const _state = useDialogContext("Dialog.Panel")
28
+ const { dialogState, setTitleId } = $derived(_state)
29
+
30
+ onMount(() => {
31
+ setTitleId(id)
32
+ return () => setTitleId(null)
25
33
  })
26
- );
34
+
35
+ const slot = $derived({ open: dialogState === DialogStates.Open } satisfies TitleRenderPropArg)
36
+
37
+ const ourProps = $derived(
38
+ mergeProps({
39
+ id,
40
+ })
41
+ )
27
42
  </script>
28
43
 
29
44
  <ElementOrComponent {ourProps} {theirProps} slots={slot} defaultTag={DEFAULT_TITLE_TAG} name="DialogTitle" bind:ref />