INIT
This commit is contained in:
Generated
Vendored
+120
@@ -0,0 +1,120 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import type { LinkPreviewContentProps } from "../types.js";
|
||||
import { LinkPreviewContentState } from "../link-preview.svelte.js";
|
||||
import PopperLayer from "../../utilities/popper-layer/popper-layer.svelte";
|
||||
import { getFloatingContentCSSVars } from "../../../internal/floating-svelte/floating-utils.svelte.js";
|
||||
import PopperLayerForceMount from "../../utilities/popper-layer/popper-layer-force-mount.svelte";
|
||||
import Mounted from "../../utilities/mounted.svelte";
|
||||
import { noop } from "../../../internal/noop.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
children,
|
||||
child,
|
||||
id = createId(uid),
|
||||
ref = $bindable(null),
|
||||
side = "top",
|
||||
sideOffset = 0,
|
||||
align = "center",
|
||||
avoidCollisions = true,
|
||||
arrowPadding = 0,
|
||||
sticky = "partial",
|
||||
hideWhenDetached = false,
|
||||
collisionPadding = 0,
|
||||
onInteractOutside = noop,
|
||||
onEscapeKeydown = noop,
|
||||
forceMount = false,
|
||||
style,
|
||||
...restProps
|
||||
}: LinkPreviewContentProps = $props();
|
||||
|
||||
const contentState = LinkPreviewContentState.create({
|
||||
id: boxWith(() => id),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
onInteractOutside: boxWith(() => onInteractOutside),
|
||||
onEscapeKeydown: boxWith(() => onEscapeKeydown),
|
||||
});
|
||||
|
||||
const floatingProps = $derived({
|
||||
side,
|
||||
sideOffset,
|
||||
align,
|
||||
avoidCollisions,
|
||||
arrowPadding,
|
||||
sticky,
|
||||
hideWhenDetached,
|
||||
collisionPadding,
|
||||
});
|
||||
|
||||
const mergedProps = $derived(mergeProps(restProps, floatingProps, contentState.props));
|
||||
</script>
|
||||
|
||||
{#if forceMount}
|
||||
<PopperLayerForceMount
|
||||
{...mergedProps}
|
||||
{...contentState.popperProps}
|
||||
ref={contentState.opts.ref}
|
||||
enabled={contentState.root.opts.open.current}
|
||||
{id}
|
||||
trapFocus={false}
|
||||
loop={false}
|
||||
preventScroll={false}
|
||||
forceMount={true}
|
||||
shouldRender={contentState.shouldRender}
|
||||
>
|
||||
{#snippet popper({ props, wrapperProps })}
|
||||
{@const finalProps = mergeProps(
|
||||
props,
|
||||
{ style: getFloatingContentCSSVars("link-preview") },
|
||||
{ style }
|
||||
)}
|
||||
{#if child}
|
||||
{@render child({ props: finalProps, wrapperProps, ...contentState.snippetProps })}
|
||||
{:else}
|
||||
<div {...wrapperProps}>
|
||||
<div {...finalProps}>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<Mounted bind:mounted={contentState.root.contentMounted} />
|
||||
{/snippet}
|
||||
</PopperLayerForceMount>
|
||||
{:else if !forceMount}
|
||||
<PopperLayer
|
||||
{...mergedProps}
|
||||
{...contentState.popperProps}
|
||||
ref={contentState.opts.ref}
|
||||
open={contentState.root.opts.open.current}
|
||||
{id}
|
||||
trapFocus={false}
|
||||
loop={false}
|
||||
preventScroll={false}
|
||||
forceMount={false}
|
||||
shouldRender={contentState.shouldRender}
|
||||
>
|
||||
{#snippet popper({ props, wrapperProps })}
|
||||
{@const finalProps = mergeProps(
|
||||
props,
|
||||
{ style: getFloatingContentCSSVars("link-preview") },
|
||||
{ style }
|
||||
)}
|
||||
{#if child}
|
||||
{@render child({ props: finalProps, wrapperProps, ...contentState.snippetProps })}
|
||||
{:else}
|
||||
<div {...wrapperProps}>
|
||||
<div {...finalProps}>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<Mounted bind:mounted={contentState.root.contentMounted} />
|
||||
{/snippet}
|
||||
</PopperLayer>
|
||||
{/if}
|
||||
Reference in New Issue
Block a user