From 94d72e903face36d62ab08b521c9a00a0e3cbfd0 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Mon, 8 Sep 2025 16:36:46 +0200 Subject: [PATCH] [Editor] Add the dates and rich text if any to the editors in order to use them when displaying the popup --- src/display/editor/comment.js | 13 +++++++++-- src/display/editor/editor.js | 39 +++++++++++++++++++++++---------- src/display/editor/freetext.js | 8 ++++++- src/display/editor/highlight.js | 18 ++++++++++----- src/display/editor/ink.js | 8 ++++++- src/display/editor/stamp.js | 17 ++++++++++++-- 6 files changed, 80 insertions(+), 23 deletions(-) diff --git a/src/display/editor/comment.js b/src/display/editor/comment.js index f71892321..d32087818 100644 --- a/src/display/editor/comment.js +++ b/src/display/editor/comment.js @@ -26,6 +26,8 @@ class Comment { #initialText = null; + #richText = null; + #text = null; #date = null; @@ -144,8 +146,9 @@ class Comment { get data() { return { text: this.#text, + richText: this.#richText, date: this.#date, - deleted: this.#deleted, + deleted: this.isDeleted(), }; } @@ -153,6 +156,9 @@ class Comment { * Set the comment data. */ set data(text) { + if (text !== this.#text) { + this.#richText = null; + } if (text === null) { this.#text = ""; this.#deleted = true; @@ -163,9 +169,11 @@ class Comment { this.#deleted = false; } - setInitialText(text) { + setInitialText(text, richText = null) { this.#initialText = text; this.data = text; + this.#date = null; + this.#richText = richText; } shown() {} @@ -176,6 +184,7 @@ class Comment { this.#commentStandaloneButton?.remove(); this.#commentStandaloneButton = null; this.#text = ""; + this.#richText = null; this.#date = null; this.#editor = null; this.#commentWasFromKeyBoard = false; diff --git a/src/display/editor/editor.js b/src/display/editor/editor.js index 19d34cf97..3de1585df 100644 --- a/src/display/editor/editor.js +++ b/src/display/editor/editor.js @@ -191,7 +191,8 @@ class AnnotationEditor { this._initialOptions.isCentered = parameters.isCentered; this._structTreeParentId = null; this.annotationElementId = parameters.annotationElementId || null; - this.creationDate = new Date(); + this.creationDate = parameters.creationDate || new Date(); + this.modificationDate = parameters.modificationDate || null; const { rotation, @@ -1200,11 +1201,14 @@ class AnnotationEditor { } get comment() { - const comment = this.#comment; + const { + data: { richText, text, date, deleted }, + } = this.#comment; return { - text: comment.data.text, - date: comment.data.date, - deleted: comment.isDeleted(), + text, + richText, + date, + deleted, color: this.commentColor, }; } @@ -1216,11 +1220,11 @@ class AnnotationEditor { this.#comment.data = text; } - setCommentData(text) { + setCommentData({ comment, richText }) { if (!this.#comment) { this.#comment = new Comment(this); } - this.#comment.setInitialText(text); + this.#comment.setInitialText(comment, richText); } get hasEditedComment() { @@ -1611,13 +1615,22 @@ class AnnotationEditor { } getData() { + const { + comment: { text: str, date, deleted, richText }, + uid: id, + pageIndex, + creationDate, + modificationDate, + } = this; return { - id: this.uid, - pageIndex: this.pageIndex, + id, + pageIndex, rect: this.getPDFRect(), - contentsObj: { str: this.comment.text }, - creationDate: this.creationDate, - popupRef: !this.#comment.isDeleted(), + richText, + contentsObj: { str }, + creationDate, + modificationDate: date || modificationDate, + popupRef: !deleted, }; } @@ -1767,6 +1780,8 @@ class AnnotationEditor { id: parent.getNextId(), uiManager, annotationElementId: data.annotationElementId, + creationDate: data.creationDate, + modificationDate: data.modificationDate, }); editor.rotation = data.rotation; editor.#accessibilityData = data.accessibilityData; diff --git a/src/display/editor/freetext.js b/src/display/editor/freetext.js index bc47d21c2..7ae55a293 100644 --- a/src/display/editor/freetext.js +++ b/src/display/editor/freetext.js @@ -781,7 +781,10 @@ class FreeTextEditor extends AnnotationEditor { rotation, id, popupRef, + richText, contentsObj, + creationDate, + modificationDate, }, textContent, textPosition, @@ -809,6 +812,9 @@ class FreeTextEditor extends AnnotationEditor { deleted: false, popupRef, comment: contentsObj?.str || null, + richText, + creationDate, + modificationDate, }; } const editor = await super.deserialize(data, parent, uiManager); @@ -817,7 +823,7 @@ class FreeTextEditor extends AnnotationEditor { editor.#content = FreeTextEditor.#deserializeContent(data.value); editor._initialData = initialData; if (data.comment) { - editor.setCommentData(data.comment); + editor.setCommentData(data); } return editor; diff --git a/src/display/editor/highlight.js b/src/display/editor/highlight.js index 53f43c8c0..e4071b1d2 100644 --- a/src/display/editor/highlight.js +++ b/src/display/editor/highlight.js @@ -151,10 +151,6 @@ class HighlightEditor extends AnnotationEditor { }; } - get commentColor() { - return this.color; - } - static computeTelemetryFinalData(data) { // We want to know how many colors have been used. return { numberOfColors: data.get("color").size }; @@ -891,7 +887,10 @@ class HighlightEditor extends AnnotationEditor { color, opacity, popupRef, + richText, contentsObj, + creationDate, + modificationDate, }, parent: { page: { pageNumber }, @@ -910,7 +909,10 @@ class HighlightEditor extends AnnotationEditor { id, deleted: false, popupRef, + richText, comment: contentsObj?.str || null, + creationDate, + modificationDate, }; } else if (data instanceof InkAnnotationElement) { const { @@ -922,7 +924,10 @@ class HighlightEditor extends AnnotationEditor { color, borderStyle: { rawWidth: thickness }, popupRef, + richText, contentsObj, + creationDate, + modificationDate, }, parent: { page: { pageNumber }, @@ -941,7 +946,10 @@ class HighlightEditor extends AnnotationEditor { id, deleted: false, popupRef, + richText, comment: contentsObj?.str || null, + creationDate, + modificationDate, }; } @@ -955,7 +963,7 @@ class HighlightEditor extends AnnotationEditor { } editor._initialData = initialData; if (data.comment) { - editor.setCommentData(data.comment); + editor.setCommentData(data); } const [pageWidth, pageHeight] = editor.pageDimensions; diff --git a/src/display/editor/ink.js b/src/display/editor/ink.js index 83823f179..b6614fc17 100644 --- a/src/display/editor/ink.js +++ b/src/display/editor/ink.js @@ -150,7 +150,10 @@ class InkEditor extends DrawingEditor { opacity, borderStyle: { rawWidth: thickness }, popupRef, + richText, contentsObj, + creationDate, + modificationDate, }, parent: { page: { pageNumber }, @@ -170,14 +173,17 @@ class InkEditor extends DrawingEditor { id, deleted: false, popupRef, + richText, comment: contentsObj?.str || null, + creationDate, + modificationDate, }; } const editor = await super.deserialize(data, parent, uiManager); editor._initialData = initialData; if (data.comment) { - editor.setCommentData(data.comment); + editor.setCommentData(data); } return editor; diff --git a/src/display/editor/stamp.js b/src/display/editor/stamp.js index 9ba3db861..48c763c41 100644 --- a/src/display/editor/stamp.js +++ b/src/display/editor/stamp.js @@ -751,7 +751,17 @@ class StampEditor extends AnnotationEditor { let missingCanvas = false; if (data instanceof StampAnnotationElement) { const { - data: { rect, rotation, id, structParent, popupRef, contentsObj }, + data: { + rect, + rotation, + id, + structParent, + popupRef, + richText, + contentsObj, + creationDate, + modificationDate, + }, container, parent: { page: { pageNumber }, @@ -795,7 +805,10 @@ class StampEditor extends AnnotationEditor { isSvg: false, structParent, popupRef, + richText, comment: contentsObj?.str || null, + creationDate, + modificationDate, }; } const editor = await super.deserialize(data, parent, uiManager); @@ -823,7 +836,7 @@ class StampEditor extends AnnotationEditor { } editor._initialData = initialData; if (data.comment) { - editor.setCommentData(data.comment); + editor.setCommentData(data); } // No need to be add in the undo stack if the editor is created from an // existing one.