Przeglądaj źródła

add: 回复注释设置为可配置显示与隐藏

liutian 1 miesiąc temu
rodzic
commit
638d93370c

+ 4 - 2
packages/core/src/annotation/freetext.js

@@ -13,7 +13,8 @@ export default class Shape extends Base {
     scale,
     eventBus,
     layer,
-    show = false
+    show = false,
+    enableReply = true
   }) {
     super({
       container,
@@ -24,6 +25,7 @@ export default class Shape extends Base {
       eventBus,
       show
     })
+    this.enableReply = enableReply
 
     this.layer = layer
     this.hidden = true
@@ -355,7 +357,7 @@ export default class Shape extends Base {
     this.outerLine.append(this.topRect)
     this.outerLineContainer.append(this.outerLine)
     this.outerLineContainer.append(this.deletetButton)
-    this.outerLineContainer.append(this.replyButton)
+    this.enableReply && this.outerLineContainer.append(this.replyButton)
     this.initial = true
     this.firstSelect = true
     if (this.show) {

+ 4 - 2
packages/core/src/annotation/ink.js

@@ -12,7 +12,8 @@ export default class Ink extends Base {
     scale,
     eventBus,
     layer,
-    show = false
+    show = false,
+    enableReply = true
   }) {
     super({
       container,
@@ -23,6 +24,7 @@ export default class Ink extends Base {
       eventBus,
       show
     })
+    this.enableReply = enableReply
 
     this.layer = layer
     this.hidden = true
@@ -896,7 +898,7 @@ export default class Ink extends Base {
     this.outerLine.append(this.topRect)
     this.outerLineContainer.append(this.outerLine)
     this.outerLineContainer.append(this.deletetButton)
-    this.outerLineContainer.append(this.replyButton)
+    this.enableReply && this.outerLineContainer.append(this.replyButton)
     this.initial = true
   }
 

+ 34 - 14
packages/core/src/annotation/layer.js

@@ -41,6 +41,7 @@ class ComPDFAnnotationLayer {
     scale,
     pageIndex,
     eventBus,
+    enableReply = true,
     $t
   }) {
     this._cancelled = false;
@@ -72,6 +73,8 @@ class ComPDFAnnotationLayer {
     this.onHandleAddSign = this.addSign.bind(this)
 
     this.annotationStore.$t = $t
+
+    this.enableReply = enableReply
   }
 
   // 处理注释工具切换
@@ -377,6 +380,7 @@ class ComPDFAnnotationLayer {
       this.renderContainer()
     }
     if (this.annotations && this.annotations.length) {
+      const enableReply = this.enableReply
       for (let i = 0; i < this.annotations.length; i++) {
         const annotation = this.annotations[i]
         if (!annotation) continue
@@ -389,7 +393,8 @@ class ComPDFAnnotationLayer {
             viewport: this.viewport,
             scale: this.scale,
             eventBus: this.eventBus,
-            layer: this
+            layer: this,
+            enableReply
           })
           this.annotationsArray.push(markup)
         } else if (annotation.type === 'line' && !annotation.isDelete) {
@@ -416,7 +421,8 @@ class ComPDFAnnotationLayer {
               viewport: this.viewport,
               scale: this.scale,
               eventBus: this.eventBus,
-              layer: this
+              layer: this,
+              enableReply
             })
             this.annotationsArray.push(line)
           }
@@ -429,7 +435,8 @@ class ComPDFAnnotationLayer {
             viewport: this.viewport,
             scale: this.scale,
             eventBus: this.eventBus,
-            layer: this
+            layer: this,
+            enableReply
           })
           this.annotationsArray.push(shape)
         } else if (annotation.type === 'ink' && !annotation.isDelete) {
@@ -440,7 +447,8 @@ class ComPDFAnnotationLayer {
             viewport: this.viewport,
             scale: this.scale,
             eventBus: this.eventBus,
-            layer: this
+            layer: this,
+            enableReply
           })
           this.annotationsArray.push(ink)
         } else if (annotation.type === 'freetext' && !annotation.isDelete) {
@@ -451,7 +459,8 @@ class ComPDFAnnotationLayer {
             viewport: this.viewport,
             scale: this.scale,
             eventBus: this.eventBus,
-            layer: this
+            layer: this,
+            enableReply
           })
           this.annotationsArray.push(freetext)
         }
@@ -463,7 +472,8 @@ class ComPDFAnnotationLayer {
             viewport: this.viewport,
             scale: this.scale,
             eventBus: this.eventBus,
-            layer: this
+            layer: this,
+            enableReply
           })
           this.annotationsArray.push(text)
         }
@@ -476,7 +486,8 @@ class ComPDFAnnotationLayer {
             viewport: this.viewport,
             scale: this.scale,
             eventBus: this.eventBus,
-            layer: this
+            layer: this,
+            enableReply
           })
           this.annotationsArray.push(text)
         }
@@ -687,6 +698,8 @@ class ComPDFAnnotationLayer {
     if (!this.div) {
       this.renderContainer()
     }
+
+    const enableReply = this.enableReply
     const markupType = ['highlight', 'underline', 'squiggly', 'strikeout']
     if (markupType.includes(annotation.type)) {
       const markup = new MarkupTextAnnotation({
@@ -696,7 +709,8 @@ class ComPDFAnnotationLayer {
         viewport: this.viewport,
         scale: this.scale,
         eventBus: this.eventBus,
-        layer: this
+        layer: this,
+        enableReply
       })
       this.annotationsArray.push(markup)
     } else if (annotation.type === 'line' || annotation.type === 'arrow') {
@@ -708,7 +722,8 @@ class ComPDFAnnotationLayer {
         scale: this.scale,
         eventBus: this.eventBus,
         show: true,
-        layer: this
+        layer: this,
+        enableReply
       })
       this.annotationsArray.push(line)
     } else if (annotation.type === 'square' || annotation.type === 'circle') {
@@ -719,7 +734,8 @@ class ComPDFAnnotationLayer {
         viewport: this.viewport,
         scale: this.scale,
         eventBus: this.eventBus,
-        layer: this
+        layer: this,
+        enableReply
       })
       this.annotationsArray.push(shape)
     } else if (annotation.type === 'ink' && !annotation.isDelete) {
@@ -730,7 +746,8 @@ class ComPDFAnnotationLayer {
         viewport: this.viewport,
         scale: this.scale,
         eventBus: this.eventBus,
-        layer: this
+        layer: this,
+        enableReply
       })
       this.annotationsArray.push(ink)
     } else if (annotation.type === 'freetext' && !annotation.isDelete) {
@@ -742,7 +759,8 @@ class ComPDFAnnotationLayer {
         scale: this.scale,
         eventBus: this.eventBus,
         layer: this,
-        show
+        show,
+        enableReply
       })
       this.annotationsArray.push(freetext)
     } else if (annotation.type === 'text' && !annotation.isDelete) {
@@ -753,7 +771,8 @@ class ComPDFAnnotationLayer {
         viewport: this.viewport,
         scale: this.scale,
         eventBus: this.eventBus,
-        layer: this
+        layer: this,
+        enableReply
       })
       this.annotationsArray.push(text)
     } else if ((annotation.type === 'stamp') && !annotation.isDelete) {
@@ -765,7 +784,8 @@ class ComPDFAnnotationLayer {
         viewport: this.viewport,
         scale: this.scale,
         eventBus: this.eventBus,
-        layer: this
+        layer: this,
+        enableReply
       })
       this.annotationsArray.push(text)
     } else if (annotation.type === 'textfield' && !annotation.isDelete) {

+ 4 - 2
packages/core/src/annotation/line.js

@@ -14,7 +14,8 @@ export default class Line extends Base {
     viewport,
     eventBus,
     layer,
-    show = false
+    show = false,
+    enableReply = true
   }) {
     super({
       container,
@@ -24,6 +25,7 @@ export default class Line extends Base {
       eventBus,
       show
     })
+    this.enableReply = enableReply
 
     this.layer = layer
     this.hidden = true
@@ -235,7 +237,7 @@ export default class Line extends Base {
     this.outerLine.append(this.endCircle)
     this.outerLineContainer.append(this.outerLine)
     this.outerLineContainer.append(this.deletetButton)
-    this.outerLineContainer.append(this.replyButton)
+    this.enableReply && this.outerLineContainer.append(this.replyButton)
     this.initial = true
   }
 

+ 4 - 2
packages/core/src/annotation/shape.js

@@ -13,7 +13,8 @@ export default class Shape extends Base {
     scale,
     eventBus,
     layer,
-    show = false
+    show = false,
+    enableReply = true
   }) {
     super({
       container,
@@ -24,6 +25,7 @@ export default class Shape extends Base {
       eventBus,
       show
     })
+    this.enableReply = enableReply
 
     this.layer = layer
     this.hidden = true
@@ -313,7 +315,7 @@ export default class Shape extends Base {
     this.outerLine.append(this.topRect)
     this.outerLineContainer.append(this.outerLine)
     this.outerLineContainer.append(this.deletetButton)
-    this.outerLineContainer.append(this.replyButton)
+    this.enableReply && this.outerLineContainer.append(this.replyButton)
     this.initial = true
   }
 

+ 4 - 2
packages/core/src/annotation/stamp.js

@@ -15,7 +15,8 @@ export default class Stamp extends Base {
     scale,
     eventBus,
     layer,
-    show = false
+    show = false,
+    enableReply = true
   }) {
     super({
       container,
@@ -26,6 +27,7 @@ export default class Stamp extends Base {
       eventBus,
       show
     })
+    this.enableReply = enableReply
 
     this.layer = layer
     this.hidden = true
@@ -283,7 +285,7 @@ export default class Stamp extends Base {
     this.outerLine.append(this.topRightRect)
     this.outerLineContainer.append(this.outerLine)
     this.outerLineContainer.append(this.deletetButton)
-    this.outerLineContainer.append(this.replyButton)
+    this.enableReply && this.outerLineContainer.append(this.replyButton)
     this.initial = true
 
     this.eventBus.dispatch('imageChange')

+ 3 - 1
packages/core/src/annotation/text.js

@@ -12,6 +12,7 @@ export default class Text extends Base {
     eventBus,
     layer,
     show = false,
+    enableReply = true
   }) {
     super({
       container,
@@ -22,6 +23,7 @@ export default class Text extends Base {
       eventBus,
       show
     })
+    this.enableReply = enableReply
 
     this.textNoteStr = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
       <path fill-rule="evenodd" clip-rule="evenodd" d="M2.39961 3.60004H21.5996V18H11.9996L5.99961 21.6V18H2.39961V3.60004Z" fill="currentColor"/>
@@ -483,7 +485,7 @@ export default class Text extends Base {
       }
     );
     this.replyButton.innerHTML = this.replySvgStr
-    textEditorContainer.append(this.replyButton)
+    this.enableReply && textEditorContainer.append(this.replyButton)
     this.replyButton.addEventListener('click', this.onOpenReply)
   }
 

+ 5 - 1
packages/core/src/index.js

@@ -63,6 +63,7 @@ class ComPDFKitViewer {
     this.color = 'color'
     this.pagesPtr = []
     this.saveAction = null
+    this.enableReply = true
     this.enableDefaultFont = false
     this.enableCustomFont = false
     this.fontsJson = null
@@ -279,6 +280,9 @@ class ComPDFKitViewer {
       if ('enableDefaultFont' in options) {
         this.enableDefaultFont = options.enableDefaultFont
       }
+      if ('enableReply' in options) {
+        this.enableReply = options.enableReply
+      }
       if (options.enableCustomFont) {
         this.enableCustomFont = true
       }
@@ -1470,7 +1474,7 @@ class ComPDFKitViewer {
     this.pdfLinkService.setDocument(pdfDocument);
 
     const pdfViewer = this.pdfViewer;
-    pdfViewer.setDocument(pdfDocument, this.annotations, this.pagesPtr);
+    pdfViewer.setDocument(pdfDocument, this.annotations, this.pagesPtr, this.enableReply);
     const { firstPagePromise, onePageRendered, pagesPromise } = pdfViewer;
 
     

+ 4 - 2
packages/core/src/markup/text_annotation.js

@@ -13,7 +13,8 @@ class TextAnnotation extends BaseAnnotation {
     scale,
     eventBus,
     layer,
-    show = false
+    show = false,
+    enableReply = true
   }) {
     super({
       container,
@@ -24,6 +25,7 @@ class TextAnnotation extends BaseAnnotation {
       eventBus,
       show
     })
+    this.enableReply = enableReply
     this.layer = layer
     this.hidden = true
     this.markupContainer = null
@@ -148,7 +150,7 @@ class TextAnnotation extends BaseAnnotation {
     this.deletetButton = deletetButton
     this.outerLineContainer.append(rectContainer)
     this.outerLineContainer.append(deletetButton)
-    this.outerLineContainer.append(this.replyButton)
+    this.enableReply && this.outerLineContainer.append(this.replyButton)
   }
 
   getActualRect (viewport, s) {

+ 4 - 0
packages/core/src/pdf_page_view.js

@@ -102,6 +102,8 @@ class PDFPageView {
     this.color = ''
     this.toolMode = ''
 
+    this.enableReply = options.enableReply
+
     this.scale = options.scale || DEFAULT_SCALE;
     this.viewport = defaultViewport;
     this.pdfPageRotate = defaultViewport.rotation;
@@ -561,6 +563,7 @@ class PDFPageView {
               pageDiv: div,
               eventBus: this.eventBus,
               selected: this.selected,
+              enableReply: this.enableReply,
               $t: this.$t
             })
           }
@@ -1240,6 +1243,7 @@ class PDFPageView {
               pageDiv: div,
               eventBus: this.eventBus,
               selected: this.selected,
+              enableReply: this.enableReply,
               $t: this.$t
             })
           } else {

+ 2 - 1
packages/core/src/pdf_viewer.js

@@ -507,7 +507,7 @@ class PDFViewer {
   /**
    * @param {PDFDocumentProxy} pdfDocument
    */
-  setDocument(pdfDocument, annotations, pagesPtr) {
+  setDocument(pdfDocument, annotations, pagesPtr, enableReply) {
     if (this.pdfDocument) {
       this.eventBus.dispatch("pagesdestroy", { source: this });
 
@@ -664,6 +664,7 @@ class PDFViewer {
             doc: this.doc,
             messageHandler: this.messageHandler,
             contentEditHistoryManager: this.contentEditHistoryManager,
+            enableReply
           });
           this._pages.push(pageView);
         }