@@ -73,6 +73,13 @@ class AnnotationEditorLayer {
73
73
74
74
static _initialized = false ;
75
75
76
+ static #editorTypes = new Map (
77
+ [ FreeTextEditor , InkEditor , StampEditor ] . map ( type => [
78
+ type . _editorType ,
79
+ type ,
80
+ ] )
81
+ ) ;
82
+
76
83
/**
77
84
* @param {AnnotationEditorLayerOptions } options
78
85
*/
@@ -85,7 +92,7 @@ class AnnotationEditorLayer {
85
92
viewport,
86
93
l10n,
87
94
} ) {
88
- const editorTypes = [ FreeTextEditor , InkEditor , StampEditor ] ;
95
+ const editorTypes = [ ... AnnotationEditorLayer . #editorTypes . values ( ) ] ;
89
96
if ( ! AnnotationEditorLayer . _initialized ) {
90
97
AnnotationEditorLayer . _initialized = true ;
91
98
for ( const editorType of editorTypes ) {
@@ -131,18 +138,13 @@ class AnnotationEditorLayer {
131
138
}
132
139
133
140
if ( mode !== AnnotationEditorType . NONE ) {
134
- this . div . classList . toggle (
135
- "freeTextEditing" ,
136
- mode === AnnotationEditorType . FREETEXT
137
- ) ;
138
- this . div . classList . toggle (
139
- "inkEditing" ,
140
- mode === AnnotationEditorType . INK
141
- ) ;
142
- this . div . classList . toggle (
143
- "stampEditing" ,
144
- mode === AnnotationEditorType . STAMP
145
- ) ;
141
+ const { classList } = this . div ;
142
+ for ( const editorType of AnnotationEditorLayer . #editorTypes. values ( ) ) {
143
+ classList . toggle (
144
+ `${ editorType . _type } Editing` ,
145
+ mode === editorType . _editorType
146
+ ) ;
147
+ }
146
148
this . div . hidden = false ;
147
149
}
148
150
}
@@ -262,6 +264,11 @@ class AnnotationEditorLayer {
262
264
if ( this . isEmpty ) {
263
265
this . div . hidden = true ;
264
266
}
267
+ const { classList } = this . div ;
268
+ for ( const editorType of AnnotationEditorLayer . #editorTypes. values ( ) ) {
269
+ classList . remove ( `${ editorType . _type } Editing` ) ;
270
+ }
271
+
265
272
this . #isDisabling = false ;
266
273
}
267
274
@@ -458,15 +465,10 @@ class AnnotationEditorLayer {
458
465
* @returns {AnnotationEditor }
459
466
*/
460
467
#createNewEditor( params ) {
461
- switch ( this . #uiManager. getMode ( ) ) {
462
- case AnnotationEditorType . FREETEXT :
463
- return new FreeTextEditor ( params ) ;
464
- case AnnotationEditorType . INK :
465
- return new InkEditor ( params ) ;
466
- case AnnotationEditorType . STAMP :
467
- return new StampEditor ( params ) ;
468
- }
469
- return null ;
468
+ const editorType = AnnotationEditorLayer . #editorTypes. get (
469
+ this . #uiManager. getMode ( )
470
+ ) ;
471
+ return editorType ? new editorType . prototype . constructor ( params ) : null ;
470
472
}
471
473
472
474
/**
@@ -497,18 +499,14 @@ class AnnotationEditorLayer {
497
499
/**
498
500
* Create a new editor
499
501
* @param {Object } data
500
- * @returns {AnnotationEditor }
502
+ * @returns {AnnotationEditor | null }
501
503
*/
502
504
deserialize ( data ) {
503
- switch ( data . annotationType ?? data . annotationEditorType ) {
504
- case AnnotationEditorType . FREETEXT :
505
- return FreeTextEditor . deserialize ( data , this , this . #uiManager) ;
506
- case AnnotationEditorType . INK :
507
- return InkEditor . deserialize ( data , this , this . #uiManager) ;
508
- case AnnotationEditorType . STAMP :
509
- return StampEditor . deserialize ( data , this , this . #uiManager) ;
510
- }
511
- return null ;
505
+ return (
506
+ AnnotationEditorLayer . #editorTypes
507
+ . get ( data . annotationType ?? data . annotationEditorType )
508
+ ?. deserialize ( data , this , this . #uiManager) || null
509
+ ) ;
512
510
}
513
511
514
512
/**
0 commit comments