|
29 | 29 |
|
30 | 30 | import { |
31 | 31 | AnnotationBorderStyleType, |
| 32 | + AnnotationEditorPrefix, |
32 | 33 | AnnotationEditorType, |
33 | 34 | AnnotationPrefix, |
34 | 35 | AnnotationType, |
@@ -242,6 +243,16 @@ class AnnotationElement { |
242 | 243 | return point; |
243 | 244 | } |
244 | 245 |
|
| 246 | + get commentText() { |
| 247 | + const { data } = this; |
| 248 | + return ( |
| 249 | + this.annotationStorage.getRawValue(`${AnnotationEditorPrefix}${data.id}`) |
| 250 | + ?.popup?.contents || |
| 251 | + data.contentsObj?.str || |
| 252 | + "" |
| 253 | + ); |
| 254 | + } |
| 255 | + |
245 | 256 | removePopup() { |
246 | 257 | (this.#popupElement?.popup || this.popup)?.remove(); |
247 | 258 | this.#popupElement = this.popup = null; |
@@ -2335,6 +2346,8 @@ class PopupElement { |
2335 | 2346 |
|
2336 | 2347 | #firstElement = null; |
2337 | 2348 |
|
| 2349 | + #commentText = null; |
| 2350 | + |
2338 | 2351 | constructor({ |
2339 | 2352 | container, |
2340 | 2353 | color, |
@@ -2495,30 +2508,52 @@ class PopupElement { |
2495 | 2508 | } |
2496 | 2509 |
|
2497 | 2510 | getData() { |
2498 | | - return this.#firstElement.data; |
| 2511 | + const { richText, color, opacity, creationDate, modificationDate } = |
| 2512 | + this.#firstElement.data; |
| 2513 | + return { |
| 2514 | + contentsObj: { str: this.comment }, |
| 2515 | + richText, |
| 2516 | + color, |
| 2517 | + opacity, |
| 2518 | + creationDate, |
| 2519 | + modificationDate, |
| 2520 | + }; |
2499 | 2521 | } |
2500 | 2522 |
|
2501 | 2523 | get elementBeforePopup() { |
2502 | 2524 | return this.#commentButton; |
2503 | 2525 | } |
2504 | 2526 |
|
2505 | 2527 | get comment() { |
2506 | | - return this.#firstElement.data.contentsObj?.str || ""; |
| 2528 | + this.#commentText ||= this.#firstElement.commentText; |
| 2529 | + return this.#commentText; |
2507 | 2530 | } |
2508 | 2531 |
|
2509 | 2532 | set comment(text) { |
2510 | 2533 | const element = this.#firstElement; |
2511 | | - if (text) { |
2512 | | - element.data.contentsObj = { str: text }; |
2513 | | - // TODO: Support saving the text. |
2514 | | - // element.annotationStorage.setValue(element.data.id, { |
2515 | | - // popup: { contents: text }, |
2516 | | - // }); |
2517 | | - } else { |
2518 | | - element.data.contentsObj = null; |
| 2534 | + const { data } = element; |
| 2535 | + if (text === this.comment) { |
| 2536 | + return; |
| 2537 | + } |
| 2538 | + const popup = { deleted: !text, contents: text || "" }; |
| 2539 | + if (!element.annotationStorage.updateEditor(data.id, { popup })) { |
| 2540 | + element.annotationStorage.setValue( |
| 2541 | + `${AnnotationEditorPrefix}${data.id}`, |
| 2542 | + { |
| 2543 | + id: data.id, |
| 2544 | + annotationType: data.annotationType, |
| 2545 | + pageIndex: element.parent.page._pageIndex, |
| 2546 | + popup, |
| 2547 | + popupRef: data.popupRef, |
| 2548 | + modificationDate: new Date(), |
| 2549 | + } |
| 2550 | + ); |
| 2551 | + } |
| 2552 | + |
| 2553 | + this.#commentText = text; |
| 2554 | + if (!text) { |
2519 | 2555 | element.removePopup(); |
2520 | 2556 | } |
2521 | | - element.data.modificationDate = new Date(); |
2522 | 2557 | } |
2523 | 2558 |
|
2524 | 2559 | get parentBoundingClientRect() { |
@@ -2707,6 +2742,10 @@ class PopupElement { |
2707 | 2742 | } |
2708 | 2743 |
|
2709 | 2744 | updateEdited({ rect, popup, deleted }) { |
| 2745 | + if (this.#commentManager) { |
| 2746 | + this.#commentText = deleted ? null : popup.text; |
| 2747 | + return; |
| 2748 | + } |
2710 | 2749 | if (deleted || popup?.deleted) { |
2711 | 2750 | this.remove(); |
2712 | 2751 | return; |
|
0 commit comments