feat: Adds the ability to resize the editor (#13916)
# Pull Request Template ## Description This PR adds support for resizing the reply editor up to nearly half the screen height. It also deprecates the old modal-based pop-out reply box, clicking the same button now expands the editor inline. Users can adjust the height using the slider or the expand button. ## Type of change - [x] New feature (non-breaking change which adds functionality) ## How Has This Been Tested? ### Loom video https://www.loom.com/share/be27e1c06d19475ab404289710b3b0da ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: Pranav <pranav@chatwoot.com>
This commit is contained in:
parent
98cf1ce9f6
commit
b5264a2560
@ -57,7 +57,7 @@ useKeyboardEvents(keyboardEvents);
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<ButtonGroup
|
<ButtonGroup
|
||||||
class="flex flex-col justify-center items-center absolute top-36 xl:top-24 ltr:right-2 rtl:left-2 bg-n-solid-2/90 backdrop-blur-lg border border-n-weak/50 rounded-full gap-1.5 p-1.5 shadow-sm transition-shadow duration-200 hover:shadow"
|
class="flex flex-col justify-center items-center absolute top-36 xl:top-24 ltr:right-2 rtl:left-2 bg-n-solid-2/90 backdrop-blur-lg border border-n-weak/50 rounded-full gap-1.5 p-1.5 shadow-sm transition-shadow duration-200 hover:shadow !z-20"
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
v-tooltip.top="$t('CONVERSATION.SIDEBAR.CONTACT')"
|
v-tooltip.top="$t('CONVERSATION.SIDEBAR.CONTACT')"
|
||||||
|
|||||||
@ -27,10 +27,6 @@ const props = defineProps({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true,
|
default: true,
|
||||||
},
|
},
|
||||||
isPopout: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits([
|
const emit = defineEmits([
|
||||||
@ -208,10 +204,7 @@ onMounted(() => {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="space-y-2 mb-4">
|
<div class="space-y-2 mb-4">
|
||||||
<div
|
<div class="overflow-y-auto max-h-56">
|
||||||
class="overflow-y-auto"
|
|
||||||
:class="{ 'max-h-96': isPopout, 'max-h-56': !isPopout }"
|
|
||||||
>
|
|
||||||
<p
|
<p
|
||||||
v-dompurify-html="formatMessage(generatedContent, false)"
|
v-dompurify-html="formatMessage(generatedContent, false)"
|
||||||
class="text-n-iris-12 text-sm prose-sm font-normal !mb-4"
|
class="text-n-iris-12 text-sm prose-sm font-normal !mb-4"
|
||||||
|
|||||||
@ -984,7 +984,32 @@ useEmitter(BUS_EVENTS.INSERT_INTO_RICH_EDITOR, insertContentIntoEditor);
|
|||||||
}
|
}
|
||||||
|
|
||||||
.ProseMirror-woot-style {
|
.ProseMirror-woot-style {
|
||||||
@apply overflow-auto min-h-[5rem] max-h-[7.5rem];
|
@apply overflow-auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ProseMirror-woot-style:not(
|
||||||
|
:where(.resizable-editor-wrapper .ProseMirror-woot-style)
|
||||||
|
) {
|
||||||
|
@apply min-h-[5rem] max-h-[7.5rem];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resizable editor wrapper styles
|
||||||
|
.resizable-editor-wrapper {
|
||||||
|
.ProseMirror-woot-style {
|
||||||
|
min-height: clamp(
|
||||||
|
var(--editor-min-allowed, var(--editor-min-height, 5rem)),
|
||||||
|
var(--editor-height, var(--editor-min-height, 5rem)),
|
||||||
|
var(--editor-max-allowed, var(--editor-max-height, 7.5rem))
|
||||||
|
);
|
||||||
|
max-height: clamp(
|
||||||
|
var(--editor-min-allowed, var(--editor-min-height, 5rem)),
|
||||||
|
var(--editor-height, var(--editor-min-height, 5rem)),
|
||||||
|
var(--editor-max-allowed, var(--editor-max-height, 7.5rem))
|
||||||
|
);
|
||||||
|
transition:
|
||||||
|
min-height var(--editor-height-transition, 180ms ease),
|
||||||
|
max-height var(--editor-height-transition, 180ms ease);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.ProseMirror-prompt-backdrop::backdrop {
|
.ProseMirror-prompt-backdrop::backdrop {
|
||||||
|
|||||||
@ -54,7 +54,7 @@ export default {
|
|||||||
default: undefined,
|
default: undefined,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
emits: ['setReplyMode', 'togglePopout', 'executeCopilotAction'],
|
emits: ['setReplyMode', 'toggleEditorSize', 'executeCopilotAction'],
|
||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
const setReplyMode = mode => {
|
const setReplyMode = mode => {
|
||||||
emit('setReplyMode', mode);
|
emit('setReplyMode', mode);
|
||||||
@ -189,7 +189,7 @@ export default {
|
|||||||
class="text-n-slate-11"
|
class="text-n-slate-11"
|
||||||
sm
|
sm
|
||||||
icon="i-lucide-maximize-2"
|
icon="i-lucide-maximize-2"
|
||||||
@click="$emit('togglePopout')"
|
@click="$emit('toggleEditorSize')"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -16,10 +16,6 @@ defineProps({
|
|||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
isPopout: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits([
|
const emit = defineEmits([
|
||||||
@ -69,7 +65,6 @@ const onSend = () => {
|
|||||||
:generated-content="generatedContent"
|
:generated-content="generatedContent"
|
||||||
:min-height="4"
|
:min-height="4"
|
||||||
:enabled-menu-options="[]"
|
:enabled-menu-options="[]"
|
||||||
:is-popout="isPopout"
|
|
||||||
@focus="onFocus"
|
@focus="onFocus"
|
||||||
@blur="onBlur"
|
@blur="onBlur"
|
||||||
@clear-selection="clearEditorSelection"
|
@clear-selection="clearEditorSelection"
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import { ref, provide } from 'vue';
|
import { ref, provide, useTemplateRef } from 'vue';
|
||||||
|
import { useElementSize } from '@vueuse/core';
|
||||||
// composable
|
// composable
|
||||||
import { useKeyboardEvents } from 'dashboard/composables/useKeyboardEvents';
|
|
||||||
import { useLabelSuggestions } from 'dashboard/composables/useLabelSuggestions';
|
import { useLabelSuggestions } from 'dashboard/composables/useLabelSuggestions';
|
||||||
import { useSnakeCase } from 'dashboard/composables/useTransformKeys';
|
import { useSnakeCase } from 'dashboard/composables/useTransformKeys';
|
||||||
|
|
||||||
@ -11,6 +11,7 @@ import MessageList from 'next/message/MessageList.vue';
|
|||||||
import ConversationLabelSuggestion from './conversation/LabelSuggestion.vue';
|
import ConversationLabelSuggestion from './conversation/LabelSuggestion.vue';
|
||||||
import Banner from 'dashboard/components/ui/Banner.vue';
|
import Banner from 'dashboard/components/ui/Banner.vue';
|
||||||
import Spinner from 'dashboard/components-next/spinner/Spinner.vue';
|
import Spinner from 'dashboard/components-next/spinner/Spinner.vue';
|
||||||
|
import ResizableEditorWrapper from './ResizableEditorWrapper.vue';
|
||||||
|
|
||||||
// stores and apis
|
// stores and apis
|
||||||
import { mapGetters } from 'vuex';
|
import { mapGetters } from 'vuex';
|
||||||
@ -43,21 +44,16 @@ export default {
|
|||||||
Banner,
|
Banner,
|
||||||
ConversationLabelSuggestion,
|
ConversationLabelSuggestion,
|
||||||
Spinner,
|
Spinner,
|
||||||
|
ResizableEditorWrapper,
|
||||||
},
|
},
|
||||||
mixins: [inboxMixin],
|
mixins: [inboxMixin],
|
||||||
setup() {
|
setup() {
|
||||||
const isPopOutReplyBox = ref(false);
|
|
||||||
const conversationPanelRef = ref(null);
|
const conversationPanelRef = ref(null);
|
||||||
|
const resizableEditorWrapperRef = ref(null);
|
||||||
const keyboardEvents = {
|
const messagesViewRef = useTemplateRef('messagesViewRef');
|
||||||
Escape: {
|
const topBannerRef = useTemplateRef('topBannerRef');
|
||||||
action: () => {
|
const { height: containerHeight } = useElementSize(messagesViewRef);
|
||||||
isPopOutReplyBox.value = false;
|
const { height: topBannerHeight } = useElementSize(topBannerRef);
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
useKeyboardEvents(keyboardEvents);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
captainTasksEnabled,
|
captainTasksEnabled,
|
||||||
@ -68,11 +64,15 @@ export default {
|
|||||||
provide('contextMenuElementTarget', conversationPanelRef);
|
provide('contextMenuElementTarget', conversationPanelRef);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isPopOutReplyBox,
|
|
||||||
captainTasksEnabled,
|
captainTasksEnabled,
|
||||||
getLabelSuggestions,
|
getLabelSuggestions,
|
||||||
isLabelSuggestionFeatureEnabled,
|
isLabelSuggestionFeatureEnabled,
|
||||||
conversationPanelRef,
|
conversationPanelRef,
|
||||||
|
resizableEditorWrapperRef,
|
||||||
|
messagesViewRef,
|
||||||
|
topBannerRef,
|
||||||
|
containerHeight,
|
||||||
|
topBannerHeight,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
@ -254,6 +254,7 @@ export default {
|
|||||||
this.fetchAllAttachmentsFromCurrentChat();
|
this.fetchAllAttachmentsFromCurrentChat();
|
||||||
this.fetchSuggestions();
|
this.fetchSuggestions();
|
||||||
this.messageSentSinceOpened = false;
|
this.messageSentSinceOpened = false;
|
||||||
|
this.resetReplyEditorHeight();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -437,26 +438,37 @@ export default {
|
|||||||
const payload = useSnakeCase(message);
|
const payload = useSnakeCase(message);
|
||||||
await this.$store.dispatch('sendMessageWithData', payload);
|
await this.$store.dispatch('sendMessageWithData', payload);
|
||||||
},
|
},
|
||||||
|
toggleReplyEditorSize() {
|
||||||
|
this.resizableEditorWrapperRef?.toggleEditorExpand?.();
|
||||||
|
},
|
||||||
|
resetReplyEditorHeight() {
|
||||||
|
this.resizableEditorWrapperRef?.resetEditorHeight?.();
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col justify-between flex-grow h-full min-w-0 m-0">
|
<div
|
||||||
<Banner
|
ref="messagesViewRef"
|
||||||
v-if="!currentChat.can_reply"
|
class="flex flex-col justify-between flex-grow h-full min-w-0 m-0"
|
||||||
color-scheme="alert"
|
>
|
||||||
class="mx-2 mt-2 overflow-hidden rounded-lg"
|
<div ref="topBannerRef">
|
||||||
:banner-message="replyWindowBannerMessage"
|
<Banner
|
||||||
:href-link="replyWindowLink"
|
v-if="!currentChat.can_reply"
|
||||||
:href-link-text="replyWindowLinkText"
|
color-scheme="alert"
|
||||||
/>
|
class="mx-2 mt-2 overflow-hidden rounded-lg"
|
||||||
<Banner
|
:banner-message="replyWindowBannerMessage"
|
||||||
v-else-if="hasDuplicateInstagramInbox"
|
:href-link="replyWindowLink"
|
||||||
color-scheme="alert"
|
:href-link-text="replyWindowLinkText"
|
||||||
class="mx-2 mt-2 overflow-hidden rounded-lg"
|
/>
|
||||||
:banner-message="$t('CONVERSATION.OLD_INSTAGRAM_INBOX_REPLY_BANNER')"
|
<Banner
|
||||||
/>
|
v-else-if="hasDuplicateInstagramInbox"
|
||||||
|
color-scheme="alert"
|
||||||
|
class="mx-2 mt-2 overflow-hidden rounded-lg"
|
||||||
|
:banner-message="$t('CONVERSATION.OLD_INSTAGRAM_INBOX_REPLY_BANNER')"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<MessageList
|
<MessageList
|
||||||
ref="conversationPanelRef"
|
ref="conversationPanelRef"
|
||||||
class="conversation-panel flex-shrink flex-grow basis-px flex flex-col overflow-y-auto relative h-full m-0 pb-4"
|
class="conversation-panel flex-shrink flex-grow basis-px flex flex-col overflow-y-auto relative h-full m-0 pb-4"
|
||||||
@ -498,13 +510,7 @@ export default {
|
|||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</MessageList>
|
</MessageList>
|
||||||
<div
|
<div class="flex relative flex-col bg-n-surface-1">
|
||||||
class="flex relative flex-col"
|
|
||||||
:class="{
|
|
||||||
'modal-mask': isPopOutReplyBox,
|
|
||||||
'bg-n-surface-1': !isPopOutReplyBox,
|
|
||||||
}"
|
|
||||||
>
|
|
||||||
<div
|
<div
|
||||||
v-if="isAnyoneTyping"
|
v-if="isAnyoneTyping"
|
||||||
class="absolute flex items-center w-full h-0 -top-7"
|
class="absolute flex items-center w-full h-0 -top-7"
|
||||||
@ -520,42 +526,12 @@ export default {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<ReplyBox
|
<ResizableEditorWrapper
|
||||||
:pop-out-reply-box="isPopOutReplyBox"
|
ref="resizableEditorWrapperRef"
|
||||||
@update:pop-out-reply-box="isPopOutReplyBox = $event"
|
:container-height="Math.max(0, containerHeight - topBannerHeight)"
|
||||||
/>
|
>
|
||||||
|
<ReplyBox @toggle-editor-size="toggleReplyEditorSize" />
|
||||||
|
</ResizableEditorWrapper>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
|
||||||
.modal-mask {
|
|
||||||
@apply fixed;
|
|
||||||
|
|
||||||
&::v-deep {
|
|
||||||
.ProseMirror-woot-style {
|
|
||||||
@apply max-h-[25rem];
|
|
||||||
}
|
|
||||||
|
|
||||||
.reply-box {
|
|
||||||
@apply border border-n-weak max-w-[75rem] w-[70%];
|
|
||||||
|
|
||||||
&.is-private {
|
|
||||||
@apply dark:border-n-amber-3/30 border-n-amber-12/5;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.reply-box .reply-box__top {
|
|
||||||
@apply relative min-h-[27.5rem];
|
|
||||||
}
|
|
||||||
|
|
||||||
.reply-box__top .input {
|
|
||||||
@apply min-h-[27.5rem];
|
|
||||||
}
|
|
||||||
|
|
||||||
.emoji-dialog {
|
|
||||||
@apply absolute ltr:left-auto rtl:right-auto bottom-1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|||||||
@ -81,13 +81,7 @@ export default {
|
|||||||
CopilotReplyBottomPanel,
|
CopilotReplyBottomPanel,
|
||||||
},
|
},
|
||||||
mixins: [inboxMixin, fileUploadMixin, keyboardEventListenerMixins],
|
mixins: [inboxMixin, fileUploadMixin, keyboardEventListenerMixins],
|
||||||
props: {
|
emits: ['toggleEditorSize'],
|
||||||
popOutReplyBox: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
emits: ['update:popOutReplyBox'],
|
|
||||||
setup() {
|
setup() {
|
||||||
const {
|
const {
|
||||||
uiSettings,
|
uiSettings,
|
||||||
@ -797,7 +791,6 @@ export default {
|
|||||||
|
|
||||||
this.clearMessage();
|
this.clearMessage();
|
||||||
this.hideEmojiPicker();
|
this.hideEmojiPicker();
|
||||||
this.$emit('update:popOutReplyBox', false);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
sendMessageAsMultipleMessages(message, copilotAcceptedMessage = '') {
|
sendMessageAsMultipleMessages(message, copilotAcceptedMessage = '') {
|
||||||
@ -1217,8 +1210,9 @@ export default {
|
|||||||
file => !file?.isRecordedAudio
|
file => !file?.isRecordedAudio
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
togglePopout() {
|
toggleEditorSize() {
|
||||||
this.$emit('update:popOutReplyBox', !this.popOutReplyBox);
|
this.$emit('toggleEditorSize');
|
||||||
|
this.$nextTick(() => this.messageEditor?.focusEditorInputField());
|
||||||
},
|
},
|
||||||
onSubmitCopilotReply() {
|
onSubmitCopilotReply() {
|
||||||
const acceptedMessage = this.copilot.accept();
|
const acceptedMessage = this.copilot.accept();
|
||||||
@ -1244,9 +1238,8 @@ export default {
|
|||||||
:is-message-length-reaching-threshold="isMessageLengthReachingThreshold"
|
:is-message-length-reaching-threshold="isMessageLengthReachingThreshold"
|
||||||
:characters-remaining="charactersRemaining"
|
:characters-remaining="charactersRemaining"
|
||||||
:editor-content="message"
|
:editor-content="message"
|
||||||
:popout-reply-box="popOutReplyBox"
|
|
||||||
@set-reply-mode="setReplyMode"
|
@set-reply-mode="setReplyMode"
|
||||||
@toggle-popout="togglePopout"
|
@toggle-editor-size="toggleEditorSize"
|
||||||
@toggle-copilot="copilot.toggleEditor"
|
@toggle-copilot="copilot.toggleEditor"
|
||||||
@execute-copilot-action="executeCopilotAction"
|
@execute-copilot-action="executeCopilotAction"
|
||||||
/>
|
/>
|
||||||
@ -1275,7 +1268,7 @@ export default {
|
|||||||
v-if="showEmojiPicker"
|
v-if="showEmojiPicker"
|
||||||
v-on-clickaway="hideEmojiPicker"
|
v-on-clickaway="hideEmojiPicker"
|
||||||
:class="{
|
:class="{
|
||||||
'emoji-dialog--expanded': isOnExpandedLayout || popOutReplyBox,
|
'emoji-dialog--expanded': isOnExpandedLayout,
|
||||||
}"
|
}"
|
||||||
:on-click="addIntoEditor"
|
:on-click="addIntoEditor"
|
||||||
/>
|
/>
|
||||||
@ -1299,7 +1292,6 @@ export default {
|
|||||||
:show-copilot-editor="copilot.showEditor.value"
|
:show-copilot-editor="copilot.showEditor.value"
|
||||||
:is-generating-content="copilot.isGenerating.value"
|
:is-generating-content="copilot.isGenerating.value"
|
||||||
:generated-content="copilot.generatedContent.value"
|
:generated-content="copilot.generatedContent.value"
|
||||||
:is-popout="popOutReplyBox"
|
|
||||||
:placeholder="$t('CONVERSATION.FOOTER.COPILOT_MSG_INPUT')"
|
:placeholder="$t('CONVERSATION.FOOTER.COPILOT_MSG_INPUT')"
|
||||||
@focus="onFocus"
|
@focus="onFocus"
|
||||||
@blur="onBlur"
|
@blur="onBlur"
|
||||||
|
|||||||
@ -0,0 +1,154 @@
|
|||||||
|
<script setup>
|
||||||
|
import { ref, computed, onMounted, onBeforeUnmount, useTemplateRef } from 'vue';
|
||||||
|
import { useEventListener } from '@vueuse/core';
|
||||||
|
import { emitter } from 'shared/helpers/mitt';
|
||||||
|
import { BUS_EVENTS } from 'shared/constants/busEvents';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
containerHeight: { type: Number, default: 0 },
|
||||||
|
});
|
||||||
|
|
||||||
|
const DEFAULT_HEIGHT = 120;
|
||||||
|
const MIN_HEIGHT = 80;
|
||||||
|
const MIN_MESSAGES_HEIGHT = 200;
|
||||||
|
const EXPAND_RATIO = 0.5;
|
||||||
|
const RESET_DELAY_MS = 120;
|
||||||
|
|
||||||
|
const wrapperRef = useTemplateRef('wrapperRef');
|
||||||
|
const surroundingHeight = ref(0);
|
||||||
|
const editorHeight = ref(DEFAULT_HEIGHT);
|
||||||
|
const isResizing = ref(false);
|
||||||
|
const startY = ref(0);
|
||||||
|
const startHeight = ref(0);
|
||||||
|
let resetTimeoutId = null;
|
||||||
|
|
||||||
|
const clamp = (val, min, max) => Math.min(Math.max(val, min), max);
|
||||||
|
|
||||||
|
// Measure height of elements surrounding the editor (top panel, email fields, bottom panel)
|
||||||
|
const measureSurroundingHeight = () => {
|
||||||
|
if (wrapperRef.value) {
|
||||||
|
surroundingHeight.value = Math.max(
|
||||||
|
0,
|
||||||
|
wrapperRef.value.offsetHeight - editorHeight.value
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const isContainerReady = computed(() => props.containerHeight > 0);
|
||||||
|
|
||||||
|
const sizeBounds = computed(() => {
|
||||||
|
const h = props.containerHeight;
|
||||||
|
const s = surroundingHeight.value;
|
||||||
|
const max = Math.max(MIN_HEIGHT, h - MIN_MESSAGES_HEIGHT - s);
|
||||||
|
const expanded = clamp(Math.floor(h * EXPAND_RATIO - s / 2), MIN_HEIGHT, max);
|
||||||
|
return {
|
||||||
|
min: MIN_HEIGHT,
|
||||||
|
max: isContainerReady.value ? max : DEFAULT_HEIGHT,
|
||||||
|
expanded,
|
||||||
|
default: clamp(DEFAULT_HEIGHT, MIN_HEIGHT, max),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const clampToBounds = val =>
|
||||||
|
clamp(val, sizeBounds.value.min, sizeBounds.value.max);
|
||||||
|
|
||||||
|
const clearDragStyles = () => {
|
||||||
|
Object.assign(document.body.style, { cursor: '', userSelect: '' });
|
||||||
|
};
|
||||||
|
|
||||||
|
const getClientY = e => (e.touches ? e.touches[0].clientY : e.clientY);
|
||||||
|
|
||||||
|
const onResizeStart = event => {
|
||||||
|
editorHeight.value = clampToBounds(editorHeight.value);
|
||||||
|
measureSurroundingHeight();
|
||||||
|
isResizing.value = true;
|
||||||
|
startY.value = getClientY(event);
|
||||||
|
startHeight.value = clampToBounds(editorHeight.value);
|
||||||
|
editorHeight.value = startHeight.value;
|
||||||
|
Object.assign(document.body.style, {
|
||||||
|
cursor: 'row-resize',
|
||||||
|
userSelect: 'none',
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onResizeMove = event => {
|
||||||
|
if (!isResizing.value) return;
|
||||||
|
if (event.touches) event.preventDefault();
|
||||||
|
editorHeight.value = clampToBounds(
|
||||||
|
startHeight.value + startY.value - getClientY(event)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onResizeEnd = () => {
|
||||||
|
if (!isResizing.value) return;
|
||||||
|
isResizing.value = false;
|
||||||
|
clearDragStyles();
|
||||||
|
};
|
||||||
|
|
||||||
|
const resetEditorHeight = () => {
|
||||||
|
editorHeight.value = sizeBounds.value.default;
|
||||||
|
};
|
||||||
|
|
||||||
|
const toggleEditorExpand = () => {
|
||||||
|
editorHeight.value = clampToBounds(editorHeight.value);
|
||||||
|
measureSurroundingHeight();
|
||||||
|
const { expanded, max, default: defaultHeight } = sizeBounds.value;
|
||||||
|
const isExpanded = editorHeight.value > defaultHeight;
|
||||||
|
// If expanded is too close to default, use max so the toggle is always noticeable
|
||||||
|
const target = expanded - defaultHeight < 100 ? max : expanded;
|
||||||
|
editorHeight.value = isExpanded ? defaultHeight : target;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMessageSent = () => {
|
||||||
|
clearTimeout(resetTimeoutId);
|
||||||
|
resetTimeoutId = setTimeout(resetEditorHeight, RESET_DELAY_MS);
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
emitter.on(BUS_EVENTS.MESSAGE_SENT, handleMessageSent);
|
||||||
|
});
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
emitter.off(BUS_EVENTS.MESSAGE_SENT, handleMessageSent);
|
||||||
|
clearTimeout(resetTimeoutId);
|
||||||
|
if (isResizing.value) {
|
||||||
|
isResizing.value = false;
|
||||||
|
clearDragStyles();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
useEventListener(document, 'mousemove', onResizeMove);
|
||||||
|
useEventListener(document, 'mouseup', onResizeEnd);
|
||||||
|
useEventListener(document, 'touchmove', onResizeMove, { passive: false });
|
||||||
|
useEventListener(document, 'touchend', onResizeEnd);
|
||||||
|
useEventListener(document, 'touchcancel', onResizeEnd);
|
||||||
|
useEventListener(window, 'blur', onResizeEnd);
|
||||||
|
|
||||||
|
defineExpose({ toggleEditorExpand, resetEditorHeight });
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div
|
||||||
|
ref="wrapperRef"
|
||||||
|
class="relative resizable-editor-wrapper"
|
||||||
|
:style="{
|
||||||
|
'--editor-height': editorHeight + 'px',
|
||||||
|
'--editor-min-allowed': sizeBounds.min + 'px',
|
||||||
|
'--editor-max-allowed': sizeBounds.max + 'px',
|
||||||
|
'--editor-height-transition': isResizing ? 'none' : '180ms ease',
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="group absolute inset-x-0 -top-4 z-10 flex h-4 cursor-row-resize select-none items-center justify-center bg-gradient-to-b from-transparent from-10% dark:to-n-surface-1/80 to-n-surface-1/90 backdrop-blur-[0.01875rem]"
|
||||||
|
@mousedown="onResizeStart"
|
||||||
|
@touchstart.prevent="onResizeStart"
|
||||||
|
@dblclick="resetEditorHeight"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="w-8 h-0.5 mt-1 rounded-full bg-n-slate-6 group-hover:bg-n-slate-8 transition-all duration-200 motion-safe:group-hover:animate-bounce"
|
||||||
|
:class="{ 'bg-n-slate-8 animate-bounce': isResizing }"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
Loading…
Reference in New Issue
Block a user