From bce557cc2dc767628bed6aac87301a1be7c5431b Mon Sep 17 00:00:00 2001
From: rxliuli <rxliuli@gmail.com>
Date: Tue, 4 Nov 2025 05:03:50 +0800
Subject: init commit

---
 .../jet/action/ShelfBasedPageScrollAction.svelte   | 51 ++++++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 src/components/jet/action/ShelfBasedPageScrollAction.svelte

(limited to 'src/components/jet/action/ShelfBasedPageScrollAction.svelte')

diff --git a/src/components/jet/action/ShelfBasedPageScrollAction.svelte b/src/components/jet/action/ShelfBasedPageScrollAction.svelte
new file mode 100644
index 0000000..9c1c13e
--- /dev/null
+++ b/src/components/jet/action/ShelfBasedPageScrollAction.svelte
@@ -0,0 +1,51 @@
+<script lang="ts" context="module">
+    import type {
+        Action,
+        ShelfBasedPageScrollAction,
+    } from '@jet-app/app-store/api/models';
+
+    export function isShelfBasedPageScrollAction(
+        action: Action,
+    ): action is ShelfBasedPageScrollAction {
+        return (
+            action.$kind === 'ShelfBasedPageScrollAction' && 'shelfId' in action
+        );
+    }
+</script>
+
+<script lang="ts">
+    import type { HTMLAnchorAttributes } from 'svelte/elements';
+
+    interface $$Props extends HTMLAnchorAttributes {
+        destination: ShelfBasedPageScrollAction;
+    }
+
+    export let destination: ShelfBasedPageScrollAction;
+
+    function handleLinkClick(e: Event) {
+        const anchorElement = e.currentTarget as HTMLAnchorElement;
+        const hash = anchorElement.hash;
+        const elementToScrollTo = document.querySelector(hash);
+        if (!elementToScrollTo) {
+            return;
+        }
+        elementToScrollTo.scrollIntoView({
+            behavior: 'smooth',
+            block: 'start',
+        });
+        history.replaceState(null, '', hash);
+    }
+</script>
+
+{#if destination.shelfId}
+    <a
+        {...$$restProps}
+        data-test-id="scroll-link"
+        href={`#${destination.shelfId}`}
+        on:click|preventDefault|stopPropagation={handleLinkClick}
+    >
+        <slot />
+    </a>
+{:else}
+    <slot />
+{/if}
-- 
cgit v1.2.3

