Skip to content

Commit

Permalink
feat: watch href
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Wang <[email protected]>
  • Loading branch information
ruibaby committed Jun 7, 2024
1 parent 8456373 commit 1251e2d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
17 changes: 16 additions & 1 deletion ui/src/components/HyperlinkInlineView.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
<script lang="ts" setup>
import type { HyperlinkInlineCard } from '@halo-dev/hyperlink-card';
import { nodeViewProps, NodeViewWrapper } from '@halo-dev/richtext-editor';
import { ref, watch } from 'vue';
defineProps(nodeViewProps);
const props = defineProps(nodeViewProps);
const cardRef = ref<InstanceType<typeof HyperlinkInlineCard> | null>();
watch(
() => props.node.attrs.href,
(value) => {
if (value && cardRef.value) {
cardRef.value.href = value;
cardRef.value.fetchSiteData();
}
}
);
</script>

<template>
Expand All @@ -11,6 +25,7 @@ defineProps(nodeViewProps);
:class="{ 'hyperlink-ring-1': selected }"
>
<hyperlink-inline-card
ref="cardRef"
class="hyperlink-pointer-events-none hyperlink-select-none"
:href="node.attrs.href"
:theme="node.attrs.theme"
Expand Down
17 changes: 16 additions & 1 deletion ui/src/components/HyperlinkView.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
<script lang="ts" setup>
import type { HyperlinkCard } from '@halo-dev/hyperlink-card';
import { nodeViewProps, NodeViewWrapper } from '@halo-dev/richtext-editor';
import { ref, watch } from 'vue';
defineProps(nodeViewProps);
const props = defineProps(nodeViewProps);
const cardRef = ref<InstanceType<typeof HyperlinkCard> | null>();
watch(
() => props.node.attrs.href,
(value) => {
if (value && cardRef.value) {
cardRef.value.href = value;
cardRef.value.fetchSiteData();
}
}
);
</script>

<template>
Expand All @@ -11,6 +25,7 @@ defineProps(nodeViewProps);
:class="{ 'hyperlink-rounded-xl hyperlink-ring-1': selected }"
>
<hyperlink-card
ref="cardRef"
class="hyperlink-pointer-events-none hyperlink-select-none"
:href="node.attrs.href"
:theme="node.attrs.theme"
Expand Down

0 comments on commit 1251e2d

Please sign in to comment.