1+ import type { LabelMode } from '@js/common' ;
12import { name as click } from '@js/common/core/events/click' ;
23import { active } from '@js/common/core/events/core/emitter.feedback' ;
34import eventsEngine from '@js/common/core/events/core/events_engine' ;
@@ -19,10 +20,26 @@ const LABEL_BEFORE_CLASS = 'dx-label-before';
1920const LABEL_CLASS = 'dx-label' ;
2021const LABEL_AFTER_CLASS = 'dx-label-after' ;
2122
22- class TextEditorLabel {
23+ export interface TextEditorLabelProperties {
24+ $editor : dxElementWrapper ;
25+ text ?: string ;
26+ mark ?: string ;
27+ mode ?: LabelMode ;
28+ rtlEnabled ?: boolean ;
29+ containsButtonsBefore ?: boolean ;
30+ beforeWidth ?: number ;
31+ containerWidth ?: number ;
32+ getContainerWidth : ( ) => number ;
33+ getBeforeWidth : ( ) => number ;
34+ onClickHandler : ( ) => void ;
35+ onHoverHandler : ( e : MouseEvent | PointerEvent ) => void ;
36+ onActiveHandler : ( e : MouseEvent | PointerEvent ) => void ;
37+ }
38+
39+ export class TextEditorLabel {
2340 public NAME : string ;
2441
25- _props : any ;
42+ _props : TextEditorLabelProperties ;
2643
2744 _id : string ;
2845
@@ -36,7 +53,7 @@ class TextEditorLabel {
3653
3754 _$root ! : dxElementWrapper ;
3855
39- constructor ( props ) {
56+ constructor ( props : TextEditorLabelProperties ) {
4057 this . NAME = 'dxLabel' ;
4158 this . _props = props ;
4259
@@ -97,25 +114,24 @@ class TextEditorLabel {
97114 eventsEngine . off ( this . _$labelSpan , activeEventName ) ;
98115
99116 if ( this . _isVisible ( ) && this . _isOutsideMode ( ) ) {
100- eventsEngine . on ( this . _$labelSpan , clickEventName , ( e ) => {
101- // @ts -expect-error
102- const selectedText = getWindow ( ) . getSelection ( ) . toString ( ) ;
117+ eventsEngine . on ( this . _$labelSpan , clickEventName , ( e : MouseEvent ) => {
118+ const selectedText = getWindow ( ) ?. getSelection ( ) ?. toString ( ) ;
103119
104120 if ( selectedText === '' ) {
105121 this . _props . onClickHandler ( ) ;
106122 e . preventDefault ( ) ;
107123 }
108124 } ) ;
109- eventsEngine . on ( this . _$labelSpan , hoverStartEventName , ( e ) => {
125+ eventsEngine . on ( this . _$labelSpan , hoverStartEventName , ( e : MouseEvent ) => {
110126 this . _props . onHoverHandler ( e ) ;
111127 } ) ;
112- eventsEngine . on ( this . _$labelSpan , activeEventName , ( e ) => {
128+ eventsEngine . on ( this . _$labelSpan , activeEventName , ( e : MouseEvent ) => {
113129 this . _props . onActiveHandler ( e ) ;
114130 } ) ;
115131 }
116132 }
117133
118- _updateEditorLabelClass ( visible ) : void {
134+ _updateEditorLabelClass ( visible : boolean ) : void {
119135 this . _props . $editor
120136 . removeClass ( TEXTEDITOR_WITH_FLOATING_LABEL_CLASS )
121137 . removeClass ( TEXTEDITOR_LABEL_OUTSIDE_CLASS )
@@ -134,7 +150,7 @@ class TextEditorLabel {
134150 }
135151 }
136152
137- _isOutsideMode ( ) {
153+ _isOutsideMode ( ) : boolean {
138154 return this . _props . mode === 'outside' ;
139155 }
140156
@@ -150,18 +166,18 @@ class TextEditorLabel {
150166 }
151167
152168 _updateMark ( ) : void {
153- this . _$labelSpan . attr ( 'data-mark' , this . _props . mark ) ;
169+ this . _$labelSpan . attr ( 'data-mark' , this . _props . mark ?? null ) ;
154170 }
155171
156172 _updateText ( ) : void {
157- this . _$labelSpan . text ( this . _props . text ) ;
173+ this . _$labelSpan . text ( this . _props . text ?? '' ) ;
158174 }
159175
160176 _updateBeforeWidth ( ) : void {
161177 if ( this . _isVisible ( ) ) {
162178 const width = this . _props . beforeWidth ?? this . _props . getBeforeWidth ( ) ;
163- // @ts -expect-error
164- this . _$before . css ( { width } ) ;
179+
180+ this . _$before ? .css ( { width } ) ;
165181
166182 this . _updateLabelTransform ( ) ;
167183 }
@@ -186,55 +202,54 @@ class TextEditorLabel {
186202 }
187203 }
188204
189- $element ( ) {
205+ $element ( ) : dxElementWrapper {
190206 return this . _$root ;
191207 }
192208
193- isVisible ( ) {
209+ isVisible ( ) : boolean {
194210 return this . _isVisible ( ) ;
195211 }
196212
197- // @ts -expect-error
198- getId ( ) {
199- if ( this . _isVisible ( ) ) return this . _id ;
213+ getId ( ) : string | undefined {
214+ if ( this . _isVisible ( ) ) {
215+ return this . _id ;
216+ }
217+
218+ return undefined ;
200219 }
201220
202- updateMode ( mode ) : void {
221+ updateMode ( mode : LabelMode ) : void {
203222 this . _props . mode = mode ;
204223 this . _toggleMarkupVisibility ( ) ;
205224 this . _updateBeforeWidth ( ) ;
206225 this . _updateMaxWidth ( ) ;
207226 }
208227
209- updateText ( text ) : void {
228+ updateText ( text : string ) : void {
210229 this . _props . text = text ;
211230 this . _updateText ( ) ;
212231 this . _toggleMarkupVisibility ( ) ;
213232 this . _updateBeforeWidth ( ) ;
214233 this . _updateMaxWidth ( ) ;
215234 }
216235
217- updateMark ( mark ) : void {
236+ updateMark ( mark : string ) : void {
218237 this . _props . mark = mark ;
219238 this . _updateMark ( ) ;
220239 }
221240
222- updateContainsButtonsBefore ( containsButtonsBefore ) : void {
241+ updateContainsButtonsBefore ( containsButtonsBefore : boolean ) : void {
223242 this . _props . containsButtonsBefore = containsButtonsBefore ;
224243 this . _updateEditorBeforeButtonsClass ( ) ;
225244 }
226245
227- updateBeforeWidth ( beforeWidth ) : void {
246+ updateBeforeWidth ( beforeWidth : number ) : void {
228247 this . _props . beforeWidth = beforeWidth ;
229248 this . _updateBeforeWidth ( ) ;
230249 }
231250
232- updateMaxWidth ( containerWidth ) : void {
251+ updateMaxWidth ( containerWidth : number ) : void {
233252 this . _props . containerWidth = containerWidth ;
234253 this . _updateMaxWidth ( ) ;
235254 }
236255}
237-
238- export {
239- TextEditorLabel ,
240- } ;
0 commit comments