Skip to content

Commit

Permalink
feat: remove beforeInput function
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielcursino committed Sep 28, 2022
1 parent e07efd2 commit 84693ce
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 12 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ The recommended way to do a new mask is writing a class that extends `MaskOption
interface MaskOptions {
instance: MaskCore;
init?(data: MaskData): void;
beforeInput?(data: MaskData): void;
input?(data: MaskData): void;
format(data: MaskData): void;
focus?(data: MaskData): void;
Expand Down
11 changes: 0 additions & 11 deletions src/core.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export interface MaskOptions {
instance: MaskCore;
init?(data: MaskData): void;
beforeInput?(data: MaskData): void;
input?(data: MaskData): void;
format(data: MaskData): void;
focus?(data: MaskData): void;
Expand Down Expand Up @@ -73,23 +72,13 @@ export class MaskCore {
this.el.removeEventListener('mouseout', this.mouseoutFunc);
}

private beforeInput() {
const cursorPosition = this.data.cursorPosition = this.el.selectionStart ?? 0;

this.options.beforeInput && this.options.beforeInput(this.data);

if (this.data.cursorPosition != cursorPosition) this.setCursorPosition(this.data.cursorPosition);
}

private input(e: Event) {
if ((e as any).__mask__) return e.preventDefault();

this.data.delete =
(e as InputEvent).inputType === 'deleteContentBackward' ||
(e as InputEvent).inputType === 'deleteContentForward';

this.beforeInput();

this.data.inputRaw = this.data.input = (e.target as HTMLInputElement).value;
const cursorPosition = this.data.cursorPosition = this.el.selectionStart ?? 0;

Expand Down

0 comments on commit 84693ce

Please sign in to comment.