mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 03:27:52 +00:00
feat: Support image resize in message signature (#8042)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="editor-root">
|
||||
<div ref="editorRoot" class="editor-root relative">
|
||||
<tag-agents
|
||||
v-if="showUserMentions && isPrivate"
|
||||
:search-key="mentionSearchKey"
|
||||
@@ -23,6 +23,23 @@
|
||||
@change="onFileChange"
|
||||
/>
|
||||
<div ref="editor" />
|
||||
<div
|
||||
v-show="isImageNodeSelected && showImageResizeToolbar"
|
||||
class="absolute shadow-md rounded-[4px] flex gap-1 py-1 px-1 bg-slate-50 dark:bg-slate-700 text-slate-800 dark:text-slate-50"
|
||||
:style="{
|
||||
top: toolbarPosition.top,
|
||||
left: toolbarPosition.left,
|
||||
}"
|
||||
>
|
||||
<button
|
||||
v-for="size in sizes"
|
||||
:key="size.name"
|
||||
class="text-xs font-medium rounded-[4px] border border-solid border-slate-200 dark:border-slate-600 px-1.5 py-0.5 hover:bg-slate-100 dark:hover:bg-slate-800"
|
||||
@click="setURLWithQueryAndImageSize(size)"
|
||||
>
|
||||
{{ size.name }}
|
||||
</button>
|
||||
</div>
|
||||
<slot name="footer" />
|
||||
</div>
|
||||
</template>
|
||||
@@ -51,6 +68,8 @@ import {
|
||||
removeSignature,
|
||||
insertAtCursor,
|
||||
scrollCursorIntoView,
|
||||
findNodeToInsertImage,
|
||||
setURLWithQueryAndSize,
|
||||
} from 'dashboard/helper/editorHelper';
|
||||
|
||||
const TYPING_INDICATOR_IDLE_TIME = 4000;
|
||||
@@ -70,8 +89,10 @@ import { CONVERSATION_EVENTS } from '../../../helper/AnalyticsHelper/events';
|
||||
import { checkFileSizeLimit } from 'shared/helpers/FileHelper';
|
||||
import { uploadFile } from 'dashboard/helper/uploadHelper';
|
||||
import alertMixin from 'shared/mixins/alertMixin';
|
||||
import { findNodeToInsertImage } from 'dashboard/helper/messageEditorHelper';
|
||||
import { MESSAGE_EDITOR_MENU_OPTIONS } from 'dashboard/constants/editor';
|
||||
import {
|
||||
MESSAGE_EDITOR_MENU_OPTIONS,
|
||||
MESSAGE_EDITOR_IMAGE_RESIZES,
|
||||
} from 'dashboard/constants/editor';
|
||||
|
||||
const createState = (
|
||||
content,
|
||||
@@ -114,6 +135,7 @@ export default {
|
||||
// allowSignature is a kill switch, ensuring no signature methods
|
||||
// are triggered except when this flag is true
|
||||
allowSignature: { type: Boolean, default: false },
|
||||
showImageResizeToolbar: { type: Boolean, default: false }, // A kill switch to show or hide the image toolbar
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
@@ -126,9 +148,16 @@ export default {
|
||||
editorView: null,
|
||||
range: null,
|
||||
state: undefined,
|
||||
isImageNodeSelected: false,
|
||||
toolbarPosition: { top: 0, left: 0 },
|
||||
sizes: MESSAGE_EDITOR_IMAGE_RESIZES,
|
||||
selectedImageNode: null,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
editorRoot() {
|
||||
return this.$refs.editorRoot;
|
||||
},
|
||||
contentFromEditor() {
|
||||
return MessageMarkdownSerializer.serialize(this.editorView.state.doc);
|
||||
},
|
||||
@@ -412,6 +441,9 @@ export default {
|
||||
focus: () => {
|
||||
this.onFocus();
|
||||
},
|
||||
click: () => {
|
||||
// this.isEditorMouseFocusedOnAnImage(); Enable it when the backend supports for message resize is done.
|
||||
},
|
||||
blur: () => {
|
||||
this.onBlur();
|
||||
},
|
||||
@@ -424,6 +456,50 @@ export default {
|
||||
},
|
||||
});
|
||||
},
|
||||
isEditorMouseFocusedOnAnImage() {
|
||||
if (!this.showImageResizeToolbar) {
|
||||
return;
|
||||
}
|
||||
this.selectedImageNode = document.querySelector(
|
||||
'img.ProseMirror-selectednode'
|
||||
);
|
||||
if (this.selectedImageNode) {
|
||||
this.isImageNodeSelected = !!this.selectedImageNode;
|
||||
// Get the position of the selected node
|
||||
this.setToolbarPosition();
|
||||
} else {
|
||||
this.isImageNodeSelected = false;
|
||||
}
|
||||
},
|
||||
setToolbarPosition() {
|
||||
const editorRect = this.editorRoot.getBoundingClientRect();
|
||||
const rect = this.selectedImageNode.getBoundingClientRect();
|
||||
this.toolbarPosition = {
|
||||
top: `${rect.top - editorRect.top - 30}px`,
|
||||
left: `${rect.left - editorRect.left - 4}px`,
|
||||
};
|
||||
},
|
||||
setURLWithQueryAndImageSize(size) {
|
||||
if (!this.showImageResizeToolbar) {
|
||||
return;
|
||||
}
|
||||
setURLWithQueryAndSize(this.selectedImageNode, size, this.editorView);
|
||||
this.isImageNodeSelected = false;
|
||||
},
|
||||
updateImgToolbarOnDelete() {
|
||||
// check if the selected node is present or not on keyup
|
||||
// this is needed because the user can select an image and then delete it
|
||||
// in that case, the selected node will be null and we need to hide the toolbar
|
||||
// otherwise, the toolbar will be visible even when the image is deleted and cause some errors
|
||||
if (this.selectedImageNode) {
|
||||
const hasImgSelectedNode = document.querySelector(
|
||||
'img.ProseMirror-selectednode'
|
||||
);
|
||||
if (!hasImgSelectedNode) {
|
||||
this.isImageNodeSelected = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
isEnterToSendEnabled() {
|
||||
return isEditorHotKeyEnabled(this.uiSettings, 'enter');
|
||||
},
|
||||
@@ -588,6 +664,7 @@ export default {
|
||||
() => this.resetTyping(),
|
||||
TYPING_INDICATOR_IDLE_TIME
|
||||
);
|
||||
// this.updateImgToolbarOnDelete(); Enable it when the backend supports for message resize is done.
|
||||
},
|
||||
onKeydown(event) {
|
||||
if (this.isEnterToSendEnabled()) {
|
||||
|
||||
Reference in New Issue
Block a user