@@ -15,6 +15,10 @@ export default {
15
15
type: String ,
16
16
required: true ,
17
17
},
18
+ readonly: {
19
+ type: Boolean ,
20
+ required: true ,
21
+ },
18
22
noteid: {
19
23
type: String ,
20
24
required: true ,
@@ -29,7 +33,7 @@ export default {
29
33
})
30
34
31
35
md .use (require (' markdown-it-task-checkbox' ), {
32
- disabled: true ,
36
+ disabled: this . readonly ,
33
37
liClass: ' task-list-item' ,
34
38
})
35
39
@@ -51,7 +55,48 @@ export default {
51
55
methods: {
52
56
onUpdate () {
53
57
this .html = this .md .render (this .value )
58
+ if (! this .readonly ) {
59
+ setTimeout (() => this .prepareOnClickListener (), 100 )
60
+ }
61
+ },
62
+
63
+ prepareOnClickListener () {
64
+ const items = document .getElementsByClassName (' task-list-item' )
65
+ for (let i = 0 ; i < items .length ; ++ i) {
66
+ items[i].removeEventListener (' click' , this .onClickListItem )
67
+ items[i].addEventListener (' click' , this .onClickListItem )
68
+ }
69
+ },
70
+
71
+ onClickListItem (event ) {
72
+ event .stopPropagation ()
73
+ let idOfCheckbox = 0
74
+ const markdownLines = this .value .split (' \n ' )
75
+ markdownLines .forEach ((line , i ) => {
76
+ // Regex Source: https://github.com/linsir/markdown-it-task-checkbox/blob/master/index.js#L121
77
+ // plus the '- '-string.
78
+ if (/ ^ [-+*] \s + \[ [xX \u00A0 ] \] [ \u00A0 ] / .test (line .trim ())) {
79
+ markdownLines[i] = this .checkLine (line, i, idOfCheckbox, event .target )
80
+ idOfCheckbox++
81
+ }
82
+ })
83
+
84
+ this .$emit (' input' , markdownLines .join (' \n ' ))
85
+ },
86
+
87
+ checkLine (line , index , id , target ) {
88
+ let returnValue = line
89
+ if (' cbx_' + id === target .id ) {
90
+ if (target .checked ) {
91
+ returnValue = returnValue .replace (/ \[ [ \u00A0 ] \] / , ' [x]' )
92
+ } else {
93
+ // matches [x] or [X], to prevent two occurences of uppercase and lowercase X to be replaced
94
+ returnValue = returnValue .replace (/ \[ [xX] \] / , ' [ ]' )
95
+ }
96
+ }
97
+ return returnValue
54
98
},
99
+
55
100
setImageRule (id ) {
56
101
// https://github.com/markdown-it/markdown-it/blob/master/docs/architecture.md#renderer
57
102
// Remember old renderer, if overridden, or proxy to default renderer
@@ -182,6 +227,7 @@ export default {
182
227
list-style-type : none ;
183
228
input {
184
229
min-height : initial !important ;
230
+ cursor : pointer ;
185
231
}
186
232
label {
187
233
cursor : default ;
0 commit comments