summaryrefslogtreecommitdiff
path: root/packages/frontend/src/components
diff options
context:
space:
mode:
authorsyuilo <4439005+syuilo@users.noreply.github.com>2024-05-06 20:37:04 +0900
committersyuilo <4439005+syuilo@users.noreply.github.com>2024-05-06 20:37:04 +0900
commitfc77ad9355f74ec4b4b155a9d5624850b3dff351 (patch)
tree2823debf720a2755c538ec72153b0223c9fc3338 /packages/frontend/src/components
parentupdate deps (#13624) (diff)
downloadsharkey-fc77ad9355f74ec4b4b155a9d5624850b3dff351.tar.gz
sharkey-fc77ad9355f74ec4b4b155a9d5624850b3dff351.tar.bz2
sharkey-fc77ad9355f74ec4b4b155a9d5624850b3dff351.zip
refactor(frontend): provide linkNavigationBehavior
Diffstat (limited to 'packages/frontend/src/components')
-rw-r--r--packages/frontend/src/components/MkAbuseReport.vue2
-rw-r--r--packages/frontend/src/components/MkLink.vue4
-rw-r--r--packages/frontend/src/components/MkMention.vue4
-rw-r--r--packages/frontend/src/components/global/MkA.vue12
-rw-r--r--packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts10
-rw-r--r--packages/frontend/src/components/global/MkUrl.vue4
6 files changed, 16 insertions, 20 deletions
diff --git a/packages/frontend/src/components/MkAbuseReport.vue b/packages/frontend/src/components/MkAbuseReport.vue
index ab65ea7ec7..a28e7c2559 100644
--- a/packages/frontend/src/components/MkAbuseReport.vue
+++ b/packages/frontend/src/components/MkAbuseReport.vue
@@ -20,7 +20,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</div>
<div class="detail">
<div>
- <Mfm :text="report.comment" :linkBehavior="'window'"/>
+ <Mfm :text="report.comment" :linkNavigationBehavior="'window'"/>
</div>
<hr/>
<div>{{ i18n.ts.reporter }}: <MkA :to="`/admin/user/${report.reporter.id}`" class="_link" :behavior="'window'">@{{ report.reporter.username }}</MkA></div>
diff --git a/packages/frontend/src/components/MkLink.vue b/packages/frontend/src/components/MkLink.vue
index bd1bd0e24a..5d54a58e97 100644
--- a/packages/frontend/src/components/MkLink.vue
+++ b/packages/frontend/src/components/MkLink.vue
@@ -6,7 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<template>
<component
: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"
- :behavior="props.behavior"
+ :behavior="props.navigationBehavior"
:title="url"
>
<slot></slot>
@@ -25,7 +25,7 @@ import { MkABehavior } from '@/components/global/MkA.vue';
const props = withDefaults(defineProps<{
url: string;
rel?: null | string;
- behavior?: MkABehavior;
+ navigationBehavior?: MkABehavior;
}>(), {
});
diff --git a/packages/frontend/src/components/MkMention.vue b/packages/frontend/src/components/MkMention.vue
index cbefecf03a..bfb49a416e 100644
--- a/packages/frontend/src/components/MkMention.vue
+++ b/packages/frontend/src/components/MkMention.vue
@@ -4,7 +4,7 @@ SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
-<MkA v-user-preview="canonical" :class="[$style.root, { [$style.isMe]: isMe }]" :to="url" :style="{ background: bgCss }" :behavior="behavior">
+<MkA v-user-preview="canonical" :class="[$style.root, { [$style.isMe]: isMe }]" :to="url" :style="{ background: bgCss }" :behavior="navigationBehavior">
<img :class="$style.icon" :src="avatarUrl" alt="">
<span>
<span>@{{ username }}</span>
@@ -26,7 +26,7 @@ import { MkABehavior } from '@/components/global/MkA.vue';
const props = defineProps<{
username: string;
host: string;
- behavior?: MkABehavior;
+ navigationBehavior?: MkABehavior;
}>();
const canonical = props.host === localHost ? `@${props.username}` : `@${props.username}@${toUnicode(props.host)}`;
diff --git a/packages/frontend/src/components/global/MkA.vue b/packages/frontend/src/components/global/MkA.vue
index b64acacc32..d1e9113c48 100644
--- a/packages/frontend/src/components/global/MkA.vue
+++ b/packages/frontend/src/components/global/MkA.vue
@@ -14,7 +14,7 @@ export type MkABehavior = 'window' | 'browser' | null;
</script>
<script lang="ts" setup>
-import { computed, shallowRef } from 'vue';
+import { computed, inject, shallowRef } from 'vue';
import * as os from '@/os.js';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { url } from '@/config.js';
@@ -30,7 +30,7 @@ const props = withDefaults(defineProps<{
behavior: null,
});
-const linkBehaviour = props.behavior;
+const behavior = props.behavior ?? inject<MkABehavior>('linkNavigationBehavior', null);
const el = shallowRef<HTMLElement>();
@@ -86,15 +86,13 @@ function openWindow() {
}
function nav(ev: MouseEvent) {
- if (props.behavior === 'browser') {
+ if (behavior === 'browser') {
location.href = props.to;
return;
}
- if (props.behavior) {
- if (props.behavior === 'window') {
- return openWindow();
- }
+ if (behavior === 'window') {
+ return openWindow();
}
if (ev.shiftKey) {
diff --git a/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts b/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts
index 6e880fc322..cab8d9c704 100644
--- a/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts
+++ b/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
-import { VNode, h, SetupContext } from 'vue';
+import { VNode, h, SetupContext, provide } from 'vue';
import * as mfm from 'mfm-js';
import * as Misskey from 'misskey-js';
import MkUrl from '@/components/global/MkUrl.vue';
@@ -43,7 +43,7 @@ type MfmProps = {
parsedNodes?: mfm.MfmNode[] | null;
enableEmojiMenu?: boolean;
enableEmojiMenuReaction?: boolean;
- linkBehavior?: MkABehavior;
+ linkNavigationBehavior?: MkABehavior;
};
type MfmEvents = {
@@ -52,6 +52,8 @@ type MfmEvents = {
// eslint-disable-next-line import/no-default-export
export default function (props: MfmProps, { emit }: { emit: SetupContext<MfmEvents>['emit'] }) {
+ provide('linkNavigationBehavior', props.linkNavigationBehavior);
+
const isNote = props.isNote ?? true;
const shouldNyaize = props.nyaize ? props.nyaize === 'respect' ? props.author?.isCat : false : false;
@@ -343,7 +345,6 @@ export default function (props: MfmProps, { emit }: { emit: SetupContext<MfmEven
key: Math.random(),
url: token.props.url,
rel: 'nofollow noopener',
- behavior: props.linkBehavior,
})];
}
@@ -352,7 +353,6 @@ export default function (props: MfmProps, { emit }: { emit: SetupContext<MfmEven
key: Math.random(),
url: token.props.url,
rel: 'nofollow noopener',
- behavior: props.linkBehavior,
}, genEl(token.children, scale, true))];
}
@@ -361,7 +361,6 @@ export default function (props: MfmProps, { emit }: { emit: SetupContext<MfmEven
key: Math.random(),
host: (token.props.host == null && props.author && props.author.host != null ? props.author.host : token.props.host) ?? host,
username: token.props.username,
- behavior: props.linkBehavior,
})];
}
@@ -370,7 +369,6 @@ export default function (props: MfmProps, { emit }: { emit: SetupContext<MfmEven
key: Math.random(),
to: isNote ? `/tags/${encodeURIComponent(token.props.hashtag)}` : `/user-tags/${encodeURIComponent(token.props.hashtag)}`,
style: 'color:var(--hashtag);',
- behavior: props.linkBehavior,
}, `#${token.props.hashtag}`)];
}
diff --git a/packages/frontend/src/components/global/MkUrl.vue b/packages/frontend/src/components/global/MkUrl.vue
index 1c2f3ccedb..9d4cd559d9 100644
--- a/packages/frontend/src/components/global/MkUrl.vue
+++ b/packages/frontend/src/components/global/MkUrl.vue
@@ -6,7 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<template>
<component
:is="self ? 'MkA' : 'a'" ref="el" :class="$style.root" class="_link" :[attr]="self ? props.url.substring(local.length) : props.url" :rel="rel ?? 'nofollow noopener'" :target="target"
- :behavior = "props.behavior"
+ :behavior="props.navigationBehavior"
@contextmenu.stop="() => {}"
>
<template v-if="!self">
@@ -38,7 +38,7 @@ const props = withDefaults(defineProps<{
url: string;
rel?: string;
showUrlPreview?: boolean;
- behavior?: MkABehavior;
+ navigationBehavior?: MkABehavior;
}>(), {
showUrlPreview: true,
});