devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
777 lines (776 loc) • 30.4 kB
JavaScript
/**
* DevExtreme (esm/__internal/ui/number_box/number_box.mask.js)
* Version: 26.1.6
* Build date: Fri Oct 16 2026
*
* Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
import eventsEngine from "../../../common/core/events/core/events_engine";
import {
name as dxDblClickEvent
} from "../../../common/core/events/double_click";
import {
addNamespace,
getChar,
isCommandKeyPressed,
normalizeKeyName
} from "../../../common/core/events/utils/index";
import number from "../../../common/core/localization/number";
import devices from "../../../core/devices";
import {
escapeRegExp
} from "../../../core/utils/common";
import {
fitIntoRange,
inRange
} from "../../../core/utils/math";
import {
isDefined,
isFunction,
isNumeric,
isPlainObject,
isString
} from "../../../core/utils/type";
import {
getGlobalFormatByDataType
} from "../../core/global_format_config";
import {
getFormat as getLDMLFormat
} from "../../core/localization/ldml/number";
import NumberBoxBase from "./number_box.base";
import {
getCaretAfterFormat,
getCaretBoundaries,
getCaretInBoundaries,
getCaretOffset,
getCaretWithOffset,
isCaretInBoundaries
} from "./number_box.caret";
import {
adjustPercentValue,
asPattern,
getNthOccurrence,
getRealSeparatorIndex,
splitByIndex
} from "./utils";
const NUMBER_FORMATTER_NAMESPACE = "dxNumberFormatter";
const MOVE_FORWARD = 1;
const MOVE_BACKWARD = -1;
const MINUS = "-";
const MINUS_KEY = "minus";
const INPUT_EVENT = "input";
const NUMPAD_DOT_KEY_CODE = 110;
const CARET_TIMEOUT_DURATION = 0;
const asFormatObject = format => isPlainObject(format) ? format : void 0;
const isNegativeValue = value => {
const parsedValue = Number(value);
return parsedValue < 0 || 1 / parsedValue === -1 / 0
};
class NumberBoxMask extends NumberBoxBase {
_getDefaultOptions() {
return Object.assign({}, super._getDefaultOptions(), {
useMaskBehavior: true,
format: null
})
}
_isDeleteKey(key) {
return "del" === key
}
_supportedKeys() {
if (!this._useMaskBehavior()) {
return super._supportedKeys()
}
return Object.assign({}, super._supportedKeys(), {
minus: e => this._revertSign(e),
del: e => this._removeHandler(e),
backspace: e => this._removeHandler(e),
leftArrow: e => this._arrowHandler(-1, e),
rightArrow: e => this._arrowHandler(1, e),
home: e => this._boundaryKeyHandler(1, e),
enter: () => this._updateFormattedValue(),
end: e => this._boundaryKeyHandler(-1, e)
})
}
_getEffectiveFormatOption() {
const {
format: format
} = this.option();
return isDefined(format) ? format : getGlobalFormatByDataType("number")
}
_getTextSeparatorIndex(text) {
const decimalSeparator = number.getDecimalSeparator();
const realSeparatorOccurrenceIndex = getRealSeparatorIndex(this._getFormatPattern()).occurrence;
return getNthOccurrence(text, decimalSeparator, realSeparatorOccurrenceIndex)
}
_focusInHandler(e) {
if (!this._preventNestedFocusEvent(e)) {
this.clearCaretTimeout();
this._caretTimeout = setTimeout(() => {
this._caretTimeout = void 0;
const caret = this._caret();
if ((null === caret || void 0 === caret ? void 0 : caret.start) === (null === caret || void 0 === caret ? void 0 : caret.end) && this._useMaskBehavior()) {
const text = this._getInputVal();
const decimalSeparatorIndex = this._getTextSeparatorIndex(text);
if (decimalSeparatorIndex >= 0) {
this._caret({
start: decimalSeparatorIndex,
end: decimalSeparatorIndex
})
} else {
this._moveCaretToBoundary(-1)
}
}
}, 0)
}
super._focusInHandler(e)
}
_focusOutHandler(e) {
const shouldHandleEvent = !this._preventNestedFocusEvent(e);
if (shouldHandleEvent) {
this._focusOutOccurs = true;
if (this._useMaskBehavior()) {
this._updateFormattedValue()
}
}
super._focusOutHandler(e);
if (shouldHandleEvent) {
this._focusOutOccurs = false
}
}
_hasValueBeenChanged(inputValue) {
const format = this._getFormatPattern();
const {
value: value
} = this.option();
const formatted = this._format(value, format) || "";
return formatted !== inputValue
}
_updateFormattedValue() {
const inputValue = this._getInputVal();
if (this._hasValueBeenChanged(inputValue)) {
this._updateParsedValue();
this._adjustParsedValue();
this._setTextByParsedValue();
const {
value: value
} = this.option();
if (this._parsedValue !== value) {
eventsEngine.trigger(this._input(), "change")
}
}
}
_arrowHandler(step, e) {
if (!this._useMaskBehavior()) {
return
}
const caret = this._caret();
if (!caret) {
return
}
const text = this._getInputVal();
const format = this._getFormatPattern();
const nextCaret = getCaretWithOffset(caret, step);
if (!isCaretInBoundaries(nextCaret, text, format)) {
const nextCaretPosition = 1 === step ? nextCaret.end : nextCaret.start;
e.preventDefault();
this._caret(getCaretInBoundaries(nextCaretPosition, text, format));
this._scrollInputTo(1 === step ? "end" : "start")
}
}
_scrollInputTo(edge) {
const inputElement = this._input().get(0);
if (!inputElement) {
return
}
inputElement.scrollLeft = "end" === edge ? inputElement.scrollWidth : 0
}
_moveCaretToBoundary(direction) {
const boundaries = getCaretBoundaries(this._getInputVal(), this._getFormatPattern());
const newCaret = getCaretWithOffset(1 === direction ? boundaries.start : boundaries.end, 0);
this._caret(newCaret)
}
_boundaryKeyHandler(direction, e) {
if (!this._useMaskBehavior() || e.shiftKey) {
return
}
this._moveCaretToBoundary(direction);
e.preventDefault();
this._scrollInputTo(1 === direction ? "start" : "end")
}
_shouldMoveCaret(text, caret) {
if (!caret) {
return false
}
const decimalSeparator = number.getDecimalSeparator();
const isDecimalSeparatorNext = text.charAt(caret.end ?? 0) === decimalSeparator;
const isSeparatorKey = this._lastKey === decimalSeparator || "." === this._lastKey || "," === this._lastKey;
return isSeparatorKey && isDecimalSeparatorNext
}
_getInputVal() {
const inputValue = number.convertDigits(this._input().val(), true);
return inputValue
}
_keyboardHandler(e) {
this.clearCaretTimeout();
this._lastKey = number.convertDigits(getChar(e), true);
this._lastKeyName = normalizeKeyName(e);
if (!this._shouldHandleKey(e.originalEvent)) {
return super._keyboardHandler(e)
}
const normalizedText = this._getInputVal();
const caret = this._caret();
let enteredChar = this._lastKey;
if ("minus" === this._lastKeyName) {
enteredChar = ""
} else if (110 === e.which) {
enteredChar = number.getDecimalSeparator()
}
const newValue = this._tryParse(normalizedText, caret, enteredChar);
if (this._shouldMoveCaret(normalizedText, caret)) {
this._moveCaret(1);
e.originalEvent.preventDefault()
}
if (void 0 === newValue) {
if ("minus" !== this._lastKeyName) {
e.originalEvent.preventDefault()
}
} else {
this._parsedValue = newValue
}
return super._keyboardHandler(e)
}
_keyPressHandler(e) {
if (!this._useMaskBehavior()) {
super._keyPressHandler(e)
}
}
_removeHandler(e) {
const caret = this._caret();
const text = this._getInputVal();
let {
start: start = 0,
end: end = 0
} = caret ?? {};
this._lastKey = getChar(e);
this._lastKeyName = normalizeKeyName(e);
const isDeleteKey = this._isDeleteKey(this._lastKeyName);
const isBackspaceKey = !isDeleteKey;
if (start === end) {
const caretPosition = start;
const canDelete = isBackspaceKey && caretPosition > 0 || isDeleteKey && caretPosition < text.length;
if (canDelete) {
if (isDeleteKey) {
end += 1
} else {
start -= 1
}
} else {
e.preventDefault();
return
}
}
const char = text.slice(start, end);
if (this._isStub(char)) {
this._moveCaret(isDeleteKey ? 1 : -1);
if (isNegativeValue(this._parsedValue)) {
this._revertSign(e);
this._setTextByParsedValue();
const {
valueChangeEvent: valueChangeEvent
} = this.option();
const shouldTriggerInputEvent = null === valueChangeEvent || void 0 === valueChangeEvent ? void 0 : valueChangeEvent.split(" ").includes("input");
if (shouldTriggerInputEvent) {
eventsEngine.trigger(this._input(), "input")
}
}
e.preventDefault();
return
}
const decimalSeparator = number.getDecimalSeparator();
if (char === decimalSeparator) {
const decimalSeparatorIndex = text.indexOf(decimalSeparator);
if (this._isNonStubAfter(decimalSeparatorIndex + 1)) {
this._moveCaret(isDeleteKey ? 1 : -1);
e.preventDefault()
}
return
}
if (end - start < text.length) {
const editedText = this._replaceSelectedText(text, {
start: start,
end: end
}, "");
const noDigits = editedText.search(/[0-9]/) < 0;
if (noDigits && this._isValueInRange(0)) {
this._parsedValue = isNegativeValue(this._parsedValue) ? -0 : 0;
return
}
}
const valueAfterRemoving = this._tryParse(text, {
start: start,
end: end
}, "");
if (void 0 === valueAfterRemoving) {
e.preventDefault()
} else {
this._parsedValue = valueAfterRemoving
}
}
_isPercentFormat() {
const noEscapedFormat = asPattern(this._getFormatPattern()).replace(/'[^']+'/g, "");
return noEscapedFormat.includes("%")
}
_parse(text, format) {
var _asFormatObject;
const customParser = null === (_asFormatObject = asFormatObject(this._getEffectiveFormatOption())) || void 0 === _asFormatObject ? void 0 : _asFormatObject.parser;
if (isFunction(customParser)) {
const customParsedValue = customParser(text);
return customParsedValue instanceof Date ? void 0 : customParsedValue
}
let integerPartStartIndex = 0;
if (isString(format)) {
const formatPointIndex = getRealSeparatorIndex(format).index;
const textPointIndex = this._getTextSeparatorIndex(text);
const formatIntegerPartLength = -1 !== formatPointIndex ? formatPointIndex : format.length;
const textIntegerPartLength = -1 !== textPointIndex ? textPointIndex : text.length;
if (textIntegerPartLength > formatIntegerPartLength && !format.includes("#")) {
integerPartStartIndex = textIntegerPartLength - formatIntegerPartLength
}
}
return number.parse(text.substr(integerPartStartIndex), isString(format) ? format : asFormatObject(format))
}
_format(value, format) {
var _asFormatObject2;
const formatOption = this._getEffectiveFormatOption();
const customFormatter = (null === (_asFormatObject2 = asFormatObject(formatOption)) || void 0 === _asFormatObject2 ? void 0 : _asFormatObject2.formatter) ?? formatOption;
const formatter = isFunction(customFormatter) ? customFormatter : number.format;
return isDefined(value) ? formatter(value, format) : ""
}
_getFormatPattern() {
if (!this._currentFormat) {
this._updateFormat()
}
return this._currentFormat
}
_updateFormat() {
const format = this._getEffectiveFormatOption();
const formatObject = asFormatObject(format);
const isCustomParser = isFunction(null === formatObject || void 0 === formatObject ? void 0 : formatObject.parser);
const isLDMLPattern = isString(format) && (format.includes("0") || format.includes("#"));
const isExponentialFormat = "exponential" === format || "exponential" === (null === formatObject || void 0 === formatObject ? void 0 : formatObject.type);
const shouldUseFormatAsIs = isCustomParser || isLDMLPattern || isExponentialFormat;
this._currentFormat = shouldUseFormatAsIs ? format : getLDMLFormat(value => {
const text = this._format(value, format) ?? "";
const convertedText = number.convertDigits(text, true);
return convertedText
})
}
_getFormatForSign(text) {
const format = this._getFormatPattern();
if (isString(format)) {
const signParts = format.split(";");
const sign = number.getSign(text, format);
signParts[1] = signParts[1] || `-${signParts[0]}`;
return sign < 0 ? signParts[1] : signParts[0]
}
const sign = number.getSign(text);
return sign < 0 ? "-" : ""
}
_removeStubs(text, excludeComma) {
const format = this._getFormatForSign(text);
const thousandsSeparator = number.getThousandsSeparator();
const stubs = this._getStubs(format);
let result = text;
if (stubs.length) {
const prefixStubs = stubs[0];
const postfixRegex = new RegExp(`(${escapeRegExp(stubs[1]||"")})$`, "g");
const decoratorsRegex = new RegExp(`[-${escapeRegExp(excludeComma?"":thousandsSeparator)}]`, "g");
result = result.replace(prefixStubs, "").replace(postfixRegex, "").replace(decoratorsRegex, "")
}
return result
}
_getStubs(format) {
const patternMatch = /[^']([#0.,]+)/g.exec(format);
const pattern = null === patternMatch || void 0 === patternMatch ? void 0 : patternMatch[0].trim();
const stubs = isDefined(pattern) ? format.split(pattern) : [format];
return stubs.map(stub => stub.replace(/'/g, ""))
}
_truncateToPrecision(value, maxPrecision) {
if (isDefined(value)) {
const strValue = value.toString();
const decimalSeparatorIndex = strValue.indexOf(".");
if (strValue && decimalSeparatorIndex > -1) {
const truncatedValue = strValue.substr(0, decimalSeparatorIndex + maxPrecision + 1);
const parsedValue = parseFloat(truncatedValue);
return isNaN(parsedValue) ? value : parsedValue
}
}
return value
}
_tryParse(text, selection, char) {
var _asFormatObject3;
const {
start: start = 0,
end: end = 0
} = selection ?? {};
const isTextSelected = start !== end;
const isWholeTextSelected = isTextSelected && 0 === start && end === text.length;
const decimalSeparator = number.getDecimalSeparator();
if (isWholeTextSelected && char === decimalSeparator) {
return 0
}
const editedText = this._replaceSelectedText(text, {
start: start,
end: end
}, char ?? void 0);
const format = this._getFormatPattern();
const hasCustomParser = isFunction(null === (_asFormatObject3 = asFormatObject(format)) || void 0 === _asFormatObject3 ? void 0 : _asFormatObject3.parser);
let parsedValue = this._getParsedValue(editedText, format);
const maxPrecision = hasCustomParser ? void 0 : this._getPrecisionLimits(this._getFormatForSign(editedText)).max;
const isValueChanged = parsedValue !== this._parsedValue;
const isDecimalPointRestricted = char === decimalSeparator && 0 === maxPrecision;
const isUselessCharRestricted = !isTextSelected && !isValueChanged && "-" !== char && this._isStub(char);
if (isDecimalPointRestricted || isUselessCharRestricted) {
return
}
if ("" === this._removeStubs(editedText)) {
parsedValue = Math.abs(0 * Number(this._parsedValue))
}
if (isNaN(Number(parsedValue))) {
return
}
const value = null === parsedValue ? this._parsedValue : parsedValue;
parsedValue = maxPrecision ? this._truncateToPrecision(value, maxPrecision) : parsedValue;
if (!hasCustomParser && this._isPercentFormat()) {
const interval = this._getIntervalFromPrecision(maxPrecision ?? 0);
return adjustPercentValue(parsedValue, interval)
}
return parsedValue
}
_getIntervalFromPrecision(precision) {
if (precision < 1) {
return 1
}
return 10 ** -precision
}
_getParsedValue(text, format) {
var _asFormatObject4;
const signFormat = (null === (_asFormatObject4 = asFormatObject(format)) || void 0 === _asFormatObject4 ? void 0 : _asFormatObject4.formatter) ?? format;
const sign = number.getSign(text, signFormat);
const textWithoutStubs = this._removeStubs(text, true);
const parsedValue = this._parse(textWithoutStubs, format);
const parsedValueSign = Number(parsedValue) < 0 ? -1 : 1;
const shouldRevertSign = isNumeric(parsedValue) && sign !== parsedValueSign;
return shouldRevertSign ? sign * parsedValue : parsedValue
}
_isValueIncomplete(text) {
var _asFormatObject5;
if (!this._useMaskBehavior()) {
return super._isValueIncomplete(text)
}
const caret = this._caret();
const point = number.getDecimalSeparator();
const pointIndex = this._getTextSeparatorIndex(text);
const isCaretOnFloat = pointIndex >= 0 && pointIndex < ((null === caret || void 0 === caret ? void 0 : caret.start) ?? 0);
const textParts = this._removeStubs(text, true).split(point);
if (!isCaretOnFloat || 2 !== textParts.length) {
return false
}
const floatLength = textParts[1].length;
const endsWithZero = "0" === textParts[1].charAt(floatLength - 1);
const isFloatPartComplete = endsWithZero || !floatLength;
const format = this._getFormatPattern();
if (isFunction(null === (_asFormatObject5 = asFormatObject(format)) || void 0 === _asFormatObject5 ? void 0 : _asFormatObject5.parser)) {
return isFloatPartComplete
}
const precision = this._getPrecisionLimits(this._getFormatForSign(asPattern(format)));
return inRange(floatLength, precision.min, precision.max) && isFloatPartComplete
}
_isValueInRange(value) {
const {
min: min,
max: max
} = this.option();
return inRange(value, min ?? -1 / 0, max ?? 1 / 0)
}
_setInputText(text) {
const normalizedText = number.convertDigits(text, true);
const caret = this._caret();
const newCaret = caret && getCaretAfterFormat(this._getInputVal(), normalizedText, caret, this._getFormatPattern());
this._input().val(text);
this._toggleEmptinessEventHandler();
this._formattedValue = text;
if (newCaret && !this._focusOutOccurs) {
this._caret(newCaret)
}
}
_useMaskBehavior() {
const {
useMaskBehavior: useMaskBehavior
} = this.option();
return !!this._getEffectiveFormatOption() && !!useMaskBehavior
}
_renderInputType() {
const {
mode: mode
} = this.option();
const isNumberType = "number" === mode;
const isDesktop = "desktop" === devices.real().deviceType;
if (this._useMaskBehavior() && isNumberType) {
this._setInputType(isDesktop || this._isSupportInputMode() ? "text" : "tel")
} else {
super._renderInputType()
}
}
_isChar(str) {
return isString(str) && 1 === str.length
}
_moveCaret(offset) {
const caret = this._caret();
if (!offset || !caret) {
return
}
const newCaret = getCaretWithOffset(caret, offset);
const adjustedCaret = getCaretInBoundaries(newCaret, this._getInputVal(), this._getFormatPattern());
this._caret(adjustedCaret)
}
_shouldHandleKey(e) {
const keyName = normalizeKeyName(e);
const isSpecialChar = isCommandKeyPressed(e) || e.altKey || e.shiftKey || !this._isChar(keyName);
const isMinusKey = "minus" === keyName;
const useMaskBehavior = this._useMaskBehavior();
return useMaskBehavior && !isSpecialChar && !isMinusKey
}
_renderInput() {
super._renderInput();
this._renderFormatter()
}
_renderFormatter() {
this._clearCache();
this._detachFormatterEvents();
if (this._useMaskBehavior()) {
this._attachFormatterEvents()
}
}
_detachFormatterEvents() {
eventsEngine.off(this._input(), ".dxNumberFormatter")
}
_isInputFromPaste(e) {
var _e$originalEvent;
return "insertFromPaste" === (null === (_e$originalEvent = e.originalEvent) || void 0 === _e$originalEvent ? void 0 : _e$originalEvent.inputType)
}
_attachFormatterEvents() {
const $input = this._input();
eventsEngine.on($input, addNamespace("input", "dxNumberFormatter"), e => {
this._formatValue(e)
});
eventsEngine.on($input, addNamespace("dxclick", "dxNumberFormatter"), () => {
if (!this._caretTimeout) {
this._caretTimeout = setTimeout(() => {
this._caretTimeout = void 0;
const caret = this._caret();
if (caret) {
this._caret(getCaretInBoundaries(caret, this._getInputVal(), this._getFormatPattern()))
}
}, 0)
}
});
eventsEngine.on($input, dxDblClickEvent, () => {
this.clearCaretTimeout()
})
}
clearCaretTimeout() {
clearTimeout(this._caretTimeout);
this._caretTimeout = void 0
}
_forceRefreshInputValue() {
if (!this._useMaskBehavior()) {
super._forceRefreshInputValue()
}
}
_isNonStubAfter(index) {
const text = this._getInputVal().slice(index);
return !!text && !this._isStub(text, true)
}
_isStub(str, allowMultipleChars) {
const escapedDecimalSeparator = escapeRegExp(number.getDecimalSeparator());
const regExpString = `^[^0-9${escapedDecimalSeparator}]+$`;
const stubRegExp = new RegExp(regExpString, "g");
return stubRegExp.test(str ?? "") && (!!allowMultipleChars || this._isChar(str))
}
_parseValue(text) {
if (!this._useMaskBehavior()) {
return super._parseValue(text)
}
return this._parsedValue
}
_getPrecisionLimits(pattern) {
const realSeparatorIndex = getRealSeparatorIndex(pattern).index;
const floatPart = (splitByIndex(pattern, realSeparatorIndex)[1] || "").replace(/[^#0]/g, "");
const minPrecision = floatPart.replace(/^(0*)#*/, "$1").length;
const maxPrecision = floatPart.length;
return {
min: minPrecision,
max: maxPrecision
}
}
_revertSign(e) {
if (!this._useMaskBehavior()) {
return
}
const caret = this._caret();
if ((null === caret || void 0 === caret ? void 0 : caret.start) !== (null === caret || void 0 === caret ? void 0 : caret.end)) {
if ("minus" === normalizeKeyName(e)) {
this._applyRevertedSign(e, caret, true);
return
}
this._caret(getCaretInBoundaries(0, this._getInputVal(), this._getFormatPattern()))
}
this._applyRevertedSign(e, caret)
}
_applyRevertedSign(e, caret, preserveSelectedText) {
const newValue = -1 * (this._parsedValue ?? 0);
if (this._isValueInRange(newValue) || 0 === newValue) {
this._parsedValue = newValue;
if (preserveSelectedText) {
const format = this._getFormatPattern();
const previousText = this._getInputVal();
this._setTextByParsedValue();
e.preventDefault();
if (caret) {
const currentText = this._getInputVal();
const offset = getCaretOffset(previousText, currentText, format);
const caretWithOffset = getCaretWithOffset(caret, offset);
const caretInBoundaries = getCaretInBoundaries(caretWithOffset, currentText, format);
this._caret(caretInBoundaries)
}
}
}
}
_removeMinusFromText(text, caret) {
const caretStart = (null === caret || void 0 === caret ? void 0 : caret.start) ?? 0;
const isMinusPressed = "minus" === this._lastKeyName && "-" === text.charAt(caretStart - 1);
return isMinusPressed ? this._replaceSelectedText(text, {
start: caretStart - 1,
end: caretStart
}, "") : text
}
_setTextByParsedValue() {
const format = this._getFormatPattern();
const parsed = this._parseValue();
const formatted = this._format(parsed, format) || "";
this._setInputText(formatted)
}
_formatValue(e) {
let normalizedText = this._getInputVal();
const caret = this._caret();
const textWithoutMinus = this._removeMinusFromText(normalizedText, caret);
const wasMinusRemoved = textWithoutMinus !== normalizedText;
const isFromPaste = this._isInputFromPaste(e);
normalizedText = textWithoutMinus;
if (!isFromPaste && this._isValueIncomplete(textWithoutMinus)) {
this._formattedValue = normalizedText;
if (wasMinusRemoved) {
this._setTextByParsedValue()
}
return
}
const formattedValue = number.convertDigits(this._formattedValue, true);
const textWasChanged = formattedValue !== normalizedText;
if (textWasChanged) {
const value = this._tryParse(normalizedText, caret, "");
if (isDefined(value)) {
this._parsedValue = value
}
}
this._setTextByParsedValue()
}
_renderDisplayText(text) {
if (this._useMaskBehavior()) {
this._toggleEmptinessEventHandler()
} else {
super._renderDisplayText(text)
}
}
_renderValue() {
if (this._useMaskBehavior()) {
const {
value: value
} = this.option();
this._parsedValue = value;
this._setTextByParsedValue()
}
return super._renderValue()
}
_updateParsedValue() {
const inputValue = this._getInputVal();
this._parsedValue = this._tryParse(inputValue, this._caret())
}
_adjustParsedValue() {
if (!this._useMaskBehavior()) {
return
}
const clearedText = this._removeStubs(this._getInputVal());
const parsedValue = clearedText ? this._parseValue() : null;
if (!isNumeric(parsedValue)) {
this._parsedValue = parsedValue;
return
}
const {
min: min,
max: max
} = this.option();
this._parsedValue = fitIntoRange(parsedValue, min, max)
}
_valueChangeEventHandler(e) {
if (!this._useMaskBehavior()) {
super._valueChangeEventHandler(e);
return
}
const caret = this._caret();
this._saveValueChangeEvent(e);
this._lastKey = null;
this._lastKeyName = null;
this._updateParsedValue();
this._adjustParsedValue();
this.option("value", this._parsedValue);
if (caret) {
this._caret(caret)
}
}
_optionChanged(args) {
switch (args.name) {
case "format":
case "useMaskBehavior":
this._renderInputType();
this._updateFormat();
this._renderFormatter();
this._renderValue();
this._refreshValueChangeEvent();
this._refreshEvents();
break;
case "min":
case "max":
this._adjustParsedValue();
super._optionChanged(args);
break;
default:
super._optionChanged(args)
}
}
_clearCache() {
delete this._formattedValue;
delete this._lastKey;
delete this._lastKeyName;
delete this._parsedValue;
delete this._focusOutOccurs;
clearTimeout(this._caretTimeout);
delete this._caretTimeout
}
_clean() {
this._clearCache();
super._clean()
}
}
export default NumberBoxMask;