|
| 1 | +<script setup lang="ts"> |
| 2 | +importtype {SlideRoute }from'@slidev/types' |
| 3 | +import {useHead }from'@unhead/vue' |
| 4 | +import {debouncedWatch }from'@vueuse/core' |
| 5 | +import {ref }from'vue' |
| 6 | +import {useNav }from'../composables/useNav' |
| 7 | +import {useDynamicSlideInfo }from'../composables/useSlideInfo' |
| 8 | +import {slidesTitle }from'../env' |
| 9 | +importIconButtonfrom'../internals/IconButton.vue' |
| 10 | +importModalfrom'../internals/Modal.vue' |
| 11 | +
|
| 12 | +useHead({ title:`Notes Edit - ${slidesTitle}` }) |
| 13 | +
|
| 14 | +const { slides }=useNav() |
| 15 | +
|
| 16 | +const showHelp=ref(false) |
| 17 | +const note=ref(serializeNotes(slides.value)) |
| 18 | +
|
| 19 | +function serializeNotes(slides:SlideRoute[]) { |
| 20 | +const lines:string[]= [] |
| 21 | +
|
| 22 | +for (const slideofslides) { |
| 23 | +if (!slide.meta.slide.note?.trim()) |
| 24 | +continue |
| 25 | +lines.push(`--- #${slide.no}`) |
| 26 | +lines.push('') |
| 27 | +lines.push(slide.meta.slide.note) |
| 28 | +lines.push('') |
| 29 | + } |
| 30 | +
|
| 31 | +returnlines.join('\n') |
| 32 | +} |
| 33 | +
|
| 34 | +function deserializeNotes(notes:string,slides:SlideRoute[]) { |
| 35 | +const lines=notes.split(/^(---\s*#\d+\s*)$/gm) |
| 36 | +
|
| 37 | +lines.forEach((line,index)=> { |
| 38 | +const match=line.match(/^---\s*#(\d+)\s*$/) |
| 39 | +if (match) { |
| 40 | +const no=Number.parseInt(match[1]) |
| 41 | +const note=lines[index+1].trim() |
| 42 | +const slide=slides.find(s=>s.no===no) |
| 43 | +if (slide) { |
| 44 | +slide.meta.slide.note=note |
| 45 | +useDynamicSlideInfo(no).update({note }) |
| 46 | + } |
| 47 | + } |
| 48 | + }) |
| 49 | +} |
| 50 | +
|
| 51 | +debouncedWatch(note, (value)=> { |
| 52 | +deserializeNotes(value,slides.value) |
| 53 | +}, { debounce:300 }) |
| 54 | +</script> |
| 55 | + |
| 56 | +<template> |
| 57 | + <Modalv-model="showHelp"class="px-6 py-4 flex flex-col gap-2"> |
| 58 | + <divclass="flex gap-2 text-xl"> |
| 59 | + <divclass="i-carbon:information my-auto" /> Help |
| 60 | + </div> |
| 61 | + <divclass="prose dark:prose-invert"> |
| 62 | + <p>This is the batch notes editor. You can edit the notes for all the slides at once here.</p> |
| 63 | + |
| 64 | + <p>The note for each slide are separated by <code>--- #[no]</code> lines, you might want to keep them while editing.</p> |
| 65 | + </div> |
| 66 | + <divclass="flex my-1"> |
| 67 | + <buttonclass="slidev-form-button"@click="showHelp = false"> |
| 68 | + Close |
| 69 | + </button> |
| 70 | + </div> |
| 71 | + </Modal> |
| 72 | + <divclass="h-full"> |
| 73 | + <divclass="slidev-glass-effect fixed bottom-5 right-5 rounded-full border border-main"> |
| 74 | + <IconButtontitle="Help"class="rounded-full"@click="showHelp = true"> |
| 75 | + <divclass="i-carbon:help text-2xl" /> |
| 76 | + </IconButton> |
| 77 | + </div> |
| 78 | + <textarea |
| 79 | +v-model="note" |
| 80 | +class="prose dark:prose-invert resize-none p5 outline-none bg-transparent block h-full w-full! max-w-full! max-h-full! min-h-full! min-w-full!" |
| 81 | + /> |
| 82 | + </div> |
| 83 | +</template> |