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