feat: Scroll lock on message context menu (#11454)
This PR uses `useScrollLock` from `VueUse` to lock scrolling on the conversation panel when the message context menu is open.
This commit is contained in:
@@ -315,11 +315,7 @@ const componentToRender = computed(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const shouldShowContextMenu = computed(() => {
|
const shouldShowContextMenu = computed(() => {
|
||||||
return !(
|
return !props.contentAttributes?.isUnsupported;
|
||||||
props.status === MESSAGE_STATUS.FAILED ||
|
|
||||||
props.status === MESSAGE_STATUS.PROGRESS ||
|
|
||||||
props.contentAttributes?.isUnsupported
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const isBubble = computed(() => {
|
const isBubble = computed(() => {
|
||||||
@@ -344,12 +340,23 @@ const contextMenuEnabledOptions = computed(() => {
|
|||||||
const hasAttachments = !!(props.attachments && props.attachments.length > 0);
|
const hasAttachments = !!(props.attachments && props.attachments.length > 0);
|
||||||
|
|
||||||
const isOutgoing = props.messageType === MESSAGE_TYPES.OUTGOING;
|
const isOutgoing = props.messageType === MESSAGE_TYPES.OUTGOING;
|
||||||
|
const isFailedOrProcessing =
|
||||||
|
props.status === MESSAGE_STATUS.FAILED ||
|
||||||
|
props.status === MESSAGE_STATUS.PROGRESS;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
copy: hasText,
|
copy: hasText,
|
||||||
delete: hasText || hasAttachments,
|
delete:
|
||||||
cannedResponse: isOutgoing && hasText,
|
(hasText || hasAttachments) &&
|
||||||
replyTo: !props.private && props.inboxSupportsReplyTo.outgoing,
|
!isFailedOrProcessing &&
|
||||||
|
!isMessageDeleted.value,
|
||||||
|
cannedResponse: isOutgoing && hasText && !isMessageDeleted.value,
|
||||||
|
copyLink: !isFailedOrProcessing,
|
||||||
|
translate: !isFailedOrProcessing && !isMessageDeleted.value && hasText,
|
||||||
|
replyTo:
|
||||||
|
!props.private &&
|
||||||
|
props.inboxSupportsReplyTo.outgoing &&
|
||||||
|
!isFailedOrProcessing,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -499,8 +506,8 @@ provideMessageContext({
|
|||||||
<div
|
<div
|
||||||
class="[grid-area:bubble] flex"
|
class="[grid-area:bubble] flex"
|
||||||
:class="{
|
:class="{
|
||||||
'ltr:pl-8 rtl:pr-8 justify-end': orientation === ORIENTATION.RIGHT,
|
'ltr:ml-8 rtl:mr-8 justify-end': orientation === ORIENTATION.RIGHT,
|
||||||
'ltr:pr-8 rtl:pl-8': orientation === ORIENTATION.LEFT,
|
'ltr:mr-8 rtl:ml-8': orientation === ORIENTATION.LEFT,
|
||||||
'min-w-0': variant === MESSAGE_VARIANTS.EMAIL,
|
'min-w-0': variant === MESSAGE_VARIANTS.EMAIL,
|
||||||
}"
|
}"
|
||||||
@contextmenu="openContextMenu($event)"
|
@contextmenu="openContextMenu($event)"
|
||||||
@@ -516,7 +523,7 @@ provideMessageContext({
|
|||||||
</div>
|
</div>
|
||||||
<div v-if="shouldShowContextMenu" class="context-menu-wrap">
|
<div v-if="shouldShowContextMenu" class="context-menu-wrap">
|
||||||
<ContextMenu
|
<ContextMenu
|
||||||
v-if="isBubble && !isMessageDeleted"
|
v-if="isBubble"
|
||||||
:context-menu-position="contextMenuPosition"
|
:context-menu-position="contextMenuPosition"
|
||||||
:is-open="showContextMenu"
|
:is-open="showContextMenu"
|
||||||
:enabled-options="contextMenuEnabledOptions"
|
:enabled-options="contextMenuEnabledOptions"
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import {
|
|||||||
computed,
|
computed,
|
||||||
watch,
|
watch,
|
||||||
onMounted,
|
onMounted,
|
||||||
onUnmounted,
|
|
||||||
defineEmits,
|
defineEmits,
|
||||||
} from 'vue';
|
} from 'vue';
|
||||||
import { useStore } from 'vuex';
|
import { useStore } from 'vuex';
|
||||||
@@ -44,7 +43,7 @@ import {
|
|||||||
useSnakeCase,
|
useSnakeCase,
|
||||||
} from 'dashboard/composables/useTransformKeys';
|
} from 'dashboard/composables/useTransformKeys';
|
||||||
import { useEmitter } from 'dashboard/composables/emitter';
|
import { useEmitter } from 'dashboard/composables/emitter';
|
||||||
import { useEventListener, useScrollLock } from '@vueuse/core';
|
import { useEventListener } from '@vueuse/core';
|
||||||
|
|
||||||
import { emitter } from 'shared/helpers/mitt';
|
import { emitter } from 'shared/helpers/mitt';
|
||||||
|
|
||||||
@@ -87,12 +86,8 @@ const store = useStore();
|
|||||||
|
|
||||||
const conversationListRef = ref(null);
|
const conversationListRef = ref(null);
|
||||||
const conversationDynamicScroller = ref(null);
|
const conversationDynamicScroller = ref(null);
|
||||||
const conversationListScrollableElement = computed(
|
|
||||||
() => conversationDynamicScroller.value?.$el
|
provide('contextMenuElementTarget', conversationDynamicScroller);
|
||||||
);
|
|
||||||
const conversationListScrollLock = useScrollLock(
|
|
||||||
conversationListScrollableElement
|
|
||||||
);
|
|
||||||
|
|
||||||
const activeAssigneeTab = ref(wootConstants.ASSIGNEE_TYPE.ME);
|
const activeAssigneeTab = ref(wootConstants.ASSIGNEE_TYPE.ME);
|
||||||
const activeStatus = ref(wootConstants.STATUS_TYPE.OPEN);
|
const activeStatus = ref(wootConstants.STATUS_TYPE.OPEN);
|
||||||
@@ -746,7 +741,6 @@ function allSelectedConversationsStatus(status) {
|
|||||||
|
|
||||||
function onContextMenuToggle(state) {
|
function onContextMenuToggle(state) {
|
||||||
isContextMenuOpen.value = state;
|
isContextMenuOpen.value = state;
|
||||||
conversationListScrollLock.value = state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleSelectAll(check) {
|
function toggleSelectAll(check) {
|
||||||
@@ -770,10 +764,6 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
onUnmounted(() => {
|
|
||||||
conversationListScrollLock.value = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
provide('selectConversation', selectConversation);
|
provide('selectConversation', selectConversation);
|
||||||
provide('deSelectConversation', deSelectConversation);
|
provide('deSelectConversation', deSelectConversation);
|
||||||
provide('assignAgent', onAssignAgent);
|
provide('assignAgent', onAssignAgent);
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { computed, onMounted, nextTick, useTemplateRef } from 'vue';
|
import {
|
||||||
import { useWindowSize, useElementBounding } from '@vueuse/core';
|
computed,
|
||||||
|
onMounted,
|
||||||
|
nextTick,
|
||||||
|
onUnmounted,
|
||||||
|
useTemplateRef,
|
||||||
|
inject,
|
||||||
|
} from 'vue';
|
||||||
|
import { useWindowSize, useElementBounding, useScrollLock } from '@vueuse/core';
|
||||||
|
|
||||||
import TeleportWithDirection from 'dashboard/components-next/TeleportWithDirection.vue';
|
import TeleportWithDirection from 'dashboard/components-next/TeleportWithDirection.vue';
|
||||||
|
|
||||||
@@ -11,27 +18,34 @@ const props = defineProps({
|
|||||||
|
|
||||||
const emit = defineEmits(['close']);
|
const emit = defineEmits(['close']);
|
||||||
|
|
||||||
|
const elementToLock = inject('contextMenuElementTarget', null);
|
||||||
|
|
||||||
const menuRef = useTemplateRef('menuRef');
|
const menuRef = useTemplateRef('menuRef');
|
||||||
|
|
||||||
|
const scrollLockElement = computed(() => {
|
||||||
|
if (!elementToLock?.value) return null;
|
||||||
|
return elementToLock.value?.$el;
|
||||||
|
});
|
||||||
|
|
||||||
|
const isLocked = useScrollLock(scrollLockElement);
|
||||||
|
|
||||||
const { width: windowWidth, height: windowHeight } = useWindowSize();
|
const { width: windowWidth, height: windowHeight } = useWindowSize();
|
||||||
const { width: menuWidth, height: menuHeight } = useElementBounding(menuRef);
|
const { width: menuWidth, height: menuHeight } = useElementBounding(menuRef);
|
||||||
|
|
||||||
const calculatePosition = (x, y, menuW, menuH, windowW, windowH) => {
|
const calculatePosition = (x, y, menuW, menuH, windowW, windowH) => {
|
||||||
|
const PADDING = 16;
|
||||||
// Initial position
|
// Initial position
|
||||||
let left = x;
|
let left = x;
|
||||||
let top = y;
|
let top = y;
|
||||||
|
|
||||||
// Boundary checks
|
// Boundary checks
|
||||||
const isOverflowingRight = left + menuW > windowW;
|
const isOverflowingRight = left + menuW > windowW - PADDING;
|
||||||
const isOverflowingBottom = top + menuH > windowH;
|
const isOverflowingBottom = top + menuH > windowH - PADDING;
|
||||||
|
|
||||||
// Adjust position if overflowing
|
// Adjust position if overflowing
|
||||||
if (isOverflowingRight) left = windowW - menuW;
|
if (isOverflowingRight) left = windowW - menuW - PADDING;
|
||||||
if (isOverflowingBottom) top = windowH - menuH;
|
if (isOverflowingBottom) top = windowH - menuH - PADDING;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
left: Math.max(0, left),
|
left: Math.max(PADDING, left),
|
||||||
top: Math.max(0, top),
|
top: Math.max(PADDING, top),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -54,8 +68,18 @@ const position = computed(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
isLocked.value = true;
|
||||||
nextTick(() => menuRef.value?.focus());
|
nextTick(() => menuRef.value?.focus());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
isLocked.value = false;
|
||||||
|
emit('close');
|
||||||
|
};
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
isLocked.value = false;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -65,7 +89,7 @@ onMounted(() => {
|
|||||||
class="fixed outline-none z-[9999] cursor-pointer"
|
class="fixed outline-none z-[9999] cursor-pointer"
|
||||||
:style="position"
|
:style="position"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
@blur="emit('close')"
|
@blur="handleClose"
|
||||||
>
|
>
|
||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -185,8 +185,17 @@ export default {
|
|||||||
contextMenuEnabledOptions() {
|
contextMenuEnabledOptions() {
|
||||||
return {
|
return {
|
||||||
copy: this.hasText,
|
copy: this.hasText,
|
||||||
delete: this.hasText || this.hasAttachments,
|
delete:
|
||||||
cannedResponse: this.isOutgoing && this.hasText,
|
(this.hasText || this.hasAttachments) &&
|
||||||
|
!this.isMessageDeleted &&
|
||||||
|
!this.isFailed,
|
||||||
|
cannedResponse:
|
||||||
|
this.isOutgoing && this.hasText && !this.isMessageDeleted,
|
||||||
|
copyLink: !this.isFailed || !this.isProcessing,
|
||||||
|
translate:
|
||||||
|
(!this.isFailed || !this.isProcessing) &&
|
||||||
|
!this.isMessageDeleted &&
|
||||||
|
this.hasText,
|
||||||
replyTo: !this.data.private && this.inboxSupportsReplyTo.outgoing,
|
replyTo: !this.data.private && this.inboxSupportsReplyTo.outgoing,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -328,7 +337,7 @@ export default {
|
|||||||
return !this.sender.type || this.sender.type === 'agent_bot';
|
return !this.sender.type || this.sender.type === 'agent_bot';
|
||||||
},
|
},
|
||||||
shouldShowContextMenu() {
|
shouldShowContextMenu() {
|
||||||
return !(this.isFailed || this.isPending || this.isUnsupported);
|
return !this.isUnsupported;
|
||||||
},
|
},
|
||||||
showAvatar() {
|
showAvatar() {
|
||||||
if (this.isOutgoing || this.isTemplate) {
|
if (this.isOutgoing || this.isTemplate) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script>
|
<script>
|
||||||
import { ref } from 'vue';
|
import { ref, provide } from 'vue';
|
||||||
// composable
|
// composable
|
||||||
import { useConfig } from 'dashboard/composables/useConfig';
|
import { useConfig } from 'dashboard/composables/useConfig';
|
||||||
import { useKeyboardEvents } from 'dashboard/composables/useKeyboardEvents';
|
import { useKeyboardEvents } from 'dashboard/composables/useKeyboardEvents';
|
||||||
@@ -63,6 +63,7 @@ export default {
|
|||||||
emits: ['contactPanelToggle'],
|
emits: ['contactPanelToggle'],
|
||||||
setup() {
|
setup() {
|
||||||
const isPopOutReplyBox = ref(false);
|
const isPopOutReplyBox = ref(false);
|
||||||
|
const conversationPanelRef = ref(null);
|
||||||
const { isEnterprise } = useConfig();
|
const { isEnterprise } = useConfig();
|
||||||
|
|
||||||
const closePopOutReplyBox = () => {
|
const closePopOutReplyBox = () => {
|
||||||
@@ -98,6 +99,8 @@ export default {
|
|||||||
FEATURE_FLAGS.CHATWOOT_V4
|
FEATURE_FLAGS.CHATWOOT_V4
|
||||||
);
|
);
|
||||||
|
|
||||||
|
provide('contextMenuElementTarget', conversationPanelRef);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isEnterprise,
|
isEnterprise,
|
||||||
isPopOutReplyBox,
|
isPopOutReplyBox,
|
||||||
@@ -108,6 +111,7 @@ export default {
|
|||||||
fetchIntegrationsIfRequired,
|
fetchIntegrationsIfRequired,
|
||||||
fetchLabelSuggestions,
|
fetchLabelSuggestions,
|
||||||
showNextBubbles,
|
showNextBubbles,
|
||||||
|
conversationPanelRef,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
@@ -541,6 +545,7 @@ export default {
|
|||||||
</div>
|
</div>
|
||||||
<NextMessageList
|
<NextMessageList
|
||||||
v-if="showNextBubbles"
|
v-if="showNextBubbles"
|
||||||
|
ref="conversationPanelRef"
|
||||||
class="conversation-panel"
|
class="conversation-panel"
|
||||||
:current-user-id="currentUserId"
|
:current-user-id="currentUserId"
|
||||||
:first-unread-id="unReadMessages[0]?.id"
|
:first-unread-id="unReadMessages[0]?.id"
|
||||||
@@ -572,7 +577,7 @@ export default {
|
|||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</NextMessageList>
|
</NextMessageList>
|
||||||
<ul v-else class="conversation-panel">
|
<ul v-else ref="conversationPanelRef" class="conversation-panel">
|
||||||
<transition name="slide-up">
|
<transition name="slide-up">
|
||||||
<!-- eslint-disable-next-line vue/require-toggle-inside-transition -->
|
<!-- eslint-disable-next-line vue/require-toggle-inside-transition -->
|
||||||
<li class="min-h-[4rem]">
|
<li class="min-h-[4rem]">
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ export default {
|
|||||||
emits: ['open', 'close', 'replyTo'],
|
emits: ['open', 'close', 'replyTo'],
|
||||||
setup() {
|
setup() {
|
||||||
const { getPlainText } = useMessageFormatter();
|
const { getPlainText } = useMessageFormatter();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getPlainText,
|
getPlainText,
|
||||||
};
|
};
|
||||||
@@ -167,7 +168,7 @@ export default {
|
|||||||
</woot-modal>
|
</woot-modal>
|
||||||
<!-- Confirm Deletion -->
|
<!-- Confirm Deletion -->
|
||||||
<woot-delete-modal
|
<woot-delete-modal
|
||||||
v-if="showDeleteModal"
|
v-if="showDeleteModal && enabledOptions['delete']"
|
||||||
v-model:show="showDeleteModal"
|
v-model:show="showDeleteModal"
|
||||||
class="context-menu--delete-modal"
|
class="context-menu--delete-modal"
|
||||||
:on-close="closeDeleteModal"
|
:on-close="closeDeleteModal"
|
||||||
@@ -212,7 +213,7 @@ export default {
|
|||||||
@click.stop="handleCopy"
|
@click.stop="handleCopy"
|
||||||
/>
|
/>
|
||||||
<MenuItem
|
<MenuItem
|
||||||
v-if="enabledOptions['copy']"
|
v-if="enabledOptions['translate']"
|
||||||
:option="{
|
:option="{
|
||||||
icon: 'translate',
|
icon: 'translate',
|
||||||
label: $t('CONVERSATION.CONTEXT_MENU.TRANSLATE'),
|
label: $t('CONVERSATION.CONTEXT_MENU.TRANSLATE'),
|
||||||
@@ -222,6 +223,7 @@ export default {
|
|||||||
/>
|
/>
|
||||||
<hr />
|
<hr />
|
||||||
<MenuItem
|
<MenuItem
|
||||||
|
v-if="enabledOptions['copyLink']"
|
||||||
:option="{
|
:option="{
|
||||||
icon: 'link',
|
icon: 'link',
|
||||||
label: $t('CONVERSATION.CONTEXT_MENU.COPY_PERMALINK'),
|
label: $t('CONVERSATION.CONTEXT_MENU.COPY_PERMALINK'),
|
||||||
|
|||||||
Reference in New Issue
Block a user