diff --git a/src/mask/input_element_adapter.ts b/src/mask/input_element_adapter.ts index 83b8b668ab..0cb0b693a5 100644 --- a/src/mask/input_element_adapter.ts +++ b/src/mask/input_element_adapter.ts @@ -1,5 +1,5 @@ import { InputMaskBase } from "./mask_base"; -import { ITextMaskInputArgs } from "./mask_utils"; +import { ITextInputParams } from "./mask_utils"; export class InputElementAdapter { constructor(private inputMaskInstance: InputMaskBase, private inputElement: HTMLInputElement, value: string = "") { @@ -23,8 +23,8 @@ export class InputElementAdapter { this.inputElement.value = maskedValue; }; - public createArgs(event: any): ITextMaskInputArgs { - const args: ITextMaskInputArgs = { + public createArgs(event: any): ITextInputParams { + const args: ITextInputParams = { insertedChars: event.data, selectionStart: event.target.selectionStart, selectionEnd: event.target.selectionEnd, diff --git a/src/mask/mask_base.ts b/src/mask/mask_base.ts index 50034fde31..31cafa74f4 100644 --- a/src/mask/mask_base.ts +++ b/src/mask/mask_base.ts @@ -1,6 +1,6 @@ import { Base } from "../base"; import { JsonObject, Serializer, property } from "../jsonobject"; -import { IInputMask, IMaskedValue, ITextMaskInputArgs } from "./mask_utils"; +import { IInputMask, IMaskedInputResult, ITextInputParams } from "./mask_utils"; export class InputMaskBase extends Base implements IInputMask { @property() saveMaskedValue: boolean; @@ -36,7 +36,7 @@ export class InputMaskBase extends Base implements IInputMask { // return this.getUnmaskedValue(this.input.value, true); // } - public processInput(args: ITextMaskInputArgs): IMaskedValue { + public processInput(args: ITextInputParams): IMaskedInputResult { return { value: args.prevValue, caretPosition: args.selectionEnd, cancelPreventDefault: false }; } diff --git a/src/mask/mask_currency.ts b/src/mask/mask_currency.ts index 7192f9fd7e..a7b9af5702 100644 --- a/src/mask/mask_currency.ts +++ b/src/mask/mask_currency.ts @@ -1,6 +1,6 @@ import { Serializer, property } from "../jsonobject"; import { InputMaskNumeric } from "./mask_number"; -import { IMaskedValue, ITextMaskInputArgs } from "./mask_utils"; +import { IMaskedInputResult, ITextInputParams } from "./mask_utils"; export class InputMaskCurrency extends InputMaskNumeric { @property() prefix: string; @@ -25,7 +25,7 @@ export class InputMaskCurrency extends InputMaskNumeric { return result; } - public unwrapInputArgs(args: ITextMaskInputArgs): void { + public unwrapInputArgs(args: ITextInputParams): void { let result = args.prevValue; if(!result) return; @@ -40,7 +40,7 @@ export class InputMaskCurrency extends InputMaskNumeric { } args.prevValue = result; } - public processInput(args: ITextMaskInputArgs): IMaskedValue { + public processInput(args: ITextInputParams): IMaskedInputResult { this.unwrapInputArgs(args); const result = super.processInput(args); const preffixPadding = (this.prefix || "").length; diff --git a/src/mask/mask_datetime.ts b/src/mask/mask_datetime.ts index 49723c7345..32f873ee10 100644 --- a/src/mask/mask_datetime.ts +++ b/src/mask/mask_datetime.ts @@ -1,6 +1,6 @@ import { Serializer, property } from "../jsonobject"; import { InputMaskPattern } from "./mask_pattern"; -import { IMaskedValue, ITextMaskInputArgs, numberDefinition } from "./mask_utils"; +import { IMaskedInputResult, ITextInputParams, numberDefinition } from "./mask_utils"; export interface IDateTimeMaskLexem { type: "month" | "day" | "year" | "separator"; @@ -392,7 +392,7 @@ export class InputMaskDateTime extends InputMaskPattern { } } - public processInput(args: ITextMaskInputArgs): IMaskedValue { + public processInput(args: ITextInputParams): IMaskedInputResult { const result = { value: args.prevValue, caretPosition: args.selectionEnd, cancelPreventDefault: false }; const leftPart = args.prevValue.slice(0, args.selectionStart); const rightPart = args.prevValue.slice(args.selectionEnd); diff --git a/src/mask/mask_number.ts b/src/mask/mask_number.ts index 00ec8815dc..4b988d78f4 100644 --- a/src/mask/mask_number.ts +++ b/src/mask/mask_number.ts @@ -1,6 +1,6 @@ import { Serializer, property } from "../jsonobject"; import { InputMaskBase } from "./mask_base"; -import { IMaskedValue, ITextMaskInputArgs, numberDefinition } from "./mask_utils"; +import { IMaskedInputResult, ITextInputParams, numberDefinition } from "./mask_utils"; interface INumericalComposition { integralPart: string; @@ -34,7 +34,7 @@ export class InputMaskNumeric extends InputMaskBase { @property() min: number; @property() max: number; - private calccaretPosition(leftPart: string, args: ITextMaskInputArgs, maskedValue: string) { + private calccaretPosition(leftPart: string, args: ITextInputParams, maskedValue: string) { const leftPartMaskedLength = !! leftPart ? this.displayNumber(this.parseNumber(leftPart), false).length : 0; let validCharIndex = 0; let result = args.selectionStart; @@ -172,7 +172,7 @@ export class InputMaskNumeric extends InputMaskBase { public getUnmaskedValue(src: string): any { return this.getNumberUnmaskedValue(src); } - public processInput(args: ITextMaskInputArgs): IMaskedValue { + public processInput(args: ITextInputParams): IMaskedInputResult { const result = { value: args.prevValue, caretPosition: args.selectionEnd, cancelPreventDefault: false }; const leftPart = args.prevValue.slice(0, args.selectionStart) + (args.insertedChars || ""); const rightPart = args.prevValue.slice(args.selectionEnd); diff --git a/src/mask/mask_pattern.ts b/src/mask/mask_pattern.ts index b46bd6de35..8cccc77cda 100644 --- a/src/mask/mask_pattern.ts +++ b/src/mask/mask_pattern.ts @@ -1,7 +1,7 @@ import { settings } from "../settings"; import { Serializer, property } from "../jsonobject"; import { InputMaskBase } from "./mask_base"; -import { IMaskedValue, ITextMaskInputArgs } from "./mask_utils"; +import { IMaskedInputResult, ITextInputParams } from "./mask_utils"; export interface IMaskLiteral { type: "const" | "regex" | "fixed"; @@ -122,7 +122,7 @@ export class InputMaskPattern extends InputMaskBase { const input = (src === undefined || src === null) ? "" : src; return getUnmaskedValueByPattern(input, this.literals, matchWholeMask); } - public processInput(args: ITextMaskInputArgs): IMaskedValue { + public processInput(args: ITextInputParams): IMaskedInputResult { const result = { value: args.prevValue, caretPosition: args.selectionEnd, cancelPreventDefault: false }; if(!args.insertedChars && args.selectionStart === args.selectionEnd) { return result; diff --git a/src/mask/mask_utils.ts b/src/mask/mask_utils.ts index 3ef260ea78..d5aa3090ea 100644 --- a/src/mask/mask_utils.ts +++ b/src/mask/mask_utils.ts @@ -1,12 +1,12 @@ export var numberDefinition = /[0-9]/; -export interface IMaskedValue { +export interface IMaskedInputResult { value: string; caretPosition: number; cancelPreventDefault?: boolean; } -export interface ITextMaskInputArgs { +export interface ITextInputParams { prevValue: string; selectionStart: number; selectionEnd: number; @@ -17,5 +17,5 @@ export interface ITextMaskInputArgs { export interface IInputMask { getMaskedValue(src: any): string; getUnmaskedValue(src: string): any; - processInput(args: ITextMaskInputArgs): IMaskedValue; + processInput(args: ITextInputParams): IMaskedInputResult; } \ No newline at end of file diff --git a/tests/mask/mask_currency_tests.ts b/tests/mask/mask_currency_tests.ts index 33bdce4add..b67266aa14 100644 --- a/tests/mask/mask_currency_tests.ts +++ b/tests/mask/mask_currency_tests.ts @@ -1,6 +1,6 @@ import { JsonObject } from "../../src/jsonobject"; import { InputMaskCurrency } from "../../src/mask/mask_currency"; -import { ITextMaskInputArgs } from "../../src/mask/mask_utils"; +import { ITextInputParams } from "../../src/mask/mask_utils"; import { QuestionTextModel } from "../../src/question_text"; export default QUnit.module("Currency mask"); @@ -103,7 +103,7 @@ QUnit.test("get currency masked invalid text", function(assert) { maskInstance.prefix = "$_"; maskInstance.suffix = "_USD"; - let args: ITextMaskInputArgs = { prevValue: "$_1_USD", selectionStart: 0, selectionEnd: 0, insertedChars: "" }; + let args: ITextInputParams = { prevValue: "$_1_USD", selectionStart: 0, selectionEnd: 0, insertedChars: "" }; maskInstance.unwrapInputArgs(args); assert.equal(args.prevValue, "1");