2020-10-24 18:21:41 +02:00
|
|
|
<template>
|
2023-04-08 02:01:42 +02:00
|
|
|
<a
|
|
|
|
:href="to"
|
|
|
|
:class="active ? activeClass : null"
|
|
|
|
@click="nav"
|
|
|
|
@contextmenu.prevent.stop="onContextmenu"
|
|
|
|
@click.stop
|
|
|
|
>
|
|
|
|
<slot></slot>
|
|
|
|
</a>
|
2020-10-24 18:21:41 +02:00
|
|
|
</template>
|
|
|
|
|
2022-01-15 23:47:28 +01:00
|
|
|
<script lang="ts" setup>
|
2023-04-08 02:01:42 +02:00
|
|
|
import { inject } from "vue";
|
|
|
|
import * as os from "@/os";
|
|
|
|
import copyToClipboard from "@/scripts/copy-to-clipboard";
|
|
|
|
import { url } from "@/config";
|
|
|
|
import { popout as popout_ } from "@/scripts/popout";
|
|
|
|
import { i18n } from "@/i18n";
|
|
|
|
import { useRouter } from "@/router";
|
2020-10-24 18:21:41 +02:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const props = withDefaults(
|
|
|
|
defineProps<{
|
|
|
|
to: string;
|
|
|
|
activeClass?: null | string;
|
|
|
|
behavior?: null | "window" | "browser" | "modalWindow";
|
|
|
|
}>(),
|
|
|
|
{
|
|
|
|
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();
|
2023-04-08 02:01:42 +02:00
|
|
|
if (selection && selection.toString() !== "") return;
|
|
|
|
os.contextMenu(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: "label",
|
|
|
|
text: props.to,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: "ph-browser ph-bold ph-lg",
|
|
|
|
text: i18n.ts.openInWindow,
|
|
|
|
action: () => {
|
|
|
|
os.pageWindow(props.to);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: "ph-arrows-out-simple ph-bold ph-lg",
|
|
|
|
text: i18n.ts.showInPage,
|
|
|
|
action: () => {
|
|
|
|
router.push(props.to, "forcePage");
|
|
|
|
},
|
|
|
|
},
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
icon: "ph-arrow-square-out ph-bold ph-lg",
|
|
|
|
text: i18n.ts.openInNewTab,
|
|
|
|
action: () => {
|
|
|
|
window.open(props.to, "_blank");
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: "ph-link-simple ph-bold ph-lg",
|
|
|
|
text: i18n.ts.copyLink,
|
|
|
|
action: () => {
|
|
|
|
copyToClipboard(`${url}${props.to}`);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
ev
|
|
|
|
);
|
2022-01-15 23:47:28 +01:00
|
|
|
}
|
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-01-15 23:47:28 +01:00
|
|
|
function modalWindow() {
|
|
|
|
os.modalPageWindow(props.to);
|
|
|
|
}
|
2021-04-11 14:09:35 +02:00
|
|
|
|
2022-01-15 23:47:28 +01:00
|
|
|
function popout() {
|
|
|
|
popout_(props.to);
|
|
|
|
}
|
2020-11-03 02:43:50 +01:00
|
|
|
|
2022-07-17 22:03:39 +02:00
|
|
|
function nav(ev: MouseEvent) {
|
2023-03-22 19:50:30 +01:00
|
|
|
if (!ev.ctrlKey) {
|
|
|
|
ev.preventDefault();
|
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
if (props.behavior === "browser") {
|
2023-03-22 19:50:30 +01:00
|
|
|
location.href = props.to;
|
|
|
|
return;
|
|
|
|
}
|
2021-03-02 17:03:29 +01:00
|
|
|
|
2023-03-22 19:50:30 +01:00
|
|
|
if (props.behavior) {
|
2023-04-08 02:01:42 +02:00
|
|
|
if (props.behavior === "window") {
|
2023-03-22 19:50:30 +01:00
|
|
|
return openWindow();
|
2023-04-08 02:01:42 +02:00
|
|
|
} else if (props.behavior === "modalWindow") {
|
2023-03-22 19:50:30 +01:00
|
|
|
return modalWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ev.shiftKey) {
|
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
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
router.push(props.to, ev.ctrlKey ? "forcePage" : null);
|
2022-07-17 22:03:39 +02:00
|
|
|
}
|
2022-01-15 23:47:28 +01:00
|
|
|
}
|
2020-10-24 18:21:41 +02:00
|
|
|
</script>
|