Line data Source code
1 7 : <template>
2 : <div class="widget-markdown relative w-full" @dblclick="startEditing">
3 : <SanitizedHtml
4 : class="comfy-markdown-content size-full min-h-[60px] overflow-y-auto rounded-lg"
5 : :class="isEditing ? 'invisible' : 'visible'"
6 : tabindex="0"
7 : data-capture-wheel="true"
8 : role="textarea"
9 : :aria-label="widget.name || $t('g.markdown')"
10 : aria-readonly="true"
11 : :html="renderedHtml"
12 : />
13 :
14 : <Textarea
15 : v-show="isEditing"
16 : ref="textareaRef"
17 : v-model="modelValue"
18 : :aria-label="`${$t('g.edit')} ${widget.name || $t('g.markdown')} ${$t('g.content')}`"
19 : class="absolute inset-0 min-h-[60px] resize-none font-mono text-(length:--comfy-textarea-font-size)"
20 : data-capture-wheel="true"
21 : @blur="handleBlur"
22 : @pointerdown.capture.stop
23 : @pointermove.capture.stop
24 : @pointerup.capture.stop
25 : @click.stop
26 : @keydown.stop
27 : />
28 : </div>
29 : </template>
30 :
31 : <script setup lang="ts">
32 : import { computed, nextTick, ref } from 'vue'
33 :
34 : import SanitizedHtml from '@comfyorg/design-system/common/SanitizedHtml'
35 : import Textarea from '@comfyorg/design-system/textarea/Textarea'
36 :
37 : import type { SimplifiedWidget } from '@/types/simplifiedWidget'
38 : import { renderMarkdownToHtml } from '@/utils/markdownRendererUtil'
39 :
40 : const { widget } = defineProps<{
41 : widget: SimplifiedWidget<string>
42 : }>()
43 :
44 15 : const modelValue = defineModel<string>({ default: '' })
45 :
46 15 : const isEditing = ref(false)
47 15 : const textareaRef = ref<InstanceType<typeof Textarea>>()
48 :
49 15 : const renderedHtml = computed(() =>
50 : renderMarkdownToHtml(modelValue.value || '')
51 : )
52 :
53 0 : async function startEditing() {
54 0 : if (isEditing.value || widget.options?.read_only) return
55 :
56 0 : isEditing.value = true
57 0 : await nextTick()
58 :
59 0 : textareaRef.value?.focus()
60 : }
61 :
62 0 : function handleBlur() {
63 0 : isEditing.value = false
64 : }
65 : </script>
|