Skip to content

Commit fc77ad9

Browse files
committed
refactor(frontend): provide linkNavigationBehavior
1 parent 2b21c19 commit fc77ad9

File tree

6 files changed

+16
-20
lines changed

6 files changed

+16
-20
lines changed

packages/frontend/src/components/MkAbuseReport.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ SPDX-License-Identifier: AGPL-3.0-only
2020
</div>
2121
<div class="detail">
2222
<div>
23-
<Mfm :text="report.comment" :linkBehavior="'window'"/>
23+
<Mfm :text="report.comment" :linkNavigationBehavior="'window'"/>
2424
</div>
2525
<hr/>
2626
<div>{{ i18n.ts.reporter }}: <MkA :to="`/admin/user/${report.reporter.id}`" class="_link" :behavior="'window'">@{{ report.reporter.username }}</MkA></div>

packages/frontend/src/components/MkLink.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only
66
<template>
77
<component
88
: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"
9-
:behavior="props.behavior"
9+
:behavior="props.navigationBehavior"
1010
:title="url"
1111
>
1212
<slot></slot>
@@ -25,7 +25,7 @@ import { MkABehavior } from '@/components/global/MkA.vue';
2525
const props = withDefaults(defineProps<{
2626
url: string;
2727
rel?: null | string;
28-
behavior?: MkABehavior;
28+
navigationBehavior?: MkABehavior;
2929
}>(), {
3030
});
3131

packages/frontend/src/components/MkMention.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ SPDX-License-Identifier: AGPL-3.0-only
44
-->
55

66
<template>
7-
<MkA v-user-preview="canonical" :class="[$style.root, { [$style.isMe]: isMe }]" :to="url" :style="{ background: bgCss }" :behavior="behavior">
7+
<MkA v-user-preview="canonical" :class="[$style.root, { [$style.isMe]: isMe }]" :to="url" :style="{ background: bgCss }" :behavior="navigationBehavior">
88
<img :class="$style.icon" :src="avatarUrl" alt="">
99
<span>
1010
<span>@{{ username }}</span>
@@ -26,7 +26,7 @@ import { MkABehavior } from '@/components/global/MkA.vue';
2626
const props = defineProps<{
2727
username: string;
2828
host: string;
29-
behavior?: MkABehavior;
29+
navigationBehavior?: MkABehavior;
3030
}>();
3131

3232
const canonical = props.host === localHost ? `@${props.username}` : `@${props.username}@${toUnicode(props.host)}`;

packages/frontend/src/components/global/MkA.vue

+5-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export type MkABehavior = 'window' | 'browser' | null;
1414
</script>
1515

1616
<script lang="ts" setup>
17-
import { computed, shallowRef } from 'vue';
17+
import { computed, inject, shallowRef } from 'vue';
1818
import * as os from '@/os.js';
1919
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
2020
import { url } from '@/config.js';
@@ -30,7 +30,7 @@ const props = withDefaults(defineProps<{
3030
behavior: null,
3131
});
3232

33-
const linkBehaviour = props.behavior;
33+
const behavior = props.behavior ?? inject<MkABehavior>('linkNavigationBehavior', null);
3434

3535
const el = shallowRef<HTMLElement>();
3636

@@ -86,15 +86,13 @@ function openWindow() {
8686
}
8787

8888
function nav(ev: MouseEvent) {
89-
if (props.behavior === 'browser') {
89+
if (behavior === 'browser') {
9090
location.href = props.to;
9191
return;
9292
}
9393

94-
if (props.behavior) {
95-
if (props.behavior === 'window') {
96-
return openWindow();
97-
}
94+
if (behavior === 'window') {
95+
return openWindow();
9896
}
9997

10098
if (ev.shiftKey) {

packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: AGPL-3.0-only
44
*/
55

6-
import { VNode, h, SetupContext } from 'vue';
6+
import { VNode, h, SetupContext, provide } from 'vue';
77
import * as mfm from 'mfm-js';
88
import * as Misskey from 'misskey-js';
99
import MkUrl from '@/components/global/MkUrl.vue';
@@ -43,7 +43,7 @@ type MfmProps = {
4343
parsedNodes?: mfm.MfmNode[] | null;
4444
enableEmojiMenu?: boolean;
4545
enableEmojiMenuReaction?: boolean;
46-
linkBehavior?: MkABehavior;
46+
linkNavigationBehavior?: MkABehavior;
4747
};
4848

4949
type MfmEvents = {
@@ -52,6 +52,8 @@ type MfmEvents = {
5252

5353
// eslint-disable-next-line import/no-default-export
5454
export default function (props: MfmProps, { emit }: { emit: SetupContext<MfmEvents>['emit'] }) {
55+
provide('linkNavigationBehavior', props.linkNavigationBehavior);
56+
5557
const isNote = props.isNote ?? true;
5658
const shouldNyaize = props.nyaize ? props.nyaize === 'respect' ? props.author?.isCat : false : false;
5759

@@ -343,7 +345,6 @@ export default function (props: MfmProps, { emit }: { emit: SetupContext<MfmEven
343345
key: Math.random(),
344346
url: token.props.url,
345347
rel: 'nofollow noopener',
346-
behavior: props.linkBehavior,
347348
})];
348349
}
349350

@@ -352,7 +353,6 @@ export default function (props: MfmProps, { emit }: { emit: SetupContext<MfmEven
352353
key: Math.random(),
353354
url: token.props.url,
354355
rel: 'nofollow noopener',
355-
behavior: props.linkBehavior,
356356
}, genEl(token.children, scale, true))];
357357
}
358358

@@ -361,7 +361,6 @@ export default function (props: MfmProps, { emit }: { emit: SetupContext<MfmEven
361361
key: Math.random(),
362362
host: (token.props.host == null && props.author && props.author.host != null ? props.author.host : token.props.host) ?? host,
363363
username: token.props.username,
364-
behavior: props.linkBehavior,
365364
})];
366365
}
367366

@@ -370,7 +369,6 @@ export default function (props: MfmProps, { emit }: { emit: SetupContext<MfmEven
370369
key: Math.random(),
371370
to: isNote ? `/tags/${encodeURIComponent(token.props.hashtag)}` : `/user-tags/${encodeURIComponent(token.props.hashtag)}`,
372371
style: 'color:var(--hashtag);',
373-
behavior: props.linkBehavior,
374372
}, `#${token.props.hashtag}`)];
375373
}
376374

packages/frontend/src/components/global/MkUrl.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only
66
<template>
77
<component
88
: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"
9-
:behavior = "props.behavior"
9+
:behavior="props.navigationBehavior"
1010
@contextmenu.stop="() => {}"
1111
>
1212
<template v-if="!self">
@@ -38,7 +38,7 @@ const props = withDefaults(defineProps<{
3838
url: string;
3939
rel?: string;
4040
showUrlPreview?: boolean;
41-
behavior?: MkABehavior;
41+
navigationBehavior?: MkABehavior;
4242
}>(), {
4343
showUrlPreview: true,
4444
});

0 commit comments

Comments
 (0)