2023-07-27 05:31:52 +00:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
<template>
|
2023-01-15 00:14:17 +00:00
|
|
|
<Transition
|
|
|
|
appear
|
2023-05-19 04:58:09 +00:00
|
|
|
:enterActiveClass="defaultStore.state.animation ? $style.transition_fade_enterActive : ''"
|
|
|
|
:leaveActiveClass="defaultStore.state.animation ? $style.transition_fade_leaveActive : ''"
|
|
|
|
:enterFromClass="defaultStore.state.animation ? $style.transition_fade_enterFrom : ''"
|
|
|
|
:leaveToClass="defaultStore.state.animation ? $style.transition_fade_leaveTo : ''"
|
2023-01-15 00:14:17 +00:00
|
|
|
>
|
|
|
|
<div ref="rootEl" :class="$style.root" :style="{ zIndex }" @contextmenu.prevent.stop="() => {}">
|
2022-07-17 14:18:05 +00:00
|
|
|
<MkMenu :items="items" :align="'left'" @close="$emit('closed')"/>
|
2020-10-25 14:22:27 +00:00
|
|
|
</div>
|
2022-12-30 04:37:14 +00:00
|
|
|
</Transition>
|
2020-10-17 11:12:00 +00:00
|
|
|
</template>
|
|
|
|
|
2022-01-30 05:11:52 +00:00
|
|
|
<script lang="ts" setup>
|
2023-12-07 05:42:09 +00:00
|
|
|
import { onMounted, onBeforeUnmount, shallowRef, ref } from 'vue';
|
2022-09-06 09:21:49 +00:00
|
|
|
import MkMenu from './MkMenu.vue';
|
2023-12-24 07:16:58 +00:00
|
|
|
import { MenuItem } from '@/types/menu.js';
|
2023-09-19 07:37:43 +00:00
|
|
|
import contains from '@/scripts/contains.js';
|
|
|
|
import { defaultStore } from '@/store.js';
|
|
|
|
import * as os from '@/os.js';
|
2020-10-17 11:12:00 +00:00
|
|
|
|
2022-01-30 05:11:52 +00:00
|
|
|
const props = defineProps<{
|
|
|
|
items: MenuItem[];
|
|
|
|
ev: MouseEvent;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
2022-05-26 13:53:09 +00:00
|
|
|
(ev: 'closed'): void;
|
2022-01-30 05:11:52 +00:00
|
|
|
}>();
|
|
|
|
|
2023-12-07 05:42:09 +00:00
|
|
|
const rootEl = shallowRef<HTMLDivElement>();
|
2022-01-30 05:11:52 +00:00
|
|
|
|
2023-12-07 05:42:09 +00:00
|
|
|
const zIndex = ref<number>(os.claimZIndex('high'));
|
2022-01-30 05:11:52 +00:00
|
|
|
|
2023-02-25 04:44:37 +00:00
|
|
|
const SCROLLBAR_THICKNESS = 16;
|
|
|
|
|
2022-01-30 05:11:52 +00:00
|
|
|
onMounted(() => {
|
|
|
|
let left = props.ev.pageX + 1; // 間違って右ダブルクリックした場合に意図せずアイテムがクリックされるのを防ぐため + 1
|
|
|
|
let top = props.ev.pageY + 1; // 間違って右ダブルクリックした場合に意図せずアイテムがクリックされるのを防ぐため + 1
|
|
|
|
|
2023-12-07 05:42:09 +00:00
|
|
|
const width = rootEl.value.offsetWidth;
|
|
|
|
const height = rootEl.value.offsetHeight;
|
2022-01-30 05:11:52 +00:00
|
|
|
|
2023-02-25 04:44:37 +00:00
|
|
|
if (left + width - window.pageXOffset >= (window.innerWidth - SCROLLBAR_THICKNESS)) {
|
|
|
|
left = (window.innerWidth - SCROLLBAR_THICKNESS) - width + window.pageXOffset;
|
2022-01-30 05:11:52 +00:00
|
|
|
}
|
|
|
|
|
2023-02-25 04:44:37 +00:00
|
|
|
if (top + height - window.pageYOffset >= (window.innerHeight - SCROLLBAR_THICKNESS)) {
|
|
|
|
top = (window.innerHeight - SCROLLBAR_THICKNESS) - height + window.pageYOffset;
|
2022-01-30 05:11:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (top < 0) {
|
|
|
|
top = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (left < 0) {
|
|
|
|
left = 0;
|
|
|
|
}
|
|
|
|
|
2023-12-07 05:42:09 +00:00
|
|
|
rootEl.value.style.top = `${top}px`;
|
|
|
|
rootEl.value.style.left = `${left}px`;
|
2022-01-30 05:11:52 +00:00
|
|
|
|
2023-07-17 05:10:40 +00:00
|
|
|
document.body.addEventListener('mousedown', onMousedown);
|
2020-10-17 11:12:00 +00:00
|
|
|
});
|
2022-01-30 05:11:52 +00:00
|
|
|
|
|
|
|
onBeforeUnmount(() => {
|
2023-07-17 05:10:40 +00:00
|
|
|
document.body.removeEventListener('mousedown', onMousedown);
|
2022-01-30 05:11:52 +00:00
|
|
|
});
|
|
|
|
|
2022-05-26 13:53:09 +00:00
|
|
|
function onMousedown(evt: Event) {
|
2023-12-07 05:42:09 +00:00
|
|
|
if (!contains(rootEl.value, evt.target) && (rootEl.value !== evt.target)) emit('closed');
|
2022-01-30 05:11:52 +00:00
|
|
|
}
|
2020-10-17 11:12:00 +00:00
|
|
|
</script>
|
|
|
|
|
2023-01-15 00:14:17 +00:00
|
|
|
<style lang="scss" module>
|
|
|
|
.transition_fade_enterActive,
|
|
|
|
.transition_fade_leaveActive {
|
2023-01-08 00:58:35 +00:00
|
|
|
transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
|
2020-10-25 14:22:27 +00:00
|
|
|
transform-origin: left top;
|
|
|
|
}
|
2023-01-15 00:14:17 +00:00
|
|
|
.transition_fade_enterFrom,
|
|
|
|
.transition_fade_leaveTo {
|
2020-10-25 14:22:27 +00:00
|
|
|
opacity: 0;
|
|
|
|
transform: scale(0.9);
|
|
|
|
}
|
2023-01-15 00:14:17 +00:00
|
|
|
|
|
|
|
.root {
|
|
|
|
position: absolute;
|
|
|
|
}
|
2020-10-17 11:12:00 +00:00
|
|
|
</style>
|