11<script setup lang="ts">
2- import {onBeforeUnmount , onMounted , ref } from " vue" ;
3- import {watchDebounced } from " @vueuse/core" ;
4- import {useCalendarStore } from " @/stores/useCalendarStore.ts" ;
5- import {readContent , writeContent } from " @/api/content.ts" ;
6- import {EditorContent , Editor } from " @tiptap/vue-3" ;
7- import {Gapcursor } from " @tiptap/extension-gapcursor" ;
8- import {CharacterCount } from " @tiptap/extension-character-count" ;
9- import {Paragraph } from " @tiptap/extension-paragraph" ;
10- import {TaskList } from " @tiptap/extension-task-list" ;
11- import {TaskItem } from " @tiptap/extension-task-item" ;
12- import {Heading } from " @tiptap/extension-heading" ;
13- import {CodeBlock } from " @tiptap/extension-code-block" ;
14- import {BulletList } from " @tiptap/extension-bullet-list" ;
15- import {ListItem } from " @tiptap/extension-list-item" ;
16- import {Bold } from " @tiptap/extension-bold" ;
17- import {Italic } from " @tiptap/extension-italic" ;
18- import {Link } from " @tiptap/extension-link" ;
19- import {Highlight } from " @tiptap/extension-highlight" ;
20- import {HorizontalRule } from " @tiptap/extension-horizontal-rule" ;
21- import {Strike } from " @tiptap/extension-strike" ;
22- import {Document } from " @tiptap/extension-document" ;
23- import {Text } from " @tiptap/extension-text" ;
24- import {History } from " @tiptap/extension-history" ;
2+ import { onBeforeUnmount , onMounted , ref } from " vue" ;
3+ import { useI18n } from " vue-i18n" ;
4+ import { watchDebounced } from " @vueuse/core" ;
5+ import { useCalendarStore } from " @/stores/useCalendarStore.ts" ;
6+ import { readContent , writeContent } from " @/api/content.ts" ;
7+ import { EditorContent , Editor } from " @tiptap/vue-3" ;
8+ import { Gapcursor } from " @tiptap/extension-gapcursor" ;
9+ import { CharacterCount } from " @tiptap/extension-character-count" ;
10+ import { Paragraph } from " @tiptap/extension-paragraph" ;
11+ import { Placeholder } from " @tiptap/extension-placeholder" ;
12+ import { TaskList } from " @tiptap/extension-task-list" ;
13+ import { TaskItem } from " @tiptap/extension-task-item" ;
14+ import { Heading } from " @tiptap/extension-heading" ;
15+ import { CodeBlock } from " @tiptap/extension-code-block" ;
16+ import { BulletList } from " @tiptap/extension-bullet-list" ;
17+ import { ListItem } from " @tiptap/extension-list-item" ;
18+ import { Bold } from " @tiptap/extension-bold" ;
19+ import { Italic } from " @tiptap/extension-italic" ;
20+ import { Link } from " @tiptap/extension-link" ;
21+ import { Highlight } from " @tiptap/extension-highlight" ;
22+ import { HorizontalRule } from " @tiptap/extension-horizontal-rule" ;
23+ import { Strike } from " @tiptap/extension-strike" ;
24+ import { Document } from " @tiptap/extension-document" ;
25+ import { Text } from " @tiptap/extension-text" ;
26+ import { History } from " @tiptap/extension-history" ;
2527
26- const store = useCalendarStore ()
27- const editor = ref ()
28- const content = ref (' ' )
28+ const { t } = useI18n ();
29+
30+ const store = useCalendarStore ();
31+ const editor = ref ();
32+ const content = ref (" " );
2933
3034onMounted (async () => {
3135 editor .value = new Editor ({
32- autofocus: ' end' ,
33- content: await readContent (store .currentDate ) as string ,
36+ autofocus: " end" ,
37+ content: ( await readContent (store .currentDate ) ) as string ,
3438 editable: true ,
3539 extensions: [
3640 Document ,
@@ -49,43 +53,44 @@ onMounted(async () => {
4953 Strike ,
5054 Link ,
5155 History ,
52- /* Image,
5356 Placeholder .configure ({
5457 includeChildren: true ,
5558 placeholder : ({ node }) => {
56- return {
57- 'paragraph': this.$t('commands.type_slash')
58- }[node.type.name] ?? ''
59+ return (
60+ {
61+ paragraph : t (" commands.type_slash" ),
62+ }[node .type .name ] ?? " "
63+ );
5964 },
60- }),*/
65+ }),
6166 Gapcursor ,
62- CharacterCount
67+ CharacterCount ,
6368 ],
64- onUpdate : async ({editor }) => {
65- content .value = editor .getHTML ()
66- }
67- })
68- })
69+ onUpdate : async ({ editor }) => {
70+ content .value = editor .getHTML ();
71+ },
72+ });
73+ });
6974
70- const focusEditor = () => editor .value .chain ().focus ().run ()
75+ const focusEditor = () => editor .value .chain ().focus ().run ();
7176
7277watchDebounced (
7378 content ,
7479 async () => writeContent (store .currentDate , content .value ),
75- {debounce: 500 , maxWait: 1500 },
76- )
80+ { debounce: 500 , maxWait: 1500 },
81+ );
7782
7883// TODO: maybe save before destroy
79- onBeforeUnmount (() => console .log (' destroying' ))
84+ onBeforeUnmount (() => console .log (" destroying" ));
8085 </script >
8186
8287<template >
8388 <div
84- class =' px-10 mt-5 text-gray-400 dark:text-gray-500 relative flex-grow cursor-text'
85- @click =' focusEditor'
89+ class =" px-10 mt-5 text-gray-400 dark:text-gray-500 relative flex-grow cursor-text"
90+ @click =" focusEditor"
8691 >
87- <div class =' text-black dark:text-white' >
88- <editor-content class =' pb-10' :editor =" editor" v-model =" content" />
92+ <div class =" text-black dark:text-white" >
93+ <editor-content class =" pb-10" :editor =" editor" v-model =" content" />
8994 </div >
9095 </div >
9196</template >
@@ -94,4 +99,4 @@ onBeforeUnmount(() => console.log('destroying'))
9499.ProseMirror :focus {
95100 @apply outline-none ;
96101}
97- </style >
102+ </style >
0 commit comments