2020-10-24 18:21:41 +02:00
|
|
|
<template>
|
|
|
|
<a :href="to" :class="active ? activeClass : null" @click.prevent="nav" @contextmenu.prevent.stop="onContextmenu">
|
|
|
|
<slot></slot>
|
|
|
|
</a>
|
|
|
|
</template>
|
|
|
|
|
2022-01-15 23:47:28 +01:00
|
|
|
<script lang="ts" setup>
|
2021-11-11 18:02:25 +01:00
|
|
|
import * as os from '@/os';
|
|
|
|
import copyToClipboard from '@/scripts/copy-to-clipboard';
|
|
|
|
import { url } from '@/config';
|
2022-01-15 23:47:28 +01:00
|
|
|
import { popout as popout_ } from '@/scripts/popout';
|
|
|
|
import { i18n } from '@/i18n';
|
2022-06-20 10:38:49 +02:00
|
|
|
import { useRouter } from '@/router';
|
2020-10-24 18:21:41 +02:00
|
|
|
|
2022-01-15 23:47:28 +01:00
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
to: string;
|
|
|
|
activeClass?: null | string;
|
2023-05-27 04:38:08 +02:00
|
|
|
behavior?: null | 'window' | 'browser';
|
2022-01-15 23:47:28 +01:00
|
|
|
}>(), {
|
|
|
|
activeClass: null,
|
|
|
|
behavior: null,
|
|
|
|
});
|
2020-10-24 18:21:41 +02:00
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
const router = useRouter();
|
2020-10-24 18:21:41 +02:00
|
|
|
|
2022-01-15 23:47:28 +01:00
|
|
|
const active = $computed(() => {
|
|
|
|
if (props.activeClass == null) return false;
|
|
|
|
const resolved = router.resolve(props.to);
|
2022-06-20 10:38:49 +02:00
|
|
|
if (resolved == null) return false;
|
|
|
|
if (resolved.route.path === router.currentRoute.value.path) return true;
|
|
|
|
if (resolved.route.name == null) return false;
|
2022-01-15 23:47:28 +01:00
|
|
|
if (router.currentRoute.value.name == null) return false;
|
2022-06-20 10:38:49 +02:00
|
|
|
return resolved.route.name === router.currentRoute.value.name;
|
2022-01-15 23:47:28 +01:00
|
|
|
});
|
2020-10-24 18:21:41 +02:00
|
|
|
|
2022-01-15 23:47:28 +01:00
|
|
|
function onContextmenu(ev) {
|
2022-01-16 00:24:53 +01:00
|
|
|
const selection = window.getSelection();
|
|
|
|
if (selection && selection.toString() !== '') return;
|
2022-01-15 23:47:28 +01:00
|
|
|
os.contextMenu([{
|
|
|
|
type: 'label',
|
|
|
|
text: props.to,
|
|
|
|
}, {
|
2022-12-20 02:52:39 +01:00
|
|
|
icon: 'ti ti-app-window',
|
2022-01-28 03:39:49 +01:00
|
|
|
text: i18n.ts.openInWindow,
|
2022-01-15 23:47:28 +01:00
|
|
|
action: () => {
|
|
|
|
os.pageWindow(props.to);
|
2022-06-20 10:38:49 +02:00
|
|
|
},
|
|
|
|
}, {
|
2022-12-21 00:39:28 +01:00
|
|
|
icon: 'ti ti-player-eject',
|
2022-01-28 03:39:49 +01:00
|
|
|
text: i18n.ts.showInPage,
|
2022-01-15 23:47:28 +01:00
|
|
|
action: () => {
|
2022-07-17 22:03:39 +02:00
|
|
|
router.push(props.to, 'forcePage');
|
2022-06-20 10:38:49 +02:00
|
|
|
},
|
2022-01-15 23:47:28 +01:00
|
|
|
}, null, {
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-external-link',
|
2022-01-28 03:39:49 +01:00
|
|
|
text: i18n.ts.openInNewTab,
|
2022-01-15 23:47:28 +01:00
|
|
|
action: () => {
|
|
|
|
window.open(props.to, '_blank');
|
2022-06-20 10:38:49 +02:00
|
|
|
},
|
2022-01-15 23:47:28 +01:00
|
|
|
}, {
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-link',
|
2022-01-28 03:39:49 +01:00
|
|
|
text: i18n.ts.copyLink,
|
2022-01-15 23:47:28 +01:00
|
|
|
action: () => {
|
|
|
|
copyToClipboard(`${url}${props.to}`);
|
2022-06-20 10:38:49 +02:00
|
|
|
},
|
2022-01-15 23:47:28 +01:00
|
|
|
}], ev);
|
|
|
|
}
|
2020-10-24 18:21:41 +02:00
|
|
|
|
2022-01-16 00:24:53 +01:00
|
|
|
function openWindow() {
|
2022-01-15 23:47:28 +01:00
|
|
|
os.pageWindow(props.to);
|
|
|
|
}
|
2020-11-03 02:43:50 +01:00
|
|
|
|
2022-07-17 22:03:39 +02:00
|
|
|
function nav(ev: MouseEvent) {
|
2022-01-15 23:47:28 +01:00
|
|
|
if (props.behavior === 'browser') {
|
|
|
|
location.href = props.to;
|
|
|
|
return;
|
|
|
|
}
|
2021-03-02 17:03:29 +01:00
|
|
|
|
2022-01-15 23:47:28 +01:00
|
|
|
if (props.behavior) {
|
|
|
|
if (props.behavior === 'window') {
|
2022-01-16 00:24:53 +01:00
|
|
|
return openWindow();
|
2022-01-15 23:47:28 +01:00
|
|
|
}
|
|
|
|
}
|
2020-10-27 05:53:47 +01:00
|
|
|
|
2022-07-17 22:03:39 +02:00
|
|
|
if (ev.shiftKey) {
|
|
|
|
return openWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
router.push(props.to, ev.ctrlKey ? 'forcePage' : null);
|
2022-01-15 23:47:28 +01:00
|
|
|
}
|
2020-10-24 18:21:41 +02:00
|
|
|
</script>
|