@@ -21,38 +21,59 @@ export default class DropDownButton extends TextEditorButton {
2121 this . currentTemplate = null ;
2222 }
2323
24- _attachEvents ( instance ) : void {
25- const { editor } = this ;
26-
24+ _attachEvents ( instance : Button ) : void {
2725 instance . option ( 'onClick' , ( e ) => {
28- // @ts -expect-error
29- if ( editor . _shouldCallOpenHandler ?.( ) ) {
30- // @ts -expect-error
31- editor . _openHandler ( e ) ;
26+ // @ts -expect-error _shouldCallOpenHandler should be typed
27+ if ( this . editor ? ._shouldCallOpenHandler ?.( ) ) {
28+ // @ts -expect-error _openHandler should be typed
29+ this . editor ? ._openHandler ( e ) ;
3230 return ;
3331 }
34- // @ts -expect-error
35- ! editor . option ( 'openOnFieldClick' ) && editor . _openHandler ( e ) ;
32+
33+ // @ts -expect-error openOnFieldClick should be typed
34+ const { openOnFieldClick } = this . editor ?. option ( ) ?? { } ;
35+
36+ if ( ! openOnFieldClick ) {
37+ // @ts -expect-error _openHandler should be typed
38+ this . editor ?. _openHandler ( e ) ;
39+ }
3640 } ) ;
3741
3842 eventsEngine . on ( instance . $element ( ) , 'mousedown' , ( e ) => {
39- if ( editor . $element ( ) . is ( '.dx-state-focused' ) ) {
43+ if ( this . editor ? .$element ( ) ? .is ( '.dx-state-focused' ) ) {
4044 e . preventDefault ( ) ;
4145 }
4246 } ) ;
4347 }
4448
4549 _create ( ) : {
46- $element : dxElementWrapper ;
4750 instance : Button ;
48- } {
51+ $element : dxElementWrapper ;
52+ } | undefined {
4953 const { editor } = this ;
54+
55+ if ( ! editor ) {
56+ return undefined ;
57+ }
58+
5059 const $element = $ ( '<div>' ) ;
5160 const options = this . _getOptions ( ) ;
5261
5362 this . _addToContainer ( $element ) ;
5463
55- const instance = editor . _createComponent ( $element , Button , extend ( { } , options , { elementAttr : { 'aria-label' : messageLocalization . format ( BUTTON_MESSAGE ) } } ) ) ;
64+ const instance = editor . _createComponent (
65+ $element ,
66+ Button ,
67+ extend (
68+ { } ,
69+ options ,
70+ {
71+ elementAttr : {
72+ 'aria-label' : messageLocalization . format ( BUTTON_MESSAGE ) ,
73+ } ,
74+ } ,
75+ ) ,
76+ ) ;
5677
5778 this . _legacyRender ( editor . $element ( ) , $element , options . visible ) ;
5879
@@ -65,7 +86,7 @@ export default class DropDownButton extends TextEditorButton {
6586 _getOptions ( ) {
6687 const { editor } = this ;
6788 const visible = this . _isVisible ( ) ;
68- const isReadOnly = editor . option ( 'readOnly' ) ;
89+ const isReadOnly = editor ? .option ( 'readOnly' ) ;
6990 const options = {
7091 focusStateEnabled : false ,
7192 hoverStateEnabled : false ,
@@ -82,7 +103,7 @@ export default class DropDownButton extends TextEditorButton {
82103 _isVisible ( ) : boolean {
83104 const { editor } = this ;
84105 // @ts -expect-error
85- return super . _isVisible ( ) && editor . option ( 'showDropDownButton' ) ;
106+ return super . _isVisible ( ) && editor ? .option ( 'showDropDownButton' ) ;
86107 }
87108
88109 // TODO: get rid of it
@@ -98,13 +119,13 @@ export default class DropDownButton extends TextEditorButton {
98119 }
99120
100121 _isSameTemplate ( ) {
101- return this . editor . option ( 'dropDownButtonTemplate' ) === this . currentTemplate ;
122+ return this . editor ? .option ( 'dropDownButtonTemplate' ) === this . currentTemplate ;
102123 }
103124
104125 _addTemplate ( options ) : void {
105126 if ( ! this . _isSameTemplate ( ) ) {
106- options . template = this . editor . _getTemplateByOption ( 'dropDownButtonTemplate' ) ;
107- this . currentTemplate = this . editor . option ( 'dropDownButtonTemplate' ) ;
127+ options . template = this . editor ? ._getTemplateByOption ( 'dropDownButtonTemplate' ) ;
128+ this . currentTemplate = this . editor ? .option ( 'dropDownButtonTemplate' ) ;
108129 }
109130 }
110131
@@ -114,11 +135,14 @@ export default class DropDownButton extends TextEditorButton {
114135
115136 if ( shouldUpdate ) {
116137 const { editor, instance } = this ;
117- const $editor = editor . $element ( ) ;
138+
139+ const $editor = editor ?. $element ( ) ;
118140 const options = this . _getOptions ( ) ;
141+
119142 // @ts -expect-error
120143 instance ?. option ( options ) ;
121- this . _legacyRender ( $editor , instance ?. $element ( ) , options . visible ) ;
144+
145+ this . _legacyRender ( $editor , ( instance as Button ) ?. $element ( ) , options . visible ) ;
122146 }
123147 }
124148}
0 commit comments