|
| 1 | +<template> |
| 2 | + <div |
| 3 | + class="description" |
| 4 | + :class="{ 'no-border-bottom': snippetStore.isFragmentsShow }" |
| 5 | + @click="onClick" |
| 6 | + > |
| 7 | + <PerfectScrollbar> |
| 8 | + <div |
| 9 | + ref="inputRef" |
| 10 | + class="input" |
| 11 | + contenteditable="true" |
| 12 | + spellcheck="false" |
| 13 | + placeholder="Add description" |
| 14 | + @blur="onBlur" |
| 15 | + > |
| 16 | + {{ desc }} |
| 17 | + </div> |
| 18 | + </PerfectScrollbar> |
| 19 | + </div> |
| 20 | +</template> |
| 21 | + |
| 22 | +<script setup lang="ts"> |
| 23 | +import { useAppStore } from '@/store/app' |
| 24 | +import { useSnippetStore } from '@/store/snippets' |
| 25 | +
|
| 26 | +import { computed, nextTick, ref, watch } from 'vue' |
| 27 | +
|
| 28 | +const snippetStore = useSnippetStore() |
| 29 | +const appStore = useAppStore() |
| 30 | +
|
| 31 | +const desc = computed(() => snippetStore.selected?.description) |
| 32 | +
|
| 33 | +const inputRef = ref<HTMLElement>() |
| 34 | +const descHeight = appStore.sizes.editor.descriptionHeight + 'px' |
| 35 | +
|
| 36 | +const onBlur = (e: Event) => { |
| 37 | + snippetStore.patchSnippetsById(snippetStore.selectedId!, { |
| 38 | + description: (e.target as HTMLElement).innerText.trimEnd() || null |
| 39 | + }) |
| 40 | +} |
| 41 | +
|
| 42 | +const onClick = () => { |
| 43 | + inputRef.value?.focus() |
| 44 | +} |
| 45 | +
|
| 46 | +watch( |
| 47 | + () => snippetStore.isDescriptionShow, |
| 48 | + v => { |
| 49 | + if (v && snippetStore.selected?.description?.length === 0) { |
| 50 | + nextTick(() => inputRef.value?.focus()) |
| 51 | + } |
| 52 | + } |
| 53 | +) |
| 54 | +</script> |
| 55 | + |
| 56 | +<style lang="scss" scoped> |
| 57 | +.description { |
| 58 | + padding: 0 var(--spacing-xs); |
| 59 | + font-size: 12px; |
| 60 | + color: var(--color-text); |
| 61 | + border-bottom: 1px solid var(--color-border); |
| 62 | + :empty::before { |
| 63 | + content: attr(placeholder); |
| 64 | + position: absolute; |
| 65 | + color: var(--color-text-3); |
| 66 | + background-color: transparent; |
| 67 | + } |
| 68 | + &.no-border-bottom { |
| 69 | + border-bottom: none; |
| 70 | + } |
| 71 | + .input { |
| 72 | + width: 100%; |
| 73 | + border: 0; |
| 74 | + outline: 0; |
| 75 | + line-height: 14px; |
| 76 | + white-space: pre-wrap; |
| 77 | + } |
| 78 | + :deep(.ps) { |
| 79 | + height: v-bind(descHeight); |
| 80 | + } |
| 81 | +} |
| 82 | +</style> |
0 commit comments