Skip to content

Commit

Permalink
work for #4842
Browse files Browse the repository at this point in the history
  • Loading branch information
OlgaLarina committed Mar 1, 2024
1 parent f763770 commit 002b5e2
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/mask/input_element_adapter.ts
Original file line number Diff line number Diff line change
@@ -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 = "") {
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/mask/mask_base.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 };
}

Expand Down
6 changes: 3 additions & 3 deletions src/mask/mask_currency.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/mask/mask_datetime.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/mask/mask_number.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/mask/mask_pattern.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/mask/mask_utils.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}
4 changes: 2 additions & 2 deletions tests/mask/mask_currency_tests.ts
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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");

Expand Down

0 comments on commit 002b5e2

Please sign in to comment.