@pzerelles/headlessui-svelte 2.1.2-next.2 → 2.1.2-next.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/button/Button.svelte +84 -54
- package/dist/checkbox/Checkbox.svelte +174 -120
- package/dist/close-button/CloseButton.svelte +12 -6
- package/dist/combobox/Combobox.svelte +50 -3
- package/dist/data-interactive/DataInteractive.svelte +57 -29
- package/dist/description/Description.svelte +32 -21
- package/dist/dialog/Dialog.svelte +69 -34
- package/dist/dialog/DialogBackdrop.svelte +29 -12
- package/dist/dialog/DialogPanel.svelte +49 -26
- package/dist/dialog/DialogTitle.svelte +38 -23
- package/dist/dialog/InternalDialog.svelte +263 -202
- package/dist/field/Field.svelte +49 -26
- package/dist/fieldset/Fieldset.svelte +50 -29
- package/dist/focus-trap/FocusTrap.svelte +436 -290
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/input/Input.svelte +85 -53
- package/dist/internal/FocusSentinel.svelte +16 -8
- package/dist/internal/ForcePortalRoot.svelte +7 -3
- package/dist/internal/FormFields.svelte +31 -20
- package/dist/internal/FormResolver.svelte +20 -15
- package/dist/internal/Hidden.svelte +44 -27
- package/dist/internal/Hidden.svelte.d.ts +2 -5
- package/dist/internal/HiddenFeatures.d.ts +5 -0
- package/dist/internal/HiddenFeatures.js +9 -0
- package/dist/internal/HoistFormFields.svelte +7 -4
- package/dist/internal/MainTreeProvider.svelte +89 -36
- package/dist/internal/Portal.svelte +18 -14
- package/dist/label/Label.svelte +91 -57
- package/dist/legend/Legend.svelte +18 -3
- package/dist/listbox/Listbox.svelte +600 -409
- package/dist/listbox/ListboxButton.svelte +176 -127
- package/dist/listbox/ListboxOption.svelte +166 -125
- package/dist/listbox/ListboxOptions.svelte +340 -244
- package/dist/listbox/ListboxSelectedOption.svelte +38 -15
- package/dist/menu/Menu.svelte +307 -218
- package/dist/menu/MenuButton.svelte +157 -115
- package/dist/menu/MenuHeading.svelte +34 -14
- package/dist/menu/MenuItem.svelte +145 -107
- package/dist/menu/MenuItems.svelte +298 -224
- package/dist/menu/MenuSection.svelte +26 -9
- package/dist/menu/MenuSeparator.svelte +20 -4
- package/dist/portal/InternalPortal.svelte +141 -85
- package/dist/portal/Portal.svelte +5 -2
- package/dist/portal/PortalGroup.svelte +30 -9
- package/dist/switch/Switch.svelte +179 -122
- package/dist/switch/Switch.svelte.d.ts +4 -4
- package/dist/switch/SwitchGroup.svelte +44 -31
- package/dist/tabs/Tab.svelte +195 -143
- package/dist/tabs/TabGroup.svelte +292 -205
- package/dist/tabs/TabList.svelte +31 -11
- package/dist/tabs/TabPanel.svelte +68 -43
- package/dist/tabs/TabPanels.svelte +18 -7
- package/dist/textarea/Textarea.svelte +97 -0
- package/dist/textarea/Textarea.svelte.d.ts +47 -0
- package/dist/textarea/index.d.ts +1 -0
- package/dist/textarea/index.js +1 -0
- package/dist/transition/InternalTransitionChild.svelte +259 -170
- package/dist/transition/Transition.svelte +96 -66
- package/dist/transition/TransitionChild.svelte +31 -11
- package/dist/utils/ElementOrComponent.svelte +44 -23
- package/dist/utils/Generic.svelte +29 -17
- package/dist/utils/StableCollection.svelte +54 -36
- package/package.json +10 -10
|
@@ -1,26 +1,37 @@
|
|
|
1
|
-
<script lang="ts" module>
|
|
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">
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
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>
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
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>
|
|
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">
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
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>
|
|
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">
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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>
|
|
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">
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
setTitleId(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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 />
|