Skip to content

Commit

Permalink
refactor: use element.matches(':focus')
Browse files Browse the repository at this point in the history
  • Loading branch information
nsbarsukov committed Jan 23, 2024
1 parent c0828a7 commit 6b314fa
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 26 deletions.
1 change: 0 additions & 1 deletion projects/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export {
MaskitoPreprocessor,
} from './lib/types';
export {
maskitoGetFocused,
maskitoInitialCalibrationPlugin,
maskitoPipe,
maskitoStrictCompositionPlugin,
Expand Down
3 changes: 1 addition & 2 deletions projects/core/src/lib/mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
getWordSelection,
isRedo,
isUndo,
maskitoGetFocused,
maskitoPipe,
maskitoTransform,
} from './utils';
Expand Down Expand Up @@ -160,7 +159,7 @@ export class Maskito extends MaskHistory {
const {element} = this;

if (
maskitoGetFocused(element.ownerDocument) === element &&
element.matches(':focus') &&
(element.selectionStart !== from || element.selectionEnd !== to)
) {
element.setSelectionRange?.(from, to);
Expand Down
18 changes: 0 additions & 18 deletions projects/core/src/lib/utils/dom/get-focused.ts

This file was deleted.

3 changes: 1 addition & 2 deletions projects/core/src/lib/utils/dom/update-element.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {ElementState} from '../../types';
import {maskitoGetFocused} from './get-focused';

/**
* Sets value to element, and dispatches input event
Expand All @@ -24,7 +23,7 @@ export function maskitoUpdateElement(

element.value = valueOrElementState.value;

if (maskitoGetFocused(element.ownerDocument) === element) {
if (element.matches(':focus')) {
element.setSelectionRange?.(from, to);
}
}
Expand Down
1 change: 0 additions & 1 deletion projects/core/src/lib/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './dom/event-listener';
export * from './dom/get-focused';
export * from './dom/history-events';
export * from './dom/update-element';
export * from './element-states-equality';
Expand Down
4 changes: 2 additions & 2 deletions projects/kit/src/lib/plugins/caret-guard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {maskitoGetFocused, MaskitoPlugin} from '@maskito/core';
import {MaskitoPlugin} from '@maskito/core';

import {clamp} from '../utils';

Expand All @@ -17,7 +17,7 @@ export function maskitoCaretGuard(
};

const listener = (): void => {
if (maskitoGetFocused(document) !== element) {
if (!element.matches(':focus')) {
return;
}

Expand Down

0 comments on commit 6b314fa

Please sign in to comment.