1
1
<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" ;
25
27
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 (" " );
29
33
30
34
onMounted (async () => {
31
35
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 ,
34
38
editable: true ,
35
39
extensions: [
36
40
Document ,
@@ -49,43 +53,44 @@ onMounted(async () => {
49
53
Strike ,
50
54
Link ,
51
55
History ,
52
- /* Image,
53
56
Placeholder .configure ({
54
57
includeChildren: true ,
55
58
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
+ );
59
64
},
60
- }),*/
65
+ }),
61
66
Gapcursor ,
62
- CharacterCount
67
+ CharacterCount ,
63
68
],
64
- onUpdate : async ({editor }) => {
65
- content .value = editor .getHTML ()
66
- }
67
- })
68
- })
69
+ onUpdate : async ({ editor }) => {
70
+ content .value = editor .getHTML ();
71
+ },
72
+ });
73
+ });
69
74
70
- const focusEditor = () => editor .value .chain ().focus ().run ()
75
+ const focusEditor = () => editor .value .chain ().focus ().run ();
71
76
72
77
watchDebounced (
73
78
content ,
74
79
async () => writeContent (store .currentDate , content .value ),
75
- {debounce: 500 , maxWait: 1500 },
76
- )
80
+ { debounce: 500 , maxWait: 1500 },
81
+ );
77
82
78
83
// TODO: maybe save before destroy
79
- onBeforeUnmount (() => console .log (' destroying' ))
84
+ onBeforeUnmount (() => console .log (" destroying" ));
80
85
</script >
81
86
82
87
<template >
83
88
<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"
86
91
>
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" />
89
94
</div >
90
95
</div >
91
96
</template >
@@ -94,4 +99,4 @@ onBeforeUnmount(() => console.log('destroying'))
94
99
.ProseMirror :focus {
95
100
@apply outline-none ;
96
101
}
97
- </style >
102
+ </style >
0 commit comments