This commit is contained in:
isUnknown 2025-10-02 15:12:20 +02:00
parent 5deb07f09d
commit 8eaa893994
4 changed files with 104 additions and 71 deletions

View file

@ -114,7 +114,7 @@
import dayjs from 'dayjs';
import 'dayjs/locale/fr';
import uniqid from 'uniqid';
import { watch, ref, computed } from 'vue';
import { watch, ref, computed, onBeforeUnmount } from 'vue';
import { useUserStore } from '../../stores/user';
import { usePageStore } from '../../stores/page';
import { useApiStore } from '../../stores/api';
@ -158,10 +158,12 @@ watch(isAddOpen, (newVal) => {
}
});
const viewContainer =
openedFile.value?.type === 'document'
const viewContainer = computed(() => {
if (!openedFile.value) return null;
return openedFile.value.type === 'document'
? document.querySelector('.vpv-pages-inner-container')
: document.querySelector('.track');
});
window.addEventListener('keydown', (event) => {
if (
@ -256,20 +258,8 @@ function closeComment() {
openedComment.value = null;
}
function toggleCommentPositionMode(enable) {
if (enable) {
waitingForCommentPosition.value = true;
viewContainer.classList.add('waiting-comment');
viewContainer.addEventListener('click', handleCommentPositionClick);
} else {
waitingForCommentPosition.value = false;
viewContainer.classList.remove('waiting-comment');
viewContainer.removeEventListener('click', handleCommentPositionClick);
}
}
function handleCommentPositionClick(event) {
if (openedFile.value.type === 'document') {
if (openedFile.value?.type === 'document') {
prepareDraftCommentInPdf(event);
} else {
prepareDraftCommentInImage(event);
@ -278,6 +268,21 @@ function handleCommentPositionClick(event) {
toggleCommentPositionMode(false);
}
function toggleCommentPositionMode(enable) {
const container = viewContainer.value;
if (!container) return; // sécurité
if (enable) {
waitingForCommentPosition.value = true;
container.classList.add('waiting-comment');
container.addEventListener('click', handleCommentPositionClick);
} else {
waitingForCommentPosition.value = false;
container.classList.remove('waiting-comment');
container.removeEventListener('click', handleCommentPositionClick);
}
}
function prepareDraftCommentInPdf(event) {
const pageContainer = event.target.closest('.page-inner-container');
if (!pageContainer || !viewContainer) return;
@ -287,7 +292,10 @@ function prepareDraftCommentInPdf(event) {
.getAttribute('aria-label');
const pageIndex = pageLabel.charAt(pageLabel.length - 1);
const viewRect = viewContainer.getBoundingClientRect();
const container = viewContainer.value;
if (!container) return;
const viewRect = container.getBoundingClientRect();
const pageRect = pageContainer.getBoundingClientRect();
const pageScroll = viewRect.top - pageRect.top;
@ -310,7 +318,9 @@ function prepareDraftCommentInPdf(event) {
function prepareDraftCommentInImage(event) {
if (!viewContainer) return;
const imageRect = viewContainer.getBoundingClientRect();
const container = viewContainer.value;
if (!container) return; // sécurité
const imageRect = container.getBoundingClientRect();
const mouseTop = event.clientY;
const mouseLeft = event.clientX;
@ -339,4 +349,11 @@ function showCorrespondingView() {
(file) => file.uuid === openedComment.value.location.file.uuid
);
}
onBeforeUnmount(() => {
const container = viewContainer.value;
if (container) {
container.removeEventListener('click', handleCommentPositionClick);
}
});
</script>