bits-ui 1.0.0-next.32 → 1.0.0-next.34
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/bits/context-menu/components/context-menu-content-static.svelte +77 -27
- package/dist/bits/context-menu/components/context-menu-content-static.svelte.d.ts +2 -2
- package/dist/bits/context-menu/components/context-menu-content.svelte +70 -31
- package/dist/bits/dropdown-menu/components/dropdown-menu-content-static.svelte +64 -26
- package/dist/bits/dropdown-menu/components/dropdown-menu-content-static.svelte.d.ts +2 -2
- package/dist/bits/dropdown-menu/components/dropdown-menu-content.svelte +59 -25
- package/dist/bits/link-preview/components/link-preview-content-static.svelte +90 -31
- package/dist/bits/link-preview/components/link-preview-content-static.svelte.d.ts +2 -2
- package/dist/bits/link-preview/components/link-preview-content.svelte +65 -30
- package/dist/bits/menu/components/menu-content-static.svelte +70 -30
- package/dist/bits/menu/components/menu-content-static.svelte.d.ts +2 -2
- package/dist/bits/menu/components/menu-content.svelte +65 -28
- package/dist/bits/menu/components/menu-sub-content-static.svelte +83 -46
- package/dist/bits/menu/components/menu-sub-content.svelte +76 -43
- package/dist/bits/popover/components/popover-content-static.svelte +70 -31
- package/dist/bits/popover/components/popover-content-static.svelte.d.ts +2 -2
- package/dist/bits/popover/components/popover-content.svelte +64 -29
- package/dist/bits/popover/popover.svelte.d.ts +3 -0
- package/dist/bits/popover/popover.svelte.js +3 -0
- package/dist/bits/select/components/select-content-static.svelte +68 -33
- package/dist/bits/select/components/select-content-static.svelte.d.ts +2 -2
- package/dist/bits/select/components/select-content.svelte +63 -38
- package/dist/bits/select/select.svelte.d.ts +4 -0
- package/dist/bits/select/select.svelte.js +1 -0
- package/dist/bits/tooltip/components/tooltip-content-static.svelte +88 -30
- package/dist/bits/tooltip/components/tooltip-content-static.svelte.d.ts +2 -2
- package/dist/bits/tooltip/components/tooltip-content.svelte +63 -28
- package/dist/bits/tooltip/tooltip.svelte.d.ts +8 -4
- package/dist/bits/tooltip/tooltip.svelte.js +4 -0
- package/dist/bits/utilities/focus-scope/focus-scope-stack.svelte.js +1 -1
- package/dist/bits/utilities/focus-scope/focus-scope.svelte +2 -0
- package/dist/bits/utilities/focus-scope/types.d.ts +4 -0
- package/dist/bits/utilities/focus-scope/useFocusScope.svelte.d.ts +5 -1
- package/dist/bits/utilities/focus-scope/useFocusScope.svelte.js +53 -34
- package/dist/bits/utilities/popper-layer/popper-layer-force-mount.svelte +85 -0
- package/dist/bits/utilities/popper-layer/popper-layer-force-mount.svelte.d.ts +21 -0
- package/dist/bits/utilities/popper-layer/popper-layer-inner.svelte +126 -0
- package/dist/bits/utilities/popper-layer/popper-layer-inner.svelte.d.ts +21 -0
- package/dist/bits/utilities/popper-layer/popper-layer.svelte +22 -62
- package/package.json +2 -2
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { box, mergeProps } from "svelte-toolbelt";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ContextMenuContentProps } from "../types.js";
|
|
4
4
|
import { CONTEXT_MENU_TRIGGER_ATTR, useMenuContent } from "../../menu/menu.svelte.js";
|
|
5
5
|
import { useId } from "../../../internal/use-id.js";
|
|
6
6
|
import { noop } from "../../../internal/noop.js";
|
|
7
7
|
import PopperLayer from "../../utilities/popper-layer/popper-layer.svelte";
|
|
8
8
|
import Mounted from "../../utilities/mounted.svelte";
|
|
9
|
+
import { getFloatingContentCSSVars } from "../../../internal/floating-svelte/floating-utils.svelte.js";
|
|
10
|
+
import PopperLayerForceMount from "../../utilities/popper-layer/popper-layer-force-mount.svelte";
|
|
9
11
|
|
|
10
12
|
let {
|
|
11
13
|
id = useId(),
|
|
@@ -20,7 +22,7 @@
|
|
|
20
22
|
onEscapeKeydown = noop,
|
|
21
23
|
forceMount = false,
|
|
22
24
|
...restProps
|
|
23
|
-
}:
|
|
25
|
+
}: ContextMenuContentProps = $props();
|
|
24
26
|
|
|
25
27
|
let isMounted = $state(false);
|
|
26
28
|
|
|
@@ -35,24 +37,20 @@
|
|
|
35
37
|
});
|
|
36
38
|
|
|
37
39
|
const mergedProps = $derived(mergeProps(restProps, contentState.props));
|
|
38
|
-
</script>
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
isStatic={true}
|
|
42
|
-
{...mergedProps}
|
|
43
|
-
present={contentState.parentMenu.open.current || forceMount}
|
|
44
|
-
{preventScroll}
|
|
45
|
-
onInteractOutside={(e) => {
|
|
41
|
+
function handleInteractOutside(e: PointerEvent) {
|
|
46
42
|
onInteractOutside(e);
|
|
47
43
|
if (e.defaultPrevented) return;
|
|
48
44
|
contentState.parentMenu.onClose();
|
|
49
|
-
}
|
|
50
|
-
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function handleEscapeKeydown(e: KeyboardEvent) {
|
|
51
48
|
onEscapeKeydown(e);
|
|
52
49
|
if (e.defaultPrevented) return;
|
|
53
50
|
contentState.parentMenu.onClose();
|
|
54
|
-
}
|
|
55
|
-
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function isValidEvent(e: PointerEvent) {
|
|
56
54
|
if ("button" in e && e.button === 2) {
|
|
57
55
|
const target = e.target as HTMLElement;
|
|
58
56
|
if (!target) return false;
|
|
@@ -62,17 +60,69 @@
|
|
|
62
60
|
return isAnotherContextTrigger;
|
|
63
61
|
}
|
|
64
62
|
return false;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
{
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
63
|
+
}
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
{#if forceMount}
|
|
67
|
+
<PopperLayerForceMount
|
|
68
|
+
{...mergedProps}
|
|
69
|
+
isStatic
|
|
70
|
+
side="right"
|
|
71
|
+
sideOffset={2}
|
|
72
|
+
align="start"
|
|
73
|
+
enabled={contentState.parentMenu.open.current}
|
|
74
|
+
{preventScroll}
|
|
75
|
+
onInteractOutside={handleInteractOutside}
|
|
76
|
+
onEscapeKeydown={handleEscapeKeydown}
|
|
77
|
+
{isValidEvent}
|
|
78
|
+
trapFocus
|
|
79
|
+
{loop}
|
|
80
|
+
{forceMount}
|
|
81
|
+
{id}
|
|
82
|
+
>
|
|
83
|
+
{#snippet popper({ props })}
|
|
84
|
+
{@const finalProps = mergeProps(props, {
|
|
85
|
+
style: getFloatingContentCSSVars("context-menu"),
|
|
86
|
+
})}
|
|
87
|
+
{#if child}
|
|
88
|
+
{@render child({ props: finalProps, ...contentState.snippetProps })}
|
|
89
|
+
{:else}
|
|
90
|
+
<div {...finalProps}>
|
|
91
|
+
{@render children?.()}
|
|
92
|
+
</div>
|
|
93
|
+
{/if}
|
|
94
|
+
<Mounted bind:isMounted />
|
|
95
|
+
{/snippet}
|
|
96
|
+
</PopperLayerForceMount>
|
|
97
|
+
{:else if !forceMount}
|
|
98
|
+
<PopperLayer
|
|
99
|
+
{...mergedProps}
|
|
100
|
+
isStatic
|
|
101
|
+
side="right"
|
|
102
|
+
sideOffset={2}
|
|
103
|
+
align="start"
|
|
104
|
+
present={contentState.parentMenu.open.current}
|
|
105
|
+
{preventScroll}
|
|
106
|
+
onInteractOutside={handleInteractOutside}
|
|
107
|
+
onEscapeKeydown={handleEscapeKeydown}
|
|
108
|
+
{isValidEvent}
|
|
109
|
+
trapFocus
|
|
110
|
+
{loop}
|
|
111
|
+
forceMount={false}
|
|
112
|
+
{id}
|
|
113
|
+
>
|
|
114
|
+
{#snippet popper({ props })}
|
|
115
|
+
{@const finalProps = mergeProps(props, {
|
|
116
|
+
style: getFloatingContentCSSVars("context-menu"),
|
|
117
|
+
})}
|
|
118
|
+
{#if child}
|
|
119
|
+
{@render child({ props: finalProps, ...contentState.snippetProps })}
|
|
120
|
+
{:else}
|
|
121
|
+
<div {...finalProps}>
|
|
122
|
+
{@render children?.()}
|
|
123
|
+
</div>
|
|
124
|
+
{/if}
|
|
125
|
+
<Mounted bind:isMounted />
|
|
126
|
+
{/snippet}
|
|
127
|
+
</PopperLayer>
|
|
128
|
+
{/if}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ContextMenuContentProps } from "../types.js";
|
|
2
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
3
|
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
4
|
$$bindings?: Bindings;
|
|
@@ -12,7 +12,7 @@ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> =
|
|
|
12
12
|
};
|
|
13
13
|
z_$$bindings?: Bindings;
|
|
14
14
|
}
|
|
15
|
-
declare const ContextMenuContentStatic: $$__sveltets_2_IsomorphicComponent<
|
|
15
|
+
declare const ContextMenuContentStatic: $$__sveltets_2_IsomorphicComponent<ContextMenuContentProps, {
|
|
16
16
|
[evt: string]: CustomEvent<any>;
|
|
17
17
|
}, {}, {}, "ref">;
|
|
18
18
|
type ContextMenuContentStatic = InstanceType<typeof ContextMenuContentStatic>;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import PopperLayer from "../../utilities/popper-layer/popper-layer.svelte";
|
|
8
8
|
import Mounted from "../../utilities/mounted.svelte";
|
|
9
9
|
import { getFloatingContentCSSVars } from "../../../internal/floating-svelte/floating-utils.svelte.js";
|
|
10
|
+
import PopperLayerForceMount from "../../utilities/popper-layer/popper-layer-force-mount.svelte";
|
|
10
11
|
|
|
11
12
|
let {
|
|
12
13
|
id = useId(),
|
|
@@ -36,26 +37,20 @@
|
|
|
36
37
|
});
|
|
37
38
|
|
|
38
39
|
const mergedProps = $derived(mergeProps(restProps, contentState.props));
|
|
39
|
-
</script>
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
{...mergedProps}
|
|
43
|
-
side="right"
|
|
44
|
-
sideOffset={2}
|
|
45
|
-
align="start"
|
|
46
|
-
present={contentState.parentMenu.open.current || forceMount}
|
|
47
|
-
{preventScroll}
|
|
48
|
-
onInteractOutside={(e) => {
|
|
41
|
+
function handleInteractOutside(e: PointerEvent) {
|
|
49
42
|
onInteractOutside(e);
|
|
50
43
|
if (e.defaultPrevented) return;
|
|
51
44
|
contentState.parentMenu.onClose();
|
|
52
|
-
}
|
|
53
|
-
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function handleEscapeKeydown(e: KeyboardEvent) {
|
|
54
48
|
onEscapeKeydown(e);
|
|
55
49
|
if (e.defaultPrevented) return;
|
|
56
50
|
contentState.parentMenu.onClose();
|
|
57
|
-
}
|
|
58
|
-
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function isValidEvent(e: PointerEvent) {
|
|
59
54
|
if ("button" in e && e.button === 2) {
|
|
60
55
|
const target = e.target as HTMLElement;
|
|
61
56
|
if (!target) return false;
|
|
@@ -65,21 +60,65 @@
|
|
|
65
60
|
return isAnotherContextTrigger;
|
|
66
61
|
}
|
|
67
62
|
return false;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
{
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
{
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
63
|
+
}
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
{#if forceMount}
|
|
67
|
+
<PopperLayerForceMount
|
|
68
|
+
{...mergedProps}
|
|
69
|
+
side="right"
|
|
70
|
+
sideOffset={2}
|
|
71
|
+
align="start"
|
|
72
|
+
enabled={contentState.parentMenu.open.current}
|
|
73
|
+
{preventScroll}
|
|
74
|
+
onInteractOutside={handleInteractOutside}
|
|
75
|
+
onEscapeKeydown={handleEscapeKeydown}
|
|
76
|
+
{isValidEvent}
|
|
77
|
+
trapFocus
|
|
78
|
+
{loop}
|
|
79
|
+
{id}
|
|
80
|
+
>
|
|
81
|
+
{#snippet popper({ props })}
|
|
82
|
+
{@const finalProps = mergeProps(props, {
|
|
83
|
+
style: getFloatingContentCSSVars("context-menu"),
|
|
84
|
+
})}
|
|
85
|
+
{#if child}
|
|
86
|
+
{@render child({ props: finalProps, ...contentState.snippetProps })}
|
|
87
|
+
{:else}
|
|
88
|
+
<div {...finalProps}>
|
|
89
|
+
{@render children?.()}
|
|
90
|
+
</div>
|
|
91
|
+
{/if}
|
|
92
|
+
<Mounted bind:isMounted />
|
|
93
|
+
{/snippet}
|
|
94
|
+
</PopperLayerForceMount>
|
|
95
|
+
{:else if !forceMount}
|
|
96
|
+
<PopperLayer
|
|
97
|
+
{...mergedProps}
|
|
98
|
+
side="right"
|
|
99
|
+
sideOffset={2}
|
|
100
|
+
align="start"
|
|
101
|
+
present={contentState.parentMenu.open.current}
|
|
102
|
+
{preventScroll}
|
|
103
|
+
onInteractOutside={handleInteractOutside}
|
|
104
|
+
onEscapeKeydown={handleEscapeKeydown}
|
|
105
|
+
{isValidEvent}
|
|
106
|
+
trapFocus
|
|
107
|
+
{loop}
|
|
108
|
+
{id}
|
|
109
|
+
>
|
|
110
|
+
{#snippet popper({ props })}
|
|
111
|
+
{@const finalProps = mergeProps(props, {
|
|
112
|
+
style: getFloatingContentCSSVars("context-menu"),
|
|
113
|
+
})}
|
|
114
|
+
{#if child}
|
|
115
|
+
{@render child({ props: finalProps, ...contentState.snippetProps })}
|
|
116
|
+
{:else}
|
|
117
|
+
<div {...finalProps}>
|
|
118
|
+
{@render children?.()}
|
|
119
|
+
</div>
|
|
120
|
+
{/if}
|
|
121
|
+
<Mounted bind:isMounted />
|
|
122
|
+
{/snippet}
|
|
123
|
+
</PopperLayer>
|
|
124
|
+
{/if}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { box, mergeProps } from "svelte-toolbelt";
|
|
3
|
-
import type {
|
|
3
|
+
import type { DropdownMenuContentProps } from "../types.js";
|
|
4
4
|
import { useMenuContent } from "../../menu/menu.svelte.js";
|
|
5
5
|
import { useId } from "../../../internal/use-id.js";
|
|
6
6
|
import { noop } from "../../../internal/noop.js";
|
|
7
7
|
import PopperLayer from "../../utilities/popper-layer/popper-layer.svelte";
|
|
8
8
|
import Mounted from "../../utilities/mounted.svelte";
|
|
9
|
+
import { getFloatingContentCSSVars } from "../../../internal/floating-svelte/floating-utils.svelte.js";
|
|
10
|
+
import PopperLayerForceMount from "../../utilities/popper-layer/popper-layer-force-mount.svelte";
|
|
9
11
|
|
|
10
12
|
let {
|
|
11
13
|
id = useId(),
|
|
@@ -17,7 +19,7 @@
|
|
|
17
19
|
onEscapeKeydown = noop,
|
|
18
20
|
forceMount = false,
|
|
19
21
|
...restProps
|
|
20
|
-
}:
|
|
22
|
+
}: DropdownMenuContentProps = $props();
|
|
21
23
|
|
|
22
24
|
let isMounted = $state(false);
|
|
23
25
|
|
|
@@ -32,35 +34,71 @@
|
|
|
32
34
|
});
|
|
33
35
|
|
|
34
36
|
const mergedProps = $derived(mergeProps(restProps, contentState.props));
|
|
35
|
-
</script>
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
isStatic={true}
|
|
39
|
-
{...mergedProps}
|
|
40
|
-
present={contentState.parentMenu.open.current || forceMount}
|
|
41
|
-
onInteractOutside={(e) => {
|
|
38
|
+
function handleInteractOutside(e: PointerEvent) {
|
|
42
39
|
contentState.handleInteractOutside(e);
|
|
43
40
|
if (e.defaultPrevented) return;
|
|
44
41
|
onInteractOutside(e);
|
|
42
|
+
if (e.defaultPrevented) return;
|
|
45
43
|
contentState.parentMenu.onClose();
|
|
46
|
-
}
|
|
47
|
-
|
|
44
|
+
}
|
|
45
|
+
function handleEscapeKeydown(e: KeyboardEvent) {
|
|
48
46
|
onEscapeKeydown(e);
|
|
49
47
|
if (e.defaultPrevented) return;
|
|
50
48
|
contentState.parentMenu.onClose();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
{
|
|
57
|
-
{
|
|
58
|
-
|
|
59
|
-
{
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
49
|
+
}
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
{#if forceMount}
|
|
53
|
+
<PopperLayerForceMount
|
|
54
|
+
{...mergedProps}
|
|
55
|
+
enabled={contentState.parentMenu.open.current}
|
|
56
|
+
onInteractOutside={handleInteractOutside}
|
|
57
|
+
onEscapeKeydown={handleEscapeKeydown}
|
|
58
|
+
trapFocus
|
|
59
|
+
{loop}
|
|
60
|
+
forceMount={true}
|
|
61
|
+
isStatic
|
|
62
|
+
{id}
|
|
63
|
+
>
|
|
64
|
+
{#snippet popper({ props })}
|
|
65
|
+
{@const finalProps = mergeProps(props, {
|
|
66
|
+
style: getFloatingContentCSSVars("dropdown-menu"),
|
|
67
|
+
})}
|
|
68
|
+
{#if child}
|
|
69
|
+
{@render child({ props: finalProps, ...contentState.snippetProps })}
|
|
70
|
+
{:else}
|
|
71
|
+
<div {...finalProps}>
|
|
72
|
+
{@render children?.()}
|
|
73
|
+
</div>
|
|
74
|
+
{/if}
|
|
75
|
+
<Mounted bind:isMounted />
|
|
76
|
+
{/snippet}
|
|
77
|
+
</PopperLayerForceMount>
|
|
78
|
+
{:else if !forceMount}
|
|
79
|
+
<PopperLayer
|
|
80
|
+
{...mergedProps}
|
|
81
|
+
present={contentState.parentMenu.open.current}
|
|
82
|
+
onInteractOutside={handleInteractOutside}
|
|
83
|
+
onEscapeKeydown={handleEscapeKeydown}
|
|
84
|
+
trapFocus
|
|
85
|
+
{loop}
|
|
86
|
+
forceMount={false}
|
|
87
|
+
isStatic
|
|
88
|
+
{id}
|
|
89
|
+
>
|
|
90
|
+
{#snippet popper({ props })}
|
|
91
|
+
{@const finalProps = mergeProps(props, {
|
|
92
|
+
style: getFloatingContentCSSVars("dropdown-menu"),
|
|
93
|
+
})}
|
|
94
|
+
{#if child}
|
|
95
|
+
{@render child({ props: finalProps, ...contentState.snippetProps })}
|
|
96
|
+
{:else}
|
|
97
|
+
<div {...finalProps}>
|
|
98
|
+
{@render children?.()}
|
|
99
|
+
</div>
|
|
100
|
+
{/if}
|
|
101
|
+
<Mounted bind:isMounted />
|
|
102
|
+
{/snippet}
|
|
103
|
+
</PopperLayer>
|
|
104
|
+
{/if}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DropdownMenuContentProps } from "../types.js";
|
|
2
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
3
|
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
4
|
$$bindings?: Bindings;
|
|
@@ -12,7 +12,7 @@ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> =
|
|
|
12
12
|
};
|
|
13
13
|
z_$$bindings?: Bindings;
|
|
14
14
|
}
|
|
15
|
-
declare const DropdownMenuContentStatic: $$__sveltets_2_IsomorphicComponent<
|
|
15
|
+
declare const DropdownMenuContentStatic: $$__sveltets_2_IsomorphicComponent<DropdownMenuContentProps, {
|
|
16
16
|
[evt: string]: CustomEvent<any>;
|
|
17
17
|
}, {}, {}, "ref">;
|
|
18
18
|
type DropdownMenuContentStatic = InstanceType<typeof DropdownMenuContentStatic>;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import PopperLayer from "../../utilities/popper-layer/popper-layer.svelte";
|
|
8
8
|
import Mounted from "../../utilities/mounted.svelte";
|
|
9
9
|
import { getFloatingContentCSSVars } from "../../../internal/floating-svelte/floating-utils.svelte.js";
|
|
10
|
+
import PopperLayerForceMount from "../../utilities/popper-layer/popper-layer-force-mount.svelte";
|
|
10
11
|
|
|
11
12
|
let {
|
|
12
13
|
id = useId(),
|
|
@@ -33,36 +34,69 @@
|
|
|
33
34
|
});
|
|
34
35
|
|
|
35
36
|
const mergedProps = $derived(mergeProps(restProps, contentState.props));
|
|
36
|
-
</script>
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
{...mergedProps}
|
|
40
|
-
present={contentState.parentMenu.open.current || forceMount}
|
|
41
|
-
onInteractOutside={(e) => {
|
|
38
|
+
function handleInteractOutside(e: PointerEvent) {
|
|
42
39
|
contentState.handleInteractOutside(e);
|
|
43
40
|
if (e.defaultPrevented) return;
|
|
44
41
|
onInteractOutside(e);
|
|
42
|
+
if (e.defaultPrevented) return;
|
|
45
43
|
contentState.parentMenu.onClose();
|
|
46
|
-
}
|
|
47
|
-
|
|
44
|
+
}
|
|
45
|
+
function handleEscapeKeydown(e: KeyboardEvent) {
|
|
48
46
|
onEscapeKeydown(e);
|
|
49
47
|
if (e.defaultPrevented) return;
|
|
50
48
|
contentState.parentMenu.onClose();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
{
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
{
|
|
60
|
-
|
|
61
|
-
{
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
{
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
49
|
+
}
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
{#if forceMount}
|
|
53
|
+
<PopperLayerForceMount
|
|
54
|
+
{...mergedProps}
|
|
55
|
+
enabled={contentState.parentMenu.open.current}
|
|
56
|
+
onInteractOutside={handleInteractOutside}
|
|
57
|
+
onEscapeKeydown={handleEscapeKeydown}
|
|
58
|
+
trapFocus
|
|
59
|
+
{loop}
|
|
60
|
+
forceMount={true}
|
|
61
|
+
{id}
|
|
62
|
+
>
|
|
63
|
+
{#snippet popper({ props })}
|
|
64
|
+
{@const finalProps = mergeProps(props, {
|
|
65
|
+
style: getFloatingContentCSSVars("dropdown-menu"),
|
|
66
|
+
})}
|
|
67
|
+
{#if child}
|
|
68
|
+
{@render child({ props: finalProps, ...contentState.snippetProps })}
|
|
69
|
+
{:else}
|
|
70
|
+
<div {...finalProps}>
|
|
71
|
+
{@render children?.()}
|
|
72
|
+
</div>
|
|
73
|
+
{/if}
|
|
74
|
+
<Mounted bind:isMounted />
|
|
75
|
+
{/snippet}
|
|
76
|
+
</PopperLayerForceMount>
|
|
77
|
+
{:else if !forceMount}
|
|
78
|
+
<PopperLayer
|
|
79
|
+
{...mergedProps}
|
|
80
|
+
present={contentState.parentMenu.open.current}
|
|
81
|
+
onInteractOutside={handleInteractOutside}
|
|
82
|
+
onEscapeKeydown={handleEscapeKeydown}
|
|
83
|
+
trapFocus
|
|
84
|
+
{loop}
|
|
85
|
+
forceMount={false}
|
|
86
|
+
{id}
|
|
87
|
+
>
|
|
88
|
+
{#snippet popper({ props })}
|
|
89
|
+
{@const finalProps = mergeProps(props, {
|
|
90
|
+
style: getFloatingContentCSSVars("dropdown-menu"),
|
|
91
|
+
})}
|
|
92
|
+
{#if child}
|
|
93
|
+
{@render child({ props: finalProps, ...contentState.snippetProps })}
|
|
94
|
+
{:else}
|
|
95
|
+
<div {...finalProps}>
|
|
96
|
+
{@render children?.()}
|
|
97
|
+
</div>
|
|
98
|
+
{/if}
|
|
99
|
+
<Mounted bind:isMounted />
|
|
100
|
+
{/snippet}
|
|
101
|
+
</PopperLayer>
|
|
102
|
+
{/if}
|
|
@@ -1,20 +1,30 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { box, mergeProps } from "svelte-toolbelt";
|
|
3
|
-
import type {
|
|
3
|
+
import type { LinkPreviewContentProps } from "../types.js";
|
|
4
4
|
import { useLinkPreviewContent } from "../link-preview.svelte.js";
|
|
5
5
|
import { useId } from "../../../internal/use-id.js";
|
|
6
6
|
import PopperLayer from "../../utilities/popper-layer/popper-layer.svelte";
|
|
7
|
+
import { getFloatingContentCSSVars } from "../../../internal/floating-svelte/floating-utils.svelte.js";
|
|
8
|
+
import PopperLayerForceMount from "../../utilities/popper-layer/popper-layer-force-mount.svelte";
|
|
7
9
|
|
|
8
10
|
let {
|
|
9
11
|
children,
|
|
10
12
|
child,
|
|
11
13
|
id = useId(),
|
|
12
14
|
ref = $bindable(null),
|
|
15
|
+
side = "top",
|
|
16
|
+
sideOffset = 0,
|
|
17
|
+
align = "center",
|
|
18
|
+
avoidCollisions = true,
|
|
19
|
+
arrowPadding = 0,
|
|
20
|
+
sticky = "partial",
|
|
21
|
+
hideWhenDetached = false,
|
|
22
|
+
collisionPadding = 0,
|
|
13
23
|
onInteractOutside,
|
|
14
24
|
onEscapeKeydown,
|
|
15
25
|
forceMount = false,
|
|
16
26
|
...restProps
|
|
17
|
-
}:
|
|
27
|
+
}: LinkPreviewContentProps = $props();
|
|
18
28
|
|
|
19
29
|
const contentState = useLinkPreviewContent({
|
|
20
30
|
id: box.with(() => id),
|
|
@@ -24,37 +34,86 @@
|
|
|
24
34
|
),
|
|
25
35
|
});
|
|
26
36
|
|
|
27
|
-
const
|
|
28
|
-
|
|
37
|
+
const floatingProps = $derived({
|
|
38
|
+
side,
|
|
39
|
+
sideOffset,
|
|
40
|
+
align,
|
|
41
|
+
avoidCollisions,
|
|
42
|
+
arrowPadding,
|
|
43
|
+
sticky,
|
|
44
|
+
hideWhenDetached,
|
|
45
|
+
collisionPadding,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const mergedProps = $derived(mergeProps(restProps, floatingProps, contentState.props));
|
|
29
49
|
|
|
30
|
-
|
|
31
|
-
isStatic={true}
|
|
32
|
-
{...mergedProps}
|
|
33
|
-
present={contentState.root.open.current || forceMount}
|
|
34
|
-
{id}
|
|
35
|
-
onInteractOutside={(e) => {
|
|
50
|
+
function handleInteractOutside(e: PointerEvent) {
|
|
36
51
|
onInteractOutside?.(e);
|
|
37
52
|
if (e.defaultPrevented) return;
|
|
38
|
-
contentState.root.
|
|
39
|
-
}
|
|
40
|
-
|
|
53
|
+
contentState.root.handleClose();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function handleEscapeKeydown(e: KeyboardEvent) {
|
|
41
57
|
onEscapeKeydown?.(e);
|
|
42
58
|
if (e.defaultPrevented) return;
|
|
43
|
-
contentState.root.
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
{
|
|
53
|
-
|
|
54
|
-
{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
{
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
contentState.root.handleClose();
|
|
60
|
+
}
|
|
61
|
+
</script>
|
|
62
|
+
|
|
63
|
+
{#if forceMount}
|
|
64
|
+
<PopperLayerForceMount
|
|
65
|
+
{...mergedProps}
|
|
66
|
+
enabled={contentState.root.open.current}
|
|
67
|
+
isStatic
|
|
68
|
+
{id}
|
|
69
|
+
onInteractOutside={handleInteractOutside}
|
|
70
|
+
onEscapeKeydown={handleEscapeKeydown}
|
|
71
|
+
onOpenAutoFocus={(e) => e.preventDefault()}
|
|
72
|
+
onCloseAutoFocus={(e) => e.preventDefault()}
|
|
73
|
+
trapFocus={false}
|
|
74
|
+
loop={false}
|
|
75
|
+
preventScroll={false}
|
|
76
|
+
forceMount={true}
|
|
77
|
+
>
|
|
78
|
+
{#snippet popper({ props })}
|
|
79
|
+
{@const mergedProps = mergeProps(props, {
|
|
80
|
+
style: getFloatingContentCSSVars("link-preview"),
|
|
81
|
+
})}
|
|
82
|
+
{#if child}
|
|
83
|
+
{@render child({ props: mergedProps, ...contentState.snippetProps })}
|
|
84
|
+
{:else}
|
|
85
|
+
<div {...mergedProps}>
|
|
86
|
+
{@render children?.()}
|
|
87
|
+
</div>
|
|
88
|
+
{/if}
|
|
89
|
+
{/snippet}
|
|
90
|
+
</PopperLayerForceMount>
|
|
91
|
+
{:else if !forceMount}
|
|
92
|
+
<PopperLayer
|
|
93
|
+
{...mergedProps}
|
|
94
|
+
present={contentState.root.open.current}
|
|
95
|
+
isStatic
|
|
96
|
+
{id}
|
|
97
|
+
onInteractOutside={handleInteractOutside}
|
|
98
|
+
onEscapeKeydown={handleEscapeKeydown}
|
|
99
|
+
onOpenAutoFocus={(e) => e.preventDefault()}
|
|
100
|
+
onCloseAutoFocus={(e) => e.preventDefault()}
|
|
101
|
+
trapFocus={false}
|
|
102
|
+
loop={false}
|
|
103
|
+
preventScroll={false}
|
|
104
|
+
forceMount={false}
|
|
105
|
+
>
|
|
106
|
+
{#snippet popper({ props })}
|
|
107
|
+
{@const mergedProps = mergeProps(props, {
|
|
108
|
+
style: getFloatingContentCSSVars("link-preview"),
|
|
109
|
+
})}
|
|
110
|
+
{#if child}
|
|
111
|
+
{@render child({ props: mergedProps, ...contentState.snippetProps })}
|
|
112
|
+
{:else}
|
|
113
|
+
<div {...mergedProps}>
|
|
114
|
+
{@render children?.()}
|
|
115
|
+
</div>
|
|
116
|
+
{/if}
|
|
117
|
+
{/snippet}
|
|
118
|
+
</PopperLayer>
|
|
119
|
+
{/if}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LinkPreviewContentProps } from "../types.js";
|
|
2
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
3
|
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
4
|
$$bindings?: Bindings;
|
|
@@ -12,7 +12,7 @@ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> =
|
|
|
12
12
|
};
|
|
13
13
|
z_$$bindings?: Bindings;
|
|
14
14
|
}
|
|
15
|
-
declare const LinkPreviewContentStatic: $$__sveltets_2_IsomorphicComponent<
|
|
15
|
+
declare const LinkPreviewContentStatic: $$__sveltets_2_IsomorphicComponent<LinkPreviewContentProps, {
|
|
16
16
|
[evt: string]: CustomEvent<any>;
|
|
17
17
|
}, {}, {}, "ref">;
|
|
18
18
|
type LinkPreviewContentStatic = InstanceType<typeof LinkPreviewContentStatic>;
|