/
HeadingBlock.vue
48 lines (44 loc) · 1.14 KB
/
HeadingBlock.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
<template>
<div ref="content"
:contenteditable="!props.readonly" spellcheck="false"
@blur="props.block.details.value=content?.innerText"
class="focus:outline-none focus-visible:outline-none w-full py-1.5 font-semibold"
:class="headingConfig[props.block.type]?.class"
:block-type="props.block.type"
:data-ph="headingConfig[props.block.type]?.placeholder">
{{ props.block.details.value }}
</div>
</template>
<script setup lang="ts">
import { ref, PropType } from 'vue'
import { Block, BlockType } from '@/utils/types'
const headingConfig = {
[BlockType.H1]: {
placeholder: 'Heading 1',
class: 'text-4xl font-semibold',
},
[BlockType.H2]: {
placeholder: 'Heading 2',
class: 'text-3xl font-medium',
},
[BlockType.H3]: {
placeholder: 'Heading 3',
class: 'text-2xl font-medium',
},
// Irrelevant BlockTypes
[BlockType.Text]: null,
[BlockType.Divider]: null,
[BlockType.Quote]: null,
}
const props = defineProps({
block: {
type: Object as PropType<Block>,
required: true,
},
readonly: {
type: Boolean,
default: false,
},
})
const content = ref<HTMLDivElement>()
</script>