lithesome 0.12.1 → 0.12.3
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/components/Combobox/ComboboxContent.svelte +21 -55
- package/dist/components/Combobox/ComboboxInput.svelte +1 -1
- package/dist/components/Hovercard/HovercardContent.svelte +22 -65
- package/dist/components/Hovercard/context.svelte.d.ts +1 -0
- package/dist/components/Hovercard/context.svelte.js +4 -0
- package/dist/components/Menu/MenuContent.svelte +21 -50
- package/dist/components/Popover/PopoverContent.svelte +32 -71
- package/dist/components/Select/SelectContent.svelte +20 -49
- package/dist/components/Toast/Toast.svelte +18 -18
- package/dist/components/Toast/ToastMessage.svelte +12 -12
- package/dist/components/Toast/ToastTitle.svelte +5 -5
- package/dist/components/Toast/Toaster.svelte +12 -12
- package/dist/internal/components/FloatingContent.svelte +74 -0
- package/dist/internal/components/FloatingContent.svelte.d.ts +21 -0
- package/dist/internal/helpers/context.svelte.js +4 -6
- package/dist/internal/helpers/floating.d.ts +1 -1
- package/dist/internal/helpers/floating.js +6 -6
- package/dist/internal/index.d.ts +1 -0
- package/dist/internal/index.js +1 -0
- package/package.json +1 -1
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
<script lang="ts">import { context } from "./Combobox.svelte";
|
|
2
|
-
import {
|
|
3
|
-
import { usePortal, useOutside } from "../../index.js";
|
|
4
|
-
import { onMount } from "svelte";
|
|
2
|
+
import { classProp, FloatingContent } from "../../internal/index.js";
|
|
5
3
|
let {
|
|
6
4
|
children,
|
|
7
5
|
transition,
|
|
@@ -15,57 +13,25 @@ let {
|
|
|
15
13
|
...props
|
|
16
14
|
} = $props();
|
|
17
15
|
const ctx = context();
|
|
18
|
-
const {
|
|
19
|
-
const attrs = $derived({
|
|
20
|
-
id: ctx.uid("content"),
|
|
21
|
-
"aria-labelledby": ctx.uid("trigger"),
|
|
22
|
-
role: "listbox",
|
|
23
|
-
class: classProp(klass, { visible: ctx.visible }),
|
|
24
|
-
"data-comboboxcontent": "",
|
|
25
|
-
hidden: !ctx.mounted || void 0
|
|
26
|
-
});
|
|
27
|
-
onMount(() => {
|
|
28
|
-
if (!ctx)
|
|
29
|
-
log.error("<ComboboxContent> Must be a direct child of <Combobox />");
|
|
30
|
-
});
|
|
31
|
-
$effect(() => {
|
|
32
|
-
if (ctx.visible && self)
|
|
33
|
-
ctx.content = self;
|
|
34
|
-
});
|
|
16
|
+
const state = $derived({ visible: ctx.visible });
|
|
35
17
|
</script>
|
|
36
18
|
|
|
37
|
-
|
|
38
|
-
{
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
{:else if ctx.visible}
|
|
57
|
-
<div
|
|
58
|
-
bind:this={self}
|
|
59
|
-
use:useFloating={{ anchor: ctx.trigger, arrow: ctx.arrow, sameWidth, constrainViewport, placement }}
|
|
60
|
-
use:useOutside={{
|
|
61
|
-
exclude: ctx.trigger,
|
|
62
|
-
callback: () => ctx.close()
|
|
63
|
-
}}
|
|
64
|
-
use:usePortal={portalTarget}
|
|
65
|
-
use:useActions={use}
|
|
66
|
-
{...attrs}
|
|
67
|
-
{...props}
|
|
68
|
-
>
|
|
69
|
-
{@render children({ visible: ctx.visible })}
|
|
70
|
-
</div>
|
|
71
|
-
{/if}
|
|
19
|
+
<FloatingContent
|
|
20
|
+
{children}
|
|
21
|
+
componentName="Select"
|
|
22
|
+
visible={ctx.visible}
|
|
23
|
+
bind:self
|
|
24
|
+
{state}
|
|
25
|
+
{ctx}
|
|
26
|
+
{transition}
|
|
27
|
+
{use}
|
|
28
|
+
{sameWidth}
|
|
29
|
+
{constrainViewport}
|
|
30
|
+
{placement}
|
|
31
|
+
{portalTarget}
|
|
32
|
+
outsideCallback={() => ctx.close()}
|
|
33
|
+
role="listbox"
|
|
34
|
+
class={classProp(klass, state)}
|
|
35
|
+
hidden={!ctx.mounted || undefined}
|
|
36
|
+
{...props}
|
|
37
|
+
/>
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
<script lang="ts">import { context } from "./Hovercard.svelte";
|
|
2
|
-
import {
|
|
3
|
-
import { useOutside, usePortal } from "../../index.js";
|
|
4
|
-
import { onMount } from "svelte";
|
|
2
|
+
import { classProp, FloatingContent } from "../../internal/index.js";
|
|
5
3
|
let {
|
|
6
4
|
children,
|
|
7
5
|
transition,
|
|
@@ -17,21 +15,7 @@ let {
|
|
|
17
15
|
...props
|
|
18
16
|
} = $props();
|
|
19
17
|
const ctx = context();
|
|
20
|
-
const {
|
|
21
|
-
const attrs = $derived({
|
|
22
|
-
id: ctx.uid("content"),
|
|
23
|
-
"aria-labelledby": ctx.uid("trigger"),
|
|
24
|
-
class: classProp(klass, { visible: ctx.visible }),
|
|
25
|
-
"data-hovercardcontent": ""
|
|
26
|
-
});
|
|
27
|
-
onMount(async () => {
|
|
28
|
-
if (!ctx)
|
|
29
|
-
log.error("<HoverCardContent> Must be a direct child of <HoverCard />");
|
|
30
|
-
});
|
|
31
|
-
$effect(() => {
|
|
32
|
-
if (ctx.visible && self)
|
|
33
|
-
ctx.content = self;
|
|
34
|
-
});
|
|
18
|
+
const state = $derived({ visible: ctx.visible });
|
|
35
19
|
const handleMouseenter = (e) => {
|
|
36
20
|
onMouseenter?.(e);
|
|
37
21
|
ctx.hovered = true;
|
|
@@ -44,50 +28,23 @@ const handleMouseleave = (e) => {
|
|
|
44
28
|
};
|
|
45
29
|
</script>
|
|
46
30
|
|
|
47
|
-
|
|
48
|
-
{
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
{...attrs}
|
|
68
|
-
{...props}
|
|
69
|
-
>
|
|
70
|
-
{@render children({ visible: ctx.visible })}
|
|
71
|
-
</div>
|
|
72
|
-
{:else if ctx.visible}
|
|
73
|
-
<div
|
|
74
|
-
bind:this={self}
|
|
75
|
-
use:useFloating={{ anchor: ctx.trigger, arrow: ctx.arrow, sameWidth, constrainViewport, placement }}
|
|
76
|
-
use:useOutside={{
|
|
77
|
-
exclude: ctx.trigger,
|
|
78
|
-
callback: () => {
|
|
79
|
-
ctx.visible = false;
|
|
80
|
-
}
|
|
81
|
-
}}
|
|
82
|
-
use:usePortal={portalTarget}
|
|
83
|
-
use:useActions={use}
|
|
84
|
-
onmouseenter={handleMouseenter}
|
|
85
|
-
onmouseleave={handleMouseleave}
|
|
86
|
-
role="menu"
|
|
87
|
-
tabindex={-1}
|
|
88
|
-
{...attrs}
|
|
89
|
-
{...props}
|
|
90
|
-
>
|
|
91
|
-
{@render children({ visible: ctx.visible })}
|
|
92
|
-
</div>
|
|
93
|
-
{/if}
|
|
31
|
+
<FloatingContent
|
|
32
|
+
{children}
|
|
33
|
+
componentName="Hovercard"
|
|
34
|
+
visible={ctx.visible}
|
|
35
|
+
bind:self
|
|
36
|
+
bind:sameWidth
|
|
37
|
+
bind:transition
|
|
38
|
+
bind:constrainViewport
|
|
39
|
+
bind:placement
|
|
40
|
+
bind:portalTarget
|
|
41
|
+
{state}
|
|
42
|
+
{ctx}
|
|
43
|
+
{use}
|
|
44
|
+
outsideCallback={() => ctx.forceClose()}
|
|
45
|
+
role="listbox"
|
|
46
|
+
class={classProp(klass, state)}
|
|
47
|
+
onmouseenter={handleMouseenter}
|
|
48
|
+
onmouseleave={handleMouseleave}
|
|
49
|
+
{...props}
|
|
50
|
+
/>
|
|
@@ -27,6 +27,10 @@ export class HovercardContext extends FloatingContext {
|
|
|
27
27
|
this.visible = false;
|
|
28
28
|
}, this.delays.out);
|
|
29
29
|
}
|
|
30
|
+
forceClose() {
|
|
31
|
+
this.visible = false;
|
|
32
|
+
this.timeout = null;
|
|
33
|
+
}
|
|
30
34
|
#effects = effects(() => {
|
|
31
35
|
this.hooks?.onChange?.(this.visible);
|
|
32
36
|
});
|
|
@@ -1,64 +1,35 @@
|
|
|
1
1
|
<script lang="ts">import { context } from "./Menu.svelte";
|
|
2
|
-
import {
|
|
3
|
-
import { useOutside, usePortal } from "../../index.js";
|
|
4
|
-
import { onMount } from "svelte";
|
|
2
|
+
import { FloatingContent } from "../../internal/index.js";
|
|
5
3
|
let {
|
|
6
4
|
children,
|
|
7
5
|
transition,
|
|
8
6
|
use = [],
|
|
9
7
|
portalTarget = "body",
|
|
8
|
+
sameWidth = false,
|
|
10
9
|
class: klass,
|
|
11
10
|
self = $bindable(),
|
|
12
11
|
placement = "bottom",
|
|
13
|
-
constrainViewport,
|
|
14
|
-
sameWidth = false,
|
|
12
|
+
constrainViewport = false,
|
|
15
13
|
...props
|
|
16
14
|
} = $props();
|
|
17
15
|
const ctx = context();
|
|
18
|
-
const {
|
|
19
|
-
const attrs = $derived({
|
|
20
|
-
id: ctx.uid("content"),
|
|
21
|
-
"aria-labelledby": ctx.uid("trigger"),
|
|
22
|
-
role: "menu",
|
|
23
|
-
class: classProp(klass, { visible: ctx.visible }),
|
|
24
|
-
"data-menucontent": ""
|
|
25
|
-
});
|
|
26
|
-
onMount(async () => {
|
|
27
|
-
if (!ctx)
|
|
28
|
-
log.error("<MenuContent> Must be a direct child of <Menu />");
|
|
29
|
-
});
|
|
30
|
-
$effect(() => {
|
|
31
|
-
if (ctx.visible && self)
|
|
32
|
-
ctx.content = self;
|
|
33
|
-
});
|
|
16
|
+
const state = $derived({ visible: ctx.visible });
|
|
34
17
|
</script>
|
|
35
18
|
|
|
36
|
-
|
|
37
|
-
{
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
<div
|
|
54
|
-
bind:this={self}
|
|
55
|
-
use:useFloating={{ anchor: ctx.trigger, arrow: ctx.arrow, sameWidth, constrainViewport, placement }}
|
|
56
|
-
use:useOutside={{ exclude: ctx.trigger, callback: () => ctx.close() }}
|
|
57
|
-
use:usePortal={portalTarget}
|
|
58
|
-
use:useActions={use}
|
|
59
|
-
{...attrs}
|
|
60
|
-
{...props}
|
|
61
|
-
>
|
|
62
|
-
{@render children({ visible: ctx.visible })}
|
|
63
|
-
</div>
|
|
64
|
-
{/if}
|
|
19
|
+
<FloatingContent
|
|
20
|
+
{children}
|
|
21
|
+
componentName="Menu"
|
|
22
|
+
visible={ctx.visible}
|
|
23
|
+
{state}
|
|
24
|
+
{ctx}
|
|
25
|
+
{transition}
|
|
26
|
+
{use}
|
|
27
|
+
{sameWidth}
|
|
28
|
+
{constrainViewport}
|
|
29
|
+
{placement}
|
|
30
|
+
{portalTarget}
|
|
31
|
+
outsideCallback={() => ctx.close()}
|
|
32
|
+
role="listbox"
|
|
33
|
+
class={klass}
|
|
34
|
+
{...props}
|
|
35
|
+
/>
|
|
@@ -1,86 +1,47 @@
|
|
|
1
1
|
<script lang="ts">import { context } from "./Popover.svelte";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { onMount } from "svelte";
|
|
2
|
+
import { FloatingContent } from "../../internal/index.js";
|
|
3
|
+
import { useTrap } from "../../index.js";
|
|
5
4
|
let {
|
|
6
5
|
children,
|
|
7
6
|
transition,
|
|
8
7
|
use = [],
|
|
9
8
|
portalTarget = "body",
|
|
9
|
+
sameWidth = false,
|
|
10
10
|
class: klass,
|
|
11
11
|
self = $bindable(),
|
|
12
12
|
placement = "bottom",
|
|
13
|
-
constrainViewport,
|
|
14
|
-
sameWidth = false,
|
|
13
|
+
constrainViewport = false,
|
|
15
14
|
...props
|
|
16
15
|
} = $props();
|
|
17
16
|
const ctx = context();
|
|
18
|
-
const {
|
|
19
|
-
const attrs = $derived({
|
|
20
|
-
id: ctx.uid("content"),
|
|
21
|
-
"aria-labelledby": ctx.uid("trigger"),
|
|
22
|
-
role: "menu",
|
|
23
|
-
class: classProp(klass, { visible: ctx.visible }),
|
|
24
|
-
"data-popovercontent": ""
|
|
25
|
-
});
|
|
26
|
-
onMount(async () => {
|
|
27
|
-
if (!ctx)
|
|
28
|
-
log.error("<PopoverContent> Must be a direct child of <Popover />");
|
|
29
|
-
});
|
|
30
|
-
$effect(() => {
|
|
31
|
-
if (ctx.visible && self)
|
|
32
|
-
ctx.content = self;
|
|
33
|
-
});
|
|
17
|
+
const state = $derived({ visible: ctx.visible });
|
|
34
18
|
</script>
|
|
35
19
|
|
|
36
|
-
|
|
37
|
-
{
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
allowOutsideClick: true,
|
|
52
|
-
onDeactivate: () => {
|
|
53
|
-
ctx.visible = false;
|
|
54
|
-
}
|
|
55
|
-
}}
|
|
56
|
-
in:inFn={inConf}
|
|
57
|
-
out:outFn={outConf}
|
|
58
|
-
{...attrs}
|
|
59
|
-
{...props}
|
|
60
|
-
>
|
|
61
|
-
{@render children({ visible: ctx.visible })}
|
|
62
|
-
</div>
|
|
63
|
-
{:else if ctx.visible}
|
|
64
|
-
<div
|
|
65
|
-
bind:this={self}
|
|
66
|
-
use:useFloating={{ anchor: ctx.trigger, arrow: ctx.arrow, sameWidth, constrainViewport, placement }}
|
|
67
|
-
use:useOutside={{
|
|
68
|
-
exclude: ctx.trigger,
|
|
69
|
-
callback: () => {
|
|
70
|
-
ctx.close();
|
|
71
|
-
}
|
|
72
|
-
}}
|
|
73
|
-
use:usePortal={portalTarget}
|
|
74
|
-
use:useActions={use}
|
|
75
|
-
use:useTrap={{
|
|
76
|
-
allowOutsideClick: true,
|
|
77
|
-
onDeactivate: () => {
|
|
78
|
-
ctx.visible = false;
|
|
20
|
+
<FloatingContent
|
|
21
|
+
{children}
|
|
22
|
+
componentName="Popover"
|
|
23
|
+
visible={ctx.visible}
|
|
24
|
+
{state}
|
|
25
|
+
{ctx}
|
|
26
|
+
{transition}
|
|
27
|
+
use={[
|
|
28
|
+
[
|
|
29
|
+
useTrap,
|
|
30
|
+
{
|
|
31
|
+
allowOutsideClick: true,
|
|
32
|
+
onDeactivate: () => {
|
|
33
|
+
ctx.visible = false;
|
|
34
|
+
}
|
|
79
35
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
{
|
|
36
|
+
],
|
|
37
|
+
...use
|
|
38
|
+
]}
|
|
39
|
+
{sameWidth}
|
|
40
|
+
{constrainViewport}
|
|
41
|
+
{placement}
|
|
42
|
+
{portalTarget}
|
|
43
|
+
outsideCallback={() => ctx.close()}
|
|
44
|
+
role="listbox"
|
|
45
|
+
class={klass}
|
|
46
|
+
{...props}
|
|
47
|
+
/>
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
<script lang="ts">import { context } from "./Select.svelte";
|
|
2
|
-
import {
|
|
3
|
-
import { useOutside, usePortal } from "../../index.js";
|
|
4
|
-
import { onMount } from "svelte";
|
|
2
|
+
import { FloatingContent } from "../../internal/index.js";
|
|
5
3
|
let {
|
|
6
4
|
children,
|
|
7
5
|
transition,
|
|
@@ -15,51 +13,24 @@ let {
|
|
|
15
13
|
...props
|
|
16
14
|
} = $props();
|
|
17
15
|
const ctx = context();
|
|
18
|
-
const {
|
|
19
|
-
const attrs = $derived({
|
|
20
|
-
id: ctx.uid("content"),
|
|
21
|
-
"aria-labelledby": ctx.uid("trigger"),
|
|
22
|
-
role: "listbox",
|
|
23
|
-
class: classProp(klass, { visible: ctx.visible }),
|
|
24
|
-
"data-selectcontent": "",
|
|
25
|
-
hidden: !ctx.mounted || void 0
|
|
26
|
-
});
|
|
27
|
-
onMount(() => {
|
|
28
|
-
if (!ctx)
|
|
29
|
-
log.error("<SelectContent> Must be a direct child of <Select />");
|
|
30
|
-
});
|
|
31
|
-
$effect(() => {
|
|
32
|
-
if (ctx.visible && self)
|
|
33
|
-
ctx.content = self;
|
|
34
|
-
});
|
|
16
|
+
const state = $derived({ visible: ctx.visible });
|
|
35
17
|
</script>
|
|
36
18
|
|
|
37
|
-
|
|
38
|
-
{
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
{
|
|
54
|
-
|
|
55
|
-
bind:this={self}
|
|
56
|
-
use:useFloating={{ anchor: ctx.trigger, arrow: ctx.arrow, sameWidth, constrainViewport, placement }}
|
|
57
|
-
use:useOutside={{ exclude: ctx.content, callback: () => ctx.close() }}
|
|
58
|
-
use:usePortal={portalTarget}
|
|
59
|
-
use:useActions={use}
|
|
60
|
-
{...attrs}
|
|
61
|
-
{...props}
|
|
62
|
-
>
|
|
63
|
-
{@render children({ visible: ctx.visible })}
|
|
64
|
-
</div>
|
|
65
|
-
{/if}
|
|
19
|
+
<FloatingContent
|
|
20
|
+
{children}
|
|
21
|
+
componentName="Select"
|
|
22
|
+
visible={ctx.visible}
|
|
23
|
+
{state}
|
|
24
|
+
{ctx}
|
|
25
|
+
{transition}
|
|
26
|
+
{use}
|
|
27
|
+
{sameWidth}
|
|
28
|
+
{constrainViewport}
|
|
29
|
+
{placement}
|
|
30
|
+
{portalTarget}
|
|
31
|
+
outsideCallback={() => ctx.close()}
|
|
32
|
+
role="listbox"
|
|
33
|
+
class={klass}
|
|
34
|
+
hidden={!ctx.mounted || undefined}
|
|
35
|
+
{...props}
|
|
36
|
+
/>
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
<script lang="ts" context="module">import { setupContext } from "../../internal/index.js";
|
|
2
2
|
import { ToastContext } from "./context.svelte.js";
|
|
3
3
|
export const { context, contextName } = setupContext();
|
|
4
|
-
</script>
|
|
5
|
-
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
6
|
<script lang="ts">import { useActions, classProp } from "../../internal/index.js";
|
|
7
7
|
import { setContext } from "svelte";
|
|
8
8
|
let { children, use = [], class: klass, self = $bindable(), ...props } = $props();
|
|
9
9
|
const ctx = new ToastContext();
|
|
10
10
|
setContext(contextName, ctx);
|
|
11
|
-
</script>
|
|
12
|
-
|
|
13
|
-
<div
|
|
14
|
-
bind:this={self}
|
|
15
|
-
use:useActions={use}
|
|
16
|
-
class={classProp(klass)}
|
|
17
|
-
role="alert"
|
|
18
|
-
aria-labelledby={ctx.uid('title')}
|
|
19
|
-
aria-describedby={ctx.uid('description')}
|
|
20
|
-
aria-live="assertive"
|
|
21
|
-
tabindex="-1"
|
|
22
|
-
data-toast=""
|
|
23
|
-
{...props}
|
|
24
|
-
>
|
|
25
|
-
{@render children({})}
|
|
26
|
-
</div>
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<div
|
|
14
|
+
bind:this={self}
|
|
15
|
+
use:useActions={use}
|
|
16
|
+
class={classProp(klass)}
|
|
17
|
+
role="alert"
|
|
18
|
+
aria-labelledby={ctx.uid('title')}
|
|
19
|
+
aria-describedby={ctx.uid('description')}
|
|
20
|
+
aria-live="assertive"
|
|
21
|
+
tabindex="-1"
|
|
22
|
+
data-toast=""
|
|
23
|
+
{...props}
|
|
24
|
+
>
|
|
25
|
+
{@render children({})}
|
|
26
|
+
</div>
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
import { context } from "./Toast.svelte";
|
|
3
3
|
let { children, use = [], class: klass, self = $bindable(), ...props } = $props();
|
|
4
4
|
const ctx = context();
|
|
5
|
-
</script>
|
|
6
|
-
|
|
7
|
-
<p
|
|
8
|
-
bind:this={self}
|
|
9
|
-
use:useActions={use}
|
|
10
|
-
id={ctx.uid('description')}
|
|
11
|
-
class={classProp(klass)}
|
|
12
|
-
data-toastdescription=""
|
|
13
|
-
{...props}
|
|
14
|
-
>
|
|
15
|
-
{@render children({})}
|
|
16
|
-
</p>
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<p
|
|
8
|
+
bind:this={self}
|
|
9
|
+
use:useActions={use}
|
|
10
|
+
id={ctx.uid('description')}
|
|
11
|
+
class={classProp(klass)}
|
|
12
|
+
data-toastdescription=""
|
|
13
|
+
{...props}
|
|
14
|
+
>
|
|
15
|
+
{@render children({})}
|
|
16
|
+
</p>
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { context } from "./Toast.svelte";
|
|
3
3
|
let { children, use = [], class: klass, self = $bindable(), ...props } = $props();
|
|
4
4
|
const ctx = context();
|
|
5
|
-
</script>
|
|
6
|
-
|
|
7
|
-
<h3 bind:this={self} use:useActions={use} id={ctx.uid('title')} class={classProp(klass)} data-toasttitle="" {...props}>
|
|
8
|
-
{@render children({})}
|
|
9
|
-
</h3>
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<h3 bind:this={self} use:useActions={use} id={ctx.uid('title')} class={classProp(klass)} data-toasttitle="" {...props}>
|
|
8
|
+
{@render children({})}
|
|
9
|
+
</h3>
|
|
@@ -9,15 +9,15 @@ let {
|
|
|
9
9
|
portalTarget = "body",
|
|
10
10
|
...props
|
|
11
11
|
} = $props();
|
|
12
|
-
</script>
|
|
13
|
-
|
|
14
|
-
<div
|
|
15
|
-
bind:this={self}
|
|
16
|
-
use:useActions={use}
|
|
17
|
-
use:usePortal={portalTarget}
|
|
18
|
-
class={classProp(klass)}
|
|
19
|
-
data-toaster=""
|
|
20
|
-
{...props}
|
|
21
|
-
>
|
|
22
|
-
{@render children(toasts)}
|
|
23
|
-
</div>
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<div
|
|
15
|
+
bind:this={self}
|
|
16
|
+
use:useActions={use}
|
|
17
|
+
use:usePortal={portalTarget}
|
|
18
|
+
class={classProp(klass)}
|
|
19
|
+
data-toaster=""
|
|
20
|
+
{...props}
|
|
21
|
+
>
|
|
22
|
+
{@render children(toasts)}
|
|
23
|
+
</div>
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
<script lang="ts">import {
|
|
2
|
+
useActions,
|
|
3
|
+
classProp,
|
|
4
|
+
log,
|
|
5
|
+
FloatingContext,
|
|
6
|
+
useFloating,
|
|
7
|
+
getTransition
|
|
8
|
+
} from "../index.js";
|
|
9
|
+
import { useOutside } from "../../actions/outside.js";
|
|
10
|
+
import { usePortal } from "../../actions/portal.js";
|
|
11
|
+
let {
|
|
12
|
+
children,
|
|
13
|
+
class: klass,
|
|
14
|
+
use = [],
|
|
15
|
+
visible = $bindable(),
|
|
16
|
+
self = $bindable(),
|
|
17
|
+
state = $bindable(),
|
|
18
|
+
transition = $bindable(),
|
|
19
|
+
sameWidth = $bindable(),
|
|
20
|
+
constrainViewport = $bindable(),
|
|
21
|
+
portalTarget = $bindable(),
|
|
22
|
+
placement = $bindable(),
|
|
23
|
+
outsideCallback,
|
|
24
|
+
ctx,
|
|
25
|
+
componentName,
|
|
26
|
+
...props
|
|
27
|
+
} = $props();
|
|
28
|
+
const attrs = $derived({
|
|
29
|
+
[`data-${componentName.toLowerCase()}content`]: "",
|
|
30
|
+
id: ctx.uid("content"),
|
|
31
|
+
"aria-labelledby": ctx.uid("trigger"),
|
|
32
|
+
class: classProp(klass, state)
|
|
33
|
+
});
|
|
34
|
+
const { inTransition, outTransition } = getTransition(transition);
|
|
35
|
+
$effect(() => {
|
|
36
|
+
if (!visible)
|
|
37
|
+
return;
|
|
38
|
+
if (!ctx)
|
|
39
|
+
throw log.error(`<${componentName}Content /> must be a child of <${componentName} />`);
|
|
40
|
+
if (!self)
|
|
41
|
+
throw log.error(`Cannot initialize content node of <${componentName}Content />.`);
|
|
42
|
+
ctx.content = self;
|
|
43
|
+
});
|
|
44
|
+
</script>
|
|
45
|
+
|
|
46
|
+
{#if inTransition && outTransition && visible}
|
|
47
|
+
{@const { config: inConf, transition: inFn } = inTransition}
|
|
48
|
+
{@const { config: outConf, transition: outFn } = outTransition}
|
|
49
|
+
<div
|
|
50
|
+
bind:this={self}
|
|
51
|
+
use:useFloating={{ anchor: ctx.trigger, arrow: ctx.arrow, sameWidth, constrainViewport, placement }}
|
|
52
|
+
use:useOutside={{ exclude: ctx.trigger, callback: () => outsideCallback() }}
|
|
53
|
+
use:usePortal={portalTarget}
|
|
54
|
+
use:useActions={use}
|
|
55
|
+
in:inFn={inConf}
|
|
56
|
+
out:outFn={outConf}
|
|
57
|
+
{...attrs}
|
|
58
|
+
{...props}
|
|
59
|
+
>
|
|
60
|
+
{@render children({ visible: visible })}
|
|
61
|
+
</div>
|
|
62
|
+
{:else if visible}
|
|
63
|
+
<div
|
|
64
|
+
bind:this={self}
|
|
65
|
+
use:useFloating={{ anchor: ctx.trigger, arrow: ctx.arrow, sameWidth, constrainViewport, placement }}
|
|
66
|
+
use:useOutside={{ exclude: ctx.trigger, callback: () => outsideCallback() }}
|
|
67
|
+
use:usePortal={portalTarget}
|
|
68
|
+
use:useActions={use}
|
|
69
|
+
{...attrs}
|
|
70
|
+
{...props}
|
|
71
|
+
>
|
|
72
|
+
{@render children({ visible: visible })}
|
|
73
|
+
</div>
|
|
74
|
+
{/if}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import { FloatingContext, type Props, type ContentProps } from '../index.js';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: Props<HTMLDivElement, any> & ContentProps & {
|
|
5
|
+
componentName: string;
|
|
6
|
+
ctx: FloatingContext;
|
|
7
|
+
state?: Record<string, any> | undefined;
|
|
8
|
+
visible: boolean;
|
|
9
|
+
outsideCallback: () => void;
|
|
10
|
+
};
|
|
11
|
+
events: {
|
|
12
|
+
[evt: string]: CustomEvent<any>;
|
|
13
|
+
};
|
|
14
|
+
slots: {};
|
|
15
|
+
};
|
|
16
|
+
export type FloatingContentProps = typeof __propDef.props;
|
|
17
|
+
export type FloatingContentEvents = typeof __propDef.events;
|
|
18
|
+
export type FloatingContentSlots = typeof __propDef.slots;
|
|
19
|
+
export default class FloatingContent extends SvelteComponent<FloatingContentProps, FloatingContentEvents, FloatingContentSlots> {
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -40,18 +40,16 @@ export const setupContext = () => {
|
|
|
40
40
|
*/
|
|
41
41
|
export const effects = (fn) => {
|
|
42
42
|
let cleanUp = null;
|
|
43
|
-
let mounted = false;
|
|
44
43
|
const destroy = () => {
|
|
45
44
|
if (cleanUp === null)
|
|
46
45
|
return;
|
|
47
46
|
cleanUp();
|
|
48
47
|
cleanUp = null;
|
|
49
48
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
$effect.root(fn);
|
|
49
|
+
try {
|
|
50
|
+
cleanUp = $effect.root(fn);
|
|
51
|
+
}
|
|
52
|
+
catch (error) { }
|
|
55
53
|
onDestroy(destroy);
|
|
56
54
|
return destroy;
|
|
57
55
|
};
|
|
@@ -7,7 +7,7 @@ interface FloatingConfig {
|
|
|
7
7
|
constrainViewport?: boolean;
|
|
8
8
|
sameWidth?: boolean;
|
|
9
9
|
}
|
|
10
|
-
export declare const useFloating: (
|
|
10
|
+
export declare const useFloating: (node: HTMLElement, config: FloatingConfig) => {
|
|
11
11
|
destroy(): void;
|
|
12
12
|
} | undefined;
|
|
13
13
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { computePosition, flip, shift, autoUpdate, size, arrow as floatingArrow } from '@floating-ui/dom';
|
|
2
2
|
import { defaultConfig, setNodeStyles, setNodeProps } from '../index.js';
|
|
3
|
-
export const useFloating = (
|
|
3
|
+
export const useFloating = (node, config) => {
|
|
4
4
|
const { anchor, arrow, placement, constrainViewport, sameWidth } = defaultConfig(config, {
|
|
5
5
|
anchor: null,
|
|
6
6
|
arrow: null,
|
|
@@ -11,8 +11,8 @@ export const useFloating = (target, config) => {
|
|
|
11
11
|
if (!anchor)
|
|
12
12
|
return;
|
|
13
13
|
let cleanUp = null;
|
|
14
|
-
cleanUp = autoUpdate(anchor,
|
|
15
|
-
computePosition(anchor,
|
|
14
|
+
cleanUp = autoUpdate(anchor, node, () => {
|
|
15
|
+
computePosition(anchor, node, {
|
|
16
16
|
placement,
|
|
17
17
|
middleware: [
|
|
18
18
|
arrow ? floatingArrow({ element: arrow }) : undefined,
|
|
@@ -25,7 +25,7 @@ export const useFloating = (target, config) => {
|
|
|
25
25
|
if (sameWidth)
|
|
26
26
|
elements.floating.style.width = elements.reference.getBoundingClientRect().width + 'px';
|
|
27
27
|
if (constrainViewport) {
|
|
28
|
-
setNodeStyles(
|
|
28
|
+
setNodeStyles(node, {
|
|
29
29
|
maxWidth: `${availableWidth}px`,
|
|
30
30
|
maxHeight: `${availableHeight}px`
|
|
31
31
|
});
|
|
@@ -35,12 +35,12 @@ export const useFloating = (target, config) => {
|
|
|
35
35
|
]
|
|
36
36
|
}).then(({ x, y, placement, middlewareData }) => {
|
|
37
37
|
const [side, alignment] = placement.split('-');
|
|
38
|
-
setNodeStyles(
|
|
38
|
+
setNodeStyles(node, {
|
|
39
39
|
left: `${x}px`,
|
|
40
40
|
top: `${y}px`,
|
|
41
41
|
position: 'absolute'
|
|
42
42
|
});
|
|
43
|
-
setNodeProps(
|
|
43
|
+
setNodeProps(node, {
|
|
44
44
|
'data-side': side,
|
|
45
45
|
'data-alignment': alignment || 'center'
|
|
46
46
|
});
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -9,3 +9,4 @@ export * from './helpers/floating.js';
|
|
|
9
9
|
export * from './helpers/log.js';
|
|
10
10
|
export * from './helpers/context.svelte.js';
|
|
11
11
|
export { default as FloatingArrow } from './components/FloatingArrow.svelte';
|
|
12
|
+
export { default as FloatingContent } from './components/FloatingContent.svelte';
|
package/dist/internal/index.js
CHANGED
|
@@ -9,3 +9,4 @@ export * from './helpers/floating.js';
|
|
|
9
9
|
export * from './helpers/log.js';
|
|
10
10
|
export * from './helpers/context.svelte.js';
|
|
11
11
|
export { default as FloatingArrow } from './components/FloatingArrow.svelte';
|
|
12
|
+
export { default as FloatingContent } from './components/FloatingContent.svelte';
|