-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaseEditor.vue
78 lines (71 loc) · 1.66 KB
/
BaseEditor.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<template>
<div class="input-field">
<label class="label-style" :for="label" v-if="label">{{ label }}</label>
<QuillEditor
ref="quill"
:id="label"
theme="snow"
toolbar="full"
:placeholder="`'${placeholder}'`"
v-model:content="content"
contentType="html"
:readOnly="readOnly"
style="height: 200px"
:class="{ err: error }"
/>
<small
:class="{ 'err-message': error }"
v-if="error && errorMessage"
aria-live="assertive"
:id="`${label}-error`"
>{{ errorMessage }}</small
>
<small
:class="{ 'err-message': error }"
v-else-if="error && !errorMessage"
aria-live="assertive"
:id="`${label}-error`"
>{{ label }} is required</small
>
</div>
</template>
<script setup lang="ts">
interface Props {
modelValue: string | number
label?: string
placeholder?: string
error?: string | boolean
errorMessage?: string | boolean
readOnly?: boolean
}
const props = defineProps<Props>()
const emit = defineEmits({
'update:modelValue': (value) => true
})
const content = ref('')
const quill = ref<any>(null)
let newContent = ''
watch(content, (newValue) => {
newContent = newValue
emit('update:modelValue', newValue)
})
watch(
() => props.modelValue,
(newValue: any) => {
if (newContent === newValue) return
quill.value.setHTML(newValue)
// Workaround https://github.com/vueup/vue-quill/issues/52
// move cursor to end
nextTick(() => {
let q = quill.value.getQuill()
q.setSelection(newValue.length, 0, 'api')
q.focus()
})
}
)
</script>
<style scoped>
:deep(.ql-tooltip) {
display: none;
}
</style>