1
1
<script setup lang="ts">
2
- import { ignorableWatch , onClickOutside } from ' @vueuse/core'
3
- import { nextTick , ref , watch } from ' vue'
2
+ import { ignorableWatch , onClickOutside , useVModel } from ' @vueuse/core'
3
+ import { ref , watch , watchEffect } from ' vue'
4
4
import { currentSlideId } from ' ../logic/nav'
5
5
import { useDynamicSlideInfo } from ' ../logic/note'
6
6
import NoteDisplay from ' ./NoteDisplay.vue'
@@ -9,6 +9,9 @@ const props = defineProps({
9
9
class: {
10
10
default: ' ' ,
11
11
},
12
+ editing: {
13
+ default: false ,
14
+ },
12
15
style: {
13
16
default : () => ({}),
14
17
},
@@ -17,6 +20,11 @@ const props = defineProps({
17
20
},
18
21
})
19
22
23
+ const emit = defineEmits ([
24
+ ' update:editing' ,
25
+ ])
26
+ const editing = useVModel (props , ' editing' , emit , { passive: true })
27
+
20
28
const { info, update } = useDynamicSlideInfo (currentSlideId )
21
29
22
30
const note = ref (' ' )
@@ -45,17 +53,11 @@ watch(
45
53
)
46
54
47
55
const input = ref <HTMLTextAreaElement >()
48
- const editing = ref (false )
49
-
50
- async function switchNoteEdit(e : MouseEvent ) {
51
- if ((e ?.target as HTMLElement )?.tagName === ' A' )
52
- return
53
56
54
- editing .value = true
55
- input .value ?.focus ()
56
- await nextTick ()
57
- input .value ?.focus ()
58
- }
57
+ watchEffect (() => {
58
+ if (editing .value )
59
+ input .value ?.focus ()
60
+ })
59
61
60
62
onClickOutside (input , () => {
61
63
editing .value = false
@@ -64,13 +66,12 @@ onClickOutside(input, () => {
64
66
65
67
<template >
66
68
<NoteDisplay
67
- v-if =" !editing && note "
69
+ v-if =" !editing"
68
70
class =" my--4 border-transparent border-2"
69
- :class =" props.class"
71
+ :class =" [ props.class, note ? '' : 'opacity-50'] "
70
72
:style =" props.style"
71
- :note =" note"
73
+ :note =" note || placeholder "
72
74
:note-html =" info?.noteHTML"
73
- @click =" switchNoteEdit"
74
75
/>
75
76
<textarea
76
77
v-else
0 commit comments