(
type: AnnotationType,
cfi: string,
color: AnnotationColor,
text: string,
notes?: string,
)
| 154 | return this.view.contents.cfiFromRange(range) |
| 155 | } |
| 156 | putAnnotation( |
| 157 | type: AnnotationType, |
| 158 | cfi: string, |
| 159 | color: AnnotationColor, |
| 160 | text: string, |
| 161 | notes?: string, |
| 162 | ) { |
| 163 | const spine = this.section |
| 164 | if (!spine?.navitem) return |
| 165 | |
| 166 | const i = this.book.annotations.findIndex((a) => a.cfi === cfi) |
| 167 | let annotation = this.book.annotations[i] |
| 168 | |
| 169 | const now = Date.now() |
| 170 | if (!annotation) { |
| 171 | annotation = { |
| 172 | id: uuidv4(), |
| 173 | bookId: this.book.id, |
| 174 | cfi, |
| 175 | spine: { |
| 176 | index: spine.index, |
| 177 | title: spine.navitem.label, |
| 178 | }, |
| 179 | createAt: now, |
| 180 | updatedAt: now, |
| 181 | type, |
| 182 | color, |
| 183 | notes, |
| 184 | text, |
| 185 | } |
| 186 | |
| 187 | this.updateBook({ |
| 188 | // DataCloneError: Failed to execute 'put' on 'IDBObjectStore': #<Object> could not be cloned. |
| 189 | annotations: [...snapshot(this.book.annotations), annotation], |
| 190 | }) |
| 191 | } else { |
| 192 | annotation = { |
| 193 | ...this.book.annotations[i]!, |
| 194 | type, |
| 195 | updatedAt: now, |
| 196 | color, |
| 197 | notes, |
| 198 | text, |
| 199 | } |
| 200 | this.book.annotations.splice(i, 1, annotation) |
| 201 | this.updateBook({ |
| 202 | annotations: [...snapshot(this.book.annotations)], |
| 203 | }) |
| 204 | } |
| 205 | } |
| 206 | removeAnnotation(cfi: string) { |
| 207 | return this.updateBook({ |
| 208 | annotations: snapshot(this.book.annotations).filter((a) => a.cfi !== cfi), |
no test coverage detected