2023-07-27 00:31:52 -05:00
|
|
|
<!--
|
2024-02-13 09:59:27 -06:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 00:31:52 -05:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-02-09 12:48:45 -06:00
|
|
|
<template>
|
2022-12-19 04:01:30 -06:00
|
|
|
<component
|
2023-12-08 02:48:18 -06:00
|
|
|
:is="self ? 'MkA' : 'a'" ref="el" style="word-break: break-all;" class="_link" :[attr]="self ? url.substring(local.length) : url" :rel="rel ?? 'nofollow noopener'" :target="target"
|
2024-05-06 06:37:04 -05:00
|
|
|
:behavior="props.navigationBehavior"
|
2021-11-19 04:36:12 -06:00
|
|
|
:title="url"
|
2024-10-21 10:56:29 -05:00
|
|
|
@click.stop
|
2020-02-09 12:48:45 -06:00
|
|
|
>
|
|
|
|
<slot></slot>
|
2023-01-09 23:45:02 -06:00
|
|
|
<i v-if="target === '_blank'" class="ti ti-external-link" :class="$style.icon"></i>
|
2020-02-09 12:48:45 -06:00
|
|
|
</component>
|
|
|
|
</template>
|
|
|
|
|
2022-01-15 17:38:55 -06:00
|
|
|
<script lang="ts" setup>
|
2023-12-06 23:42:09 -06:00
|
|
|
import { defineAsyncComponent, ref } from 'vue';
|
2024-09-10 04:39:53 -05:00
|
|
|
import { url as local } from '@@/js/config.js';
|
2023-09-19 02:37:43 -05:00
|
|
|
import { useTooltip } from '@/scripts/use-tooltip.js';
|
|
|
|
import * as os from '@/os.js';
|
2024-03-21 04:46:42 -05:00
|
|
|
import { isEnabledUrlPreview } from '@/instance.js';
|
2024-04-27 07:24:39 -05:00
|
|
|
import { MkABehavior } from '@/components/global/MkA.vue';
|
2020-02-09 12:48:45 -06:00
|
|
|
|
2022-01-15 17:38:55 -06:00
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
url: string;
|
|
|
|
rel?: null | string;
|
2024-05-06 06:37:04 -05:00
|
|
|
navigationBehavior?: MkABehavior;
|
2022-01-15 17:38:55 -06:00
|
|
|
}>(), {
|
|
|
|
});
|
2020-02-09 12:48:45 -06:00
|
|
|
|
2022-01-15 17:38:55 -06:00
|
|
|
const self = props.url.startsWith(local);
|
|
|
|
const attr = self ? 'to' : 'href';
|
|
|
|
const target = self ? null : '_blank';
|
2020-02-09 12:48:45 -06:00
|
|
|
|
2024-03-11 23:50:24 -05:00
|
|
|
const el = ref<HTMLElement | { $el: HTMLElement }>();
|
2020-10-17 06:12:00 -05:00
|
|
|
|
2024-03-21 04:46:42 -05:00
|
|
|
if (isEnabledUrlPreview.value) {
|
|
|
|
useTooltip(el, (showing) => {
|
2024-07-03 23:14:49 -05:00
|
|
|
const { dispose } = os.popup(defineAsyncComponent(() => import('@/components/MkUrlPreviewPopup.vue')), {
|
2024-03-21 04:46:42 -05:00
|
|
|
showing,
|
|
|
|
url: props.url,
|
|
|
|
source: el.value instanceof HTMLElement ? el.value : el.value?.$el,
|
2024-07-03 23:14:49 -05:00
|
|
|
}, {
|
|
|
|
closed: () => dispose(),
|
|
|
|
});
|
2024-03-21 04:46:42 -05:00
|
|
|
});
|
|
|
|
}
|
2020-02-09 12:48:45 -06:00
|
|
|
</script>
|
|
|
|
|
2023-01-09 23:45:02 -06:00
|
|
|
<style lang="scss" module>
|
|
|
|
.icon {
|
|
|
|
padding-left: 2px;
|
|
|
|
font-size: .9em;
|
2020-02-09 12:48:45 -06:00
|
|
|
}
|
|
|
|
</style>
|