@@ -31,7 +31,7 @@ export class MaskInput {
31
31
}
32
32
33
33
updateValue ( input : HTMLInputElement ) : void {
34
- if ( input . value !== '' && input . value !== this . processInput ( input ) . masked ) {
34
+ if ( input . value !== '' && input . value !== this . processInput ( input ) ? .masked ) {
35
35
this . setValue ( input , input . value )
36
36
}
37
37
}
@@ -53,11 +53,7 @@ export class MaskInput {
53
53
const mask = new Mask ( parseInput ( input , defaults ) )
54
54
this . items . set ( input , mask )
55
55
56
- queueMicrotask ( ( ) => {
57
- if ( document . body . contains ( input ) ) {
58
- this . updateValue ( input )
59
- }
60
- } )
56
+ queueMicrotask ( ( ) => this . updateValue ( input ) )
61
57
62
58
if ( input . selectionStart === null && mask . isEager ( ) ) {
63
59
console . warn ( 'Maska: input of `%s` type is not supported' , input . type )
@@ -87,7 +83,10 @@ export class MaskInput {
87
83
}
88
84
89
85
const input = e . target as HTMLInputElement
90
- const mask = this . items . get ( input ) as Mask
86
+ const mask = this . items . get ( input )
87
+
88
+ if ( mask === undefined ) return
89
+
91
90
const isDelete = 'inputType' in e && e . inputType . startsWith ( 'delete' )
92
91
const isEager = mask . isEager ( )
93
92
@@ -111,8 +110,11 @@ export class MaskInput {
111
110
const valueNew = input . value
112
111
const leftPart = value . slice ( 0 , pos )
113
112
const leftPartNew = valueNew . slice ( 0 , pos )
114
- const unmasked = this . processInput ( input , leftPart ) . unmasked
115
- const unmaskedNew = this . processInput ( input , leftPartNew ) . unmasked
113
+ const unmasked = this . processInput ( input , leftPart ) ?. unmasked
114
+ const unmaskedNew = this . processInput ( input , leftPartNew ) ?. unmasked
115
+
116
+ if ( unmasked === undefined || unmaskedNew === undefined ) return
117
+
116
118
let posFixed = pos
117
119
118
120
if ( leftPart !== leftPartNew ) {
@@ -127,6 +129,8 @@ export class MaskInput {
127
129
private setValue ( input : HTMLInputElement , value : string ) : void {
128
130
const detail = this . processInput ( input , value )
129
131
132
+ if ( detail === undefined ) return
133
+
130
134
input . value = detail . masked
131
135
132
136
if ( this . options . onMaska != null ) {
@@ -141,8 +145,11 @@ export class MaskInput {
141
145
input . dispatchEvent ( new CustomEvent ( 'input' , { detail : detail . masked } ) )
142
146
}
143
147
144
- private processInput ( input : HTMLInputElement , value ?: string ) : MaskaDetail {
145
- const mask = this . items . get ( input ) as Mask
148
+ private processInput ( input : HTMLInputElement , value ?: string ) : MaskaDetail | undefined {
149
+ const mask = this . items . get ( input )
150
+
151
+ if ( mask === undefined ) return undefined
152
+
146
153
let valueNew = value ?? input . value
147
154
148
155
if ( this . options . preProcess != null ) {
0 commit comments