mirror of
https://github.com/lingble/chatwoot.git
synced 2025-12-27 16:14:46 +00:00
# Pull Request Template ## Description This PR adds new eslint rules to the code base. **Error rules** | Rule name | Type | Files updated | | ----------------- | --- | - | | `vue/block-order` | error | ✅ | | `vue/component-name-in-template-casing` | error | ✅ | | `vue/component-options-name-casing` | error | ✅ | | `vue/custom-event-name-casing` | error | ✅ | | `vue/define-emits-declaration` | error | ✅ | | `vue/no-unused-properties` | error | ✅ | | `vue/define-macros-order` | error | ✅ | | `vue/define-props-declaration` | error | ✅ | | `vue/match-component-import-name` | error | ✅ | | `vue/next-tick-style` | error | ✅ | | `vue/no-bare-strings-in-template` | error | ✅ | | `vue/no-empty-component-block` | error | ✅ | | `vue/no-multiple-objects-in-class` | error | ✅ | | `vue/no-required-prop-with-default` | error | ✅ | | `vue/no-static-inline-styles` | error | ✅ | | `vue/no-template-target-blank` | error | ✅ | | `vue/no-this-in-before-route-enter` | error | ✅ | | `vue/no-undef-components` | error | ✅ | | `vue/no-unused-emit-declarations` | error | ✅ | | `vue/no-unused-refs` | error | ✅ | | `vue/no-use-v-else-with-v-for` | error | ✅ | | `vue/no-useless-v-bind` | error | ✅ | | `vue/no-v-text` | error | ✅ | | `vue/padding-line-between-blocks` | error | ✅ | | ~`vue/prefer-prop-type-boolean-first`~ | ~error~ | ❌ (removed this rule, cause a bug in displaying custom attributes) | | `vue/prefer-separate-static-class` | error | ✅ | | `vue/prefer-true-attribute-shorthand` | error | ✅ | | `vue/require-explicit-slots` | error | ✅ | | `vue/require-macro-variable-name` | error | ✅ | **Warn rules** | Rule name | Type | Files updated | | ---- | ------------- | ------------- | | `vue/no-root-v-if` | warn | ❎ | Fixes https://linear.app/chatwoot/issue/CW-3492/vue-eslint-rules ## Type of change - [x] New feature (non-breaking change which adds functionality) ## 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 - [x] 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: Fayaz Ahmed <fayazara@gmail.com> Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com> Co-authored-by: Shivam Mishra <scm.mymail@gmail.com> Co-authored-by: Pranav <pranav@chatwoot.com>
221 lines
5.1 KiB
Vue
Executable File
221 lines
5.1 KiB
Vue
Executable File
<script>
|
|
import { mapGetters } from 'vuex';
|
|
|
|
import ChatAttachmentButton from 'widget/components/ChatAttachment.vue';
|
|
import ChatSendButton from 'widget/components/ChatSendButton.vue';
|
|
import configMixin from '../mixins/configMixin';
|
|
import FluentIcon from 'shared/components/FluentIcon/Index.vue';
|
|
import ResizableTextArea from 'shared/components/ResizableTextArea.vue';
|
|
import darkModeMixin from 'widget/mixins/darkModeMixin.js';
|
|
|
|
const EmojiInput = () => import('shared/components/emoji/EmojiInput.vue');
|
|
|
|
export default {
|
|
name: 'ChatInputWrap',
|
|
components: {
|
|
ChatAttachmentButton,
|
|
ChatSendButton,
|
|
EmojiInput,
|
|
FluentIcon,
|
|
ResizableTextArea,
|
|
},
|
|
mixins: [configMixin, darkModeMixin],
|
|
props: {
|
|
onSendMessage: {
|
|
type: Function,
|
|
default: () => {},
|
|
},
|
|
onSendAttachment: {
|
|
type: Function,
|
|
default: () => {},
|
|
},
|
|
},
|
|
|
|
data() {
|
|
return {
|
|
userInput: '',
|
|
showEmojiPicker: false,
|
|
isFocused: false,
|
|
};
|
|
},
|
|
|
|
computed: {
|
|
...mapGetters({
|
|
widgetColor: 'appConfig/getWidgetColor',
|
|
isWidgetOpen: 'appConfig/getIsWidgetOpen',
|
|
}),
|
|
showAttachment() {
|
|
return this.hasAttachmentsEnabled && this.userInput.length === 0;
|
|
},
|
|
showSendButton() {
|
|
return this.userInput.length > 0;
|
|
},
|
|
inputColor() {
|
|
return `${this.$dm('bg-white', 'dark:bg-slate-600')}
|
|
${this.$dm('text-black-900', 'dark:text-slate-50')}`;
|
|
},
|
|
emojiIconColor() {
|
|
return this.showEmojiPicker
|
|
? `text-woot-500 ${this.$dm('text-black-900', 'dark:text-slate-100')}`
|
|
: `${this.$dm('text-black-900', 'dark:text-slate-100')}`;
|
|
},
|
|
},
|
|
watch: {
|
|
isWidgetOpen(isWidgetOpen) {
|
|
if (isWidgetOpen) {
|
|
this.focusInput();
|
|
}
|
|
},
|
|
},
|
|
destroyed() {
|
|
document.removeEventListener('keypress', this.handleEnterKeyPress);
|
|
},
|
|
mounted() {
|
|
document.addEventListener('keypress', this.handleEnterKeyPress);
|
|
if (this.isWidgetOpen) {
|
|
this.focusInput();
|
|
}
|
|
},
|
|
|
|
methods: {
|
|
onBlur() {
|
|
this.isFocused = false;
|
|
},
|
|
onFocus() {
|
|
this.isFocused = true;
|
|
},
|
|
handleButtonClick() {
|
|
if (this.userInput && this.userInput.trim()) {
|
|
this.onSendMessage(this.userInput);
|
|
}
|
|
this.userInput = '';
|
|
this.focusInput();
|
|
},
|
|
handleEnterKeyPress(e) {
|
|
if (e.keyCode === 13 && !e.shiftKey) {
|
|
e.preventDefault();
|
|
this.handleButtonClick();
|
|
}
|
|
},
|
|
toggleEmojiPicker() {
|
|
this.showEmojiPicker = !this.showEmojiPicker;
|
|
},
|
|
hideEmojiPicker(e) {
|
|
if (this.showEmojiPicker) {
|
|
e.stopPropagation();
|
|
this.toggleEmojiPicker();
|
|
}
|
|
},
|
|
emojiOnClick(emoji) {
|
|
this.userInput = `${this.userInput}${emoji} `;
|
|
},
|
|
onTypingOff() {
|
|
this.toggleTyping('off');
|
|
},
|
|
onTypingOn() {
|
|
this.toggleTyping('on');
|
|
},
|
|
toggleTyping(typingStatus) {
|
|
this.$store.dispatch('conversation/toggleUserTyping', { typingStatus });
|
|
},
|
|
focusInput() {
|
|
this.$refs.chatInput.focus();
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<div
|
|
class="chat-message--input is-focused"
|
|
:class="$dm('bg-white ', 'dark:bg-slate-600')"
|
|
@keydown.esc="hideEmojiPicker"
|
|
>
|
|
<ResizableTextArea
|
|
id="chat-input"
|
|
ref="chatInput"
|
|
v-model="userInput"
|
|
:rows="1"
|
|
:aria-label="$t('CHAT_PLACEHOLDER')"
|
|
:placeholder="$t('CHAT_PLACEHOLDER')"
|
|
class="form-input user-message-input is-focused"
|
|
:class="inputColor"
|
|
@typingOff="onTypingOff"
|
|
@typingOn="onTypingOn"
|
|
@focus="onFocus"
|
|
@blur="onBlur"
|
|
/>
|
|
<div class="button-wrap">
|
|
<ChatAttachmentButton
|
|
v-if="showAttachment"
|
|
:class="$dm('text-black-900', 'dark:text-slate-100')"
|
|
:on-attach="onSendAttachment"
|
|
/>
|
|
<button
|
|
v-if="hasEmojiPickerEnabled"
|
|
class="flex items-center justify-center icon-button"
|
|
:aria-label="$t('EMOJI.ARIA_LABEL')"
|
|
@click="toggleEmojiPicker"
|
|
>
|
|
<FluentIcon icon="emoji" :class="emojiIconColor" />
|
|
</button>
|
|
<EmojiInput
|
|
v-if="showEmojiPicker"
|
|
v-on-clickaway="hideEmojiPicker"
|
|
:on-click="emojiOnClick"
|
|
@keydown.esc="hideEmojiPicker"
|
|
/>
|
|
<ChatSendButton
|
|
v-if="showSendButton"
|
|
:on-click="handleButtonClick"
|
|
:color="widgetColor"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped lang="scss">
|
|
@import '~widget/assets/scss/variables.scss';
|
|
@import '~widget/assets/scss/mixins.scss';
|
|
|
|
.chat-message--input {
|
|
align-items: center;
|
|
display: flex;
|
|
padding: 0 $space-small 0 $space-slab;
|
|
border-radius: 7px;
|
|
|
|
&.is-focused {
|
|
box-shadow:
|
|
0 0 0 1px $color-woot,
|
|
0 0 2px 3px $color-primary-light;
|
|
}
|
|
}
|
|
|
|
.emoji-dialog {
|
|
right: 20px;
|
|
top: -302px;
|
|
max-width: 100%;
|
|
|
|
&::before {
|
|
right: $space-one;
|
|
}
|
|
}
|
|
|
|
.button-wrap {
|
|
display: flex;
|
|
align-items: center;
|
|
padding-left: $space-small;
|
|
}
|
|
|
|
.user-message-input {
|
|
border: 0;
|
|
height: $space-large;
|
|
min-height: $space-large;
|
|
max-height: 2.4 * $space-mega;
|
|
resize: none;
|
|
padding: $space-smaller 0;
|
|
margin-top: $space-small;
|
|
margin-bottom: $space-small;
|
|
}
|
|
</style>
|