({
inputCb,
doc,
mirror,
blockClass,
blockSelector,
ignoreClass,
ignoreSelector,
maskInputOptions,
maskInputFn,
sampling,
userTriggeredOnInput,
}: observerParam)
| 380 | export const INPUT_TAGS = ['INPUT', 'TEXTAREA', 'SELECT']; |
| 381 | const lastInputValueMap: WeakMap<EventTarget, inputValue> = new WeakMap(); |
| 382 | function initInputObserver({ |
| 383 | inputCb, |
| 384 | doc, |
| 385 | mirror, |
| 386 | blockClass, |
| 387 | blockSelector, |
| 388 | ignoreClass, |
| 389 | ignoreSelector, |
| 390 | maskInputOptions, |
| 391 | maskInputFn, |
| 392 | sampling, |
| 393 | userTriggeredOnInput, |
| 394 | }: observerParam): listenerHandler { |
| 395 | function eventHandler(event: Event) { |
| 396 | let target = getEventTarget(event) as HTMLElement | null; |
| 397 | const userTriggered = event.isTrusted; |
| 398 | const tagName = target && target.tagName; |
| 399 | |
| 400 | /** |
| 401 | * If a site changes the value 'selected' of an option element, the value of its parent element, usually a select element, will be changed as well. |
| 402 | * We can treat this change as a value change of the select element the current target belongs to. |
| 403 | */ |
| 404 | if (target && tagName === 'OPTION') { |
| 405 | target = dom.parentElement(target); |
| 406 | } |
| 407 | if ( |
| 408 | !target || |
| 409 | !tagName || |
| 410 | INPUT_TAGS.indexOf(tagName) < 0 || |
| 411 | isBlocked(target as Node, blockClass, blockSelector, true) |
| 412 | ) { |
| 413 | return; |
| 414 | } |
| 415 | |
| 416 | if ( |
| 417 | target.classList.contains(ignoreClass) || |
| 418 | (ignoreSelector && target.matches(ignoreSelector)) |
| 419 | ) { |
| 420 | return; |
| 421 | } |
| 422 | let text = (target as HTMLInputElement).value; |
| 423 | let isChecked = false; |
| 424 | const type: Lowercase<string> = getInputType(target) || ''; |
| 425 | |
| 426 | if (type === 'radio' || type === 'checkbox') { |
| 427 | isChecked = (target as HTMLInputElement).checked; |
| 428 | } else if ( |
| 429 | maskInputOptions[tagName.toLowerCase() as keyof MaskInputOptions] || |
| 430 | maskInputOptions[type as keyof MaskInputOptions] |
| 431 | ) { |
| 432 | text = maskInputValue({ |
| 433 | element: target, |
| 434 | maskInputOptions, |
| 435 | tagName, |
| 436 | type, |
| 437 | value: text, |
| 438 | maskInputFn, |
| 439 | }); |
no test coverage detected