summaryrefslogtreecommitdiff
path: root/src/components/jet/action/FlowAction.svelte
diff options
context:
space:
mode:
authorrxliuli <rxliuli@gmail.com>2025-11-04 05:03:50 +0800
committerrxliuli <rxliuli@gmail.com>2025-11-04 05:03:50 +0800
commitbce557cc2dc767628bed6aac87301a1be7c5431b (patch)
treeb51a051228d01fe3306cd7626d4a96768aadb944 /src/components/jet/action/FlowAction.svelte
init commit
Diffstat (limited to 'src/components/jet/action/FlowAction.svelte')
-rw-r--r--src/components/jet/action/FlowAction.svelte41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/components/jet/action/FlowAction.svelte b/src/components/jet/action/FlowAction.svelte
new file mode 100644
index 0000000..3e55e82
--- /dev/null
+++ b/src/components/jet/action/FlowAction.svelte
@@ -0,0 +1,41 @@
+<script lang="ts">
+ import type { HTMLAnchorAttributes } from 'svelte/elements';
+ import type { FlowAction } from '@jet-app/app-store/api/models';
+ import { getJetPerform } from '~/jet';
+
+ type AllowedAnchorAttributes = Omit<
+ HTMLAnchorAttributes,
+ // The `href` attribute is not allowed because it will be provided
+ // by the `FlowAction`
+ 'href'
+ >;
+
+ interface $$Props extends AllowedAnchorAttributes {
+ destination: FlowAction;
+ }
+
+ const perform = getJetPerform();
+
+ export let destination: FlowAction;
+
+ // Web cannot support internal protocols, so this guard prevents
+ // them from showing up in anchor tags.
+ $: pageUrl = destination.pageUrl?.includes('x-as3-internal:')
+ ? '#'
+ : destination?.pageUrl;
+
+ function onClick(event: MouseEvent) {
+ event.preventDefault();
+
+ perform(destination);
+ }
+</script>
+
+<a
+ {...$$restProps}
+ href={pageUrl}
+ data-test-id="internal-link"
+ on:click={onClick}
+>
+ <slot />
+</a>