2020-10-17 20:12:00 +09:00
|
|
|
<template>
|
2023-04-08 09:01:42 +09:00
|
|
|
<transition :name="$store.state.animation ? 'fade' : ''" appear>
|
|
|
|
<div
|
|
|
|
ref="rootEl"
|
|
|
|
class="nvlagfpb"
|
|
|
|
:style="{ zIndex }"
|
|
|
|
@contextmenu.prevent.stop="() => {}"
|
|
|
|
>
|
|
|
|
<MkMenu :items="items" :align="'left'" @close="$emit('closed')" />
|
|
|
|
</div>
|
|
|
|
</transition>
|
2020-10-17 20:12:00 +09:00
|
|
|
</template>
|
|
|
|
|
2022-01-30 14:11:52 +09:00
|
|
|
<script lang="ts" setup>
|
2023-04-08 09:01:42 +09:00
|
|
|
import { onMounted, onBeforeUnmount } from "vue";
|
|
|
|
import MkMenu from "./MkMenu.vue";
|
|
|
|
import { MenuItem } from "./types/menu.vue";
|
|
|
|
import contains from "@/scripts/contains";
|
|
|
|
import * as os from "@/os";
|
2020-10-17 20:12:00 +09:00
|
|
|
|
2022-01-30 14:11:52 +09:00
|
|
|
const props = defineProps<{
|
|
|
|
items: MenuItem[];
|
|
|
|
ev: MouseEvent;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
2023-04-08 09:01:42 +09:00
|
|
|
(ev: "closed"): void;
|
2022-01-30 14:11:52 +09:00
|
|
|
}>();
|
|
|
|
|
|
|
|
let rootEl = $ref<HTMLDivElement>();
|
|
|
|
|
2023-04-08 09:01:42 +09:00
|
|
|
let zIndex = $ref<number>(os.claimZIndex("high"));
|
2022-01-30 14:11:52 +09:00
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
let left = props.ev.pageX + 1; // 間違って右ダブルクリックした場合に意図せずアイテムがクリックされるのを防ぐため + 1
|
|
|
|
let top = props.ev.pageY + 1; // 間違って右ダブルクリックした場合に意図せずアイテムがクリックされるのを防ぐため + 1
|
|
|
|
|
|
|
|
const width = rootEl.offsetWidth;
|
|
|
|
const height = rootEl.offsetHeight;
|
|
|
|
|
|
|
|
if (left + width - window.pageXOffset > window.innerWidth) {
|
|
|
|
left = window.innerWidth - width + window.pageXOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (top + height - window.pageYOffset > window.innerHeight) {
|
|
|
|
top = window.innerHeight - height + window.pageYOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (top < 0) {
|
|
|
|
top = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (left < 0) {
|
|
|
|
left = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
rootEl.style.top = `${top}px`;
|
|
|
|
rootEl.style.left = `${left}px`;
|
|
|
|
|
2023-04-08 09:01:42 +09:00
|
|
|
for (const el of Array.from(document.querySelectorAll("body *"))) {
|
|
|
|
el.addEventListener("mousedown", onMousedown);
|
2020-10-17 20:12:00 +09:00
|
|
|
}
|
|
|
|
});
|
2022-01-30 14:11:52 +09:00
|
|
|
|
|
|
|
onBeforeUnmount(() => {
|
2023-04-08 09:01:42 +09:00
|
|
|
for (const el of Array.from(document.querySelectorAll("body *"))) {
|
|
|
|
el.removeEventListener("mousedown", onMousedown);
|
2022-01-30 14:11:52 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-05-26 22:53:09 +09:00
|
|
|
function onMousedown(evt: Event) {
|
2023-04-08 09:01:42 +09:00
|
|
|
if (!contains(rootEl, evt.target) && rootEl !== evt.target) emit("closed");
|
2022-01-30 14:11:52 +09:00
|
|
|
}
|
2020-10-17 20:12:00 +09:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.nvlagfpb {
|
|
|
|
position: absolute;
|
|
|
|
}
|
2020-10-25 23:22:27 +09:00
|
|
|
|
2023-04-08 09:01:42 +09:00
|
|
|
.fade-enter-active,
|
|
|
|
.fade-leave-active {
|
|
|
|
transition: opacity 0.5s cubic-bezier(0.16, 1, 0.3, 1),
|
|
|
|
transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
|
2020-10-25 23:22:27 +09:00
|
|
|
transform-origin: left top;
|
|
|
|
}
|
|
|
|
|
2023-04-08 09:01:42 +09:00
|
|
|
.fade-enter-from,
|
|
|
|
.fade-leave-to {
|
2020-10-25 23:22:27 +09:00
|
|
|
opacity: 0;
|
|
|
|
transform: scale(0.9);
|
|
|
|
}
|
2020-10-17 20:12:00 +09:00
|
|
|
</style>
|