@@ -86,7 +86,10 @@ const PagesCountLimit = {
86
86
} ;
87
87
88
88
function isValidAnnotationEditorMode ( mode ) {
89
- return Object . values ( AnnotationEditorType ) . includes ( mode ) ;
89
+ return (
90
+ Object . values ( AnnotationEditorType ) . includes ( mode ) &&
91
+ mode !== AnnotationEditorType . DISABLE
92
+ ) ;
90
93
}
91
94
92
95
/**
@@ -113,8 +116,9 @@ function isValidAnnotationEditorMode(mode) {
113
116
* being rendered. The constants from {@link AnnotationMode} should be used;
114
117
* see also {@link RenderParameters} and {@link GetOperatorListParameters}.
115
118
* The default value is `AnnotationMode.ENABLE_FORMS`.
116
- * @property {boolean } [annotationEditorEnabled] - Enables the creation and
117
- * editing of new Annotations.
119
+ * @property {boolean } [annotationEditorMode] - Enables the creation and editing
120
+ * of new Annotations. The constants from {@link AnnotationEditorType} should
121
+ * be used. The default value is `AnnotationEditorType.DISABLE`.
118
122
* @property {string } [imageResourcesPath] - Path for image resources, mainly
119
123
* mainly for annotation icons. Include trailing slash.
120
124
* @property {boolean } [enablePrintAutoRotate] - Enables automatic rotation of
@@ -213,7 +217,7 @@ class PDFPageViewBuffer {
213
217
class BaseViewer {
214
218
#buffer = null ;
215
219
216
- #annotationEditorMode = AnnotationEditorType . NONE ;
220
+ #annotationEditorMode = AnnotationEditorType . DISABLE ;
217
221
218
222
#annotationEditorUIManager = null ;
219
223
@@ -273,9 +277,8 @@ class BaseViewer {
273
277
this . textLayerMode = options . textLayerMode ?? TextLayerMode . ENABLE ;
274
278
this . #annotationMode =
275
279
options . annotationMode ?? AnnotationMode . ENABLE_FORMS ;
276
- this . #annotationEditorMode = options . annotationEditorEnabled
277
- ? AnnotationEditorType . NONE
278
- : null ;
280
+ this . #annotationEditorMode =
281
+ options . annotationEditorMode ?? AnnotationEditorType . DISABLE ;
279
282
this . imageResourcesPath = options . imageResourcesPath || "" ;
280
283
this . enablePrintAutoRotate = options . enablePrintAutoRotate || false ;
281
284
this . renderer = options . renderer || RendererType . CANVAS ;
@@ -560,7 +563,7 @@ class BaseViewer {
560
563
}
561
564
562
565
if ( ! permissions . includes ( PermissionFlag . MODIFY_CONTENTS ) ) {
563
- params . annotationEditorMode = null ;
566
+ params . annotationEditorMode = AnnotationEditorType . DISABLE ;
564
567
}
565
568
566
569
if (
@@ -710,19 +713,26 @@ class BaseViewer {
710
713
const { annotationEditorMode, annotationMode, textLayerMode } =
711
714
this . #initializePermissions( permissions ) ;
712
715
713
- if ( annotationEditorMode !== null ) {
716
+ if ( annotationEditorMode !== AnnotationEditorType . DISABLE ) {
717
+ const mode = annotationEditorMode ;
718
+
714
719
if ( isPureXfa ) {
715
720
console . warn ( "Warning: XFA-editing is not implemented." ) ;
716
- } else {
721
+ } else if ( isValidAnnotationEditorMode ( mode ) ) {
717
722
// Ensure that the Editor buttons, in the toolbar, are updated.
718
723
this . eventBus . dispatch ( "annotationeditormodechanged" , {
719
724
source : this ,
720
- mode : annotationEditorMode ,
725
+ mode,
721
726
} ) ;
722
727
723
728
this . #annotationEditorUIManager = new AnnotationEditorUIManager (
724
729
this . eventBus
725
730
) ;
731
+ if ( mode !== AnnotationEditorType . NONE ) {
732
+ this . #annotationEditorUIManager. updateMode ( mode ) ;
733
+ }
734
+ } else {
735
+ console . error ( `Invalid AnnotationEditor mode: ${ mode } ` ) ;
726
736
}
727
737
}
728
738
@@ -885,9 +895,6 @@ class BaseViewer {
885
895
}
886
896
887
897
_resetView ( ) {
888
- if ( this . #annotationEditorMode !== null ) {
889
- this . #annotationEditorMode = AnnotationEditorType . NONE ;
890
- }
891
898
this . #annotationEditorUIManager = null ;
892
899
this . _pages = [ ] ;
893
900
this . _currentPageNumber = 1 ;
@@ -2142,7 +2149,7 @@ class BaseViewer {
2142
2149
}
2143
2150
2144
2151
/**
2145
- * @type {number | null }
2152
+ * @type {number }
2146
2153
*/
2147
2154
get annotationEditorMode ( ) {
2148
2155
return this . #annotationEditorMode;
0 commit comments