UNPKG

primevue

Version:

PrimeVue is a premium UI library for Vue featuring a rich set of 90+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBlock, wh

1,216 lines (1,209 loc) 52.8 kB
import AngleDown from '@primeicons/vue/angle-down'; import AngleUp from '@primeicons/vue/angle-up'; import Times from '@primeicons/vue/times'; import { cn } from '@primeuix/utils'; import { clearSelection, getSelection } from '@primeuix/utils/dom'; import { isEmpty, isNotEmpty } from '@primeuix/utils/object'; import InputText from 'primevue/inputtext'; import BaseInput from '@primevue/core/baseinput'; import InputNumberStyle from 'primevue/inputnumber/style'; import { resolveComponent, openBlock, createElementBlock, mergeProps, createVNode, normalizeStyle, normalizeClass, renderSlot, createCommentVNode, createElementVNode, toHandlers, createBlock, resolveDynamicComponent } from 'vue'; var script$1 = { name: 'BaseInputNumber', "extends": BaseInput, props: { format: { type: Boolean, "default": true }, showButtons: { type: Boolean, "default": false }, buttonLayout: { type: String, "default": 'stacked' }, incrementButtonClass: { type: String, "default": null }, decrementButtonClass: { type: String, "default": null }, incrementIcon: { type: String, "default": undefined }, decrementIcon: { type: String, "default": undefined }, locale: { type: String, "default": undefined }, localeMatcher: { type: String, "default": undefined }, mode: { type: String, "default": 'decimal' }, prefix: { type: String, "default": null }, suffix: { type: String, "default": null }, currency: { type: String, "default": undefined }, currencyDisplay: { type: String, "default": undefined }, useGrouping: { type: Boolean, "default": true }, minFractionDigits: { type: Number, "default": undefined }, maxFractionDigits: { type: Number, "default": undefined }, roundingMode: { type: String, "default": 'halfExpand', validator: function validator(value) { return ['ceil', 'floor', 'expand', 'trunc', 'halfCeil', 'halfFloor', 'halfExpand', 'halfTrunc', 'halfEven'].includes(value); } }, min: { type: Number, "default": null }, max: { type: Number, "default": null }, step: { type: Number, "default": 1 }, allowEmpty: { type: Boolean, "default": true }, highlightOnFocus: { type: Boolean, "default": false }, showClear: { type: Boolean, "default": false }, readonly: { type: Boolean, "default": false }, placeholder: { type: String, "default": null }, inputId: { type: String, "default": null }, inputClass: { type: [String, Object], "default": null }, inputStyle: { type: Object, "default": null }, ariaLabelledby: { type: String, "default": null }, ariaLabel: { type: String, "default": null }, required: { type: Boolean, "default": false } }, style: InputNumberStyle, provide: function provide() { return { $pcInputNumber: this, $parentInstance: this }; } }; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: true } : { done: false, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = true, u = false; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = true, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); } function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } var script = { name: 'InputNumber', "extends": script$1, inheritAttrs: false, emits: ['input', 'focus', 'blur'], inject: { $pcFluid: { "default": null } }, numberFormat: null, _numeral: null, _decimal: null, _group: null, _minusSign: null, _currency: null, _suffix: null, _prefix: null, _index: null, groupChar: '', isSpecialChar: null, compositionValue: null, compositionStart: null, compositionEnd: null, prefixChar: null, suffixChar: null, timer: null, data: function data() { return { focused: false }; }, watch: { d_value: { immediate: true, handler: function handler(newValue) { var _this$$refs$clearIcon; if ((_this$$refs$clearIcon = this.$refs.clearIcon) !== null && _this$$refs$clearIcon !== void 0 && (_this$$refs$clearIcon = _this$$refs$clearIcon.$el) !== null && _this$$refs$clearIcon !== void 0 && _this$$refs$clearIcon.style) { this.$refs.clearIcon.$el.style.display = isEmpty(newValue) ? 'none' : 'block'; } } }, locale: function locale(newValue, oldValue) { this.updateConstructParser(newValue, oldValue); }, localeMatcher: function localeMatcher(newValue, oldValue) { this.updateConstructParser(newValue, oldValue); }, mode: function mode(newValue, oldValue) { this.updateConstructParser(newValue, oldValue); }, currency: function currency(newValue, oldValue) { this.updateConstructParser(newValue, oldValue); }, currencyDisplay: function currencyDisplay(newValue, oldValue) { this.updateConstructParser(newValue, oldValue); }, useGrouping: function useGrouping(newValue, oldValue) { this.updateConstructParser(newValue, oldValue); }, minFractionDigits: function minFractionDigits(newValue, oldValue) { this.updateConstructParser(newValue, oldValue); }, maxFractionDigits: function maxFractionDigits(newValue, oldValue) { this.updateConstructParser(newValue, oldValue); }, suffix: function suffix(newValue, oldValue) { this.updateConstructParser(newValue, oldValue); }, prefix: function prefix(newValue, oldValue) { this.updateConstructParser(newValue, oldValue); } }, created: function created() { this.constructParser(); }, mounted: function mounted() { var _this$$refs$clearIcon2; if ((_this$$refs$clearIcon2 = this.$refs.clearIcon) !== null && _this$$refs$clearIcon2 !== void 0 && (_this$$refs$clearIcon2 = _this$$refs$clearIcon2.$el) !== null && _this$$refs$clearIcon2 !== void 0 && _this$$refs$clearIcon2.style) { this.$refs.clearIcon.$el.style.display = !this.$filled ? 'none' : 'block'; } }, methods: { getOptions: function getOptions() { return { localeMatcher: this.localeMatcher, style: this.mode, currency: this.currency, currencyDisplay: this.currencyDisplay, useGrouping: this.useGrouping, minimumFractionDigits: this.minFractionDigits, maximumFractionDigits: this.maxFractionDigits, roundingMode: this.roundingMode }; }, constructParser: function constructParser() { this.numberFormat = new Intl.NumberFormat(this.locale, this.getOptions()); var numerals = _toConsumableArray(new Intl.NumberFormat(this.locale, { useGrouping: false }).format(9876543210)).reverse(); var index = new Map(numerals.map(function (d, i) { return [d, i]; })); this._numeral = new RegExp("[".concat(numerals.join(''), "]"), 'g'); this._group = this.getGroupingExpression(); this._minusSign = this.getMinusSignExpression(); this._currency = this.getCurrencyExpression(); this._decimal = this.getDecimalExpression(); this._suffix = this.getSuffixExpression(); this._prefix = this.getPrefixExpression(); this._index = function (d) { return index.get(d); }; }, updateConstructParser: function updateConstructParser(newValue, oldValue) { if (newValue !== oldValue) { this.constructParser(); } }, escapeRegExp: function escapeRegExp(text) { return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); }, getDecimalExpression: function getDecimalExpression() { var formatter = new Intl.NumberFormat(this.locale, _objectSpread(_objectSpread({}, this.getOptions()), {}, { useGrouping: false })); var formatted = formatter.format(1.1); if (formatted === formatter.format(1)) { return new RegExp("[]", 'g'); } return new RegExp("[".concat(formatted.replace(this._currency, '').trim().replace(this._numeral, ''), "]"), 'g'); }, getGroupingExpression: function getGroupingExpression() { var formatter = new Intl.NumberFormat(this.locale, { useGrouping: true }); this.groupChar = formatter.format(1000000).trim().replace(this._numeral, '').charAt(0); return new RegExp("[".concat(this.groupChar, "]"), 'g'); }, getMinusSignExpression: function getMinusSignExpression() { var formatter = new Intl.NumberFormat(this.locale, { useGrouping: false }); return new RegExp("[".concat(formatter.format(-1).trim().replace(this._numeral, ''), "]"), 'g'); }, getCurrencyExpression: function getCurrencyExpression() { if (this.currency) { var formatter = new Intl.NumberFormat(this.locale, { style: 'currency', currency: this.currency, currencyDisplay: this.currencyDisplay, minimumFractionDigits: 0, maximumFractionDigits: 0, roundingMode: this.roundingMode }); return new RegExp("[".concat(formatter.format(1).replace(/\s/g, '').replace(this._numeral, '').replace(this._group, ''), "]"), 'g'); } return new RegExp("[]", 'g'); }, getPrefixExpression: function getPrefixExpression() { if (this.prefix) { this.prefixChar = this.prefix; } else { var formatter = new Intl.NumberFormat(this.locale, { style: this.mode, currency: this.currency, currencyDisplay: this.currencyDisplay }); this.prefixChar = formatter.format(1).split('1')[0]; } return new RegExp("".concat(this.escapeRegExp(this.prefixChar || '')), 'g'); }, getSuffixExpression: function getSuffixExpression() { if (this.suffix) { this.suffixChar = this.suffix; } else { var formatter = new Intl.NumberFormat(this.locale, { style: this.mode, currency: this.currency, currencyDisplay: this.currencyDisplay, minimumFractionDigits: 0, maximumFractionDigits: 0, roundingMode: this.roundingMode }); this.suffixChar = formatter.format(1).split('1')[1]; } return new RegExp("".concat(this.escapeRegExp(this.suffixChar || '')), 'g'); }, formatValue: function formatValue(value) { if (value != null) { if (value === '-') { // Minus sign return value; } if (this.format) { var formatter = new Intl.NumberFormat(this.locale, this.getOptions()); var formattedValue = formatter.format(value); if (this.prefix) { if (value < 0) { var minusSign = new Intl.NumberFormat(this.locale, { useGrouping: false }).format(-1).trim().replace(this._numeral, '') || '-'; formattedValue = formattedValue.replace(this._minusSign, ''); this.resetRegex(); formattedValue = minusSign + this.prefix + formattedValue; } else { formattedValue = this.prefix + formattedValue; } } if (this.suffix) { formattedValue = formattedValue + this.suffix; } return formattedValue; } return value.toString(); } return ''; }, parseValue: function parseValue(text) { var filteredText = text.replace(this._suffix, '').replace(this._prefix, '').trim().replace(/\s/g, '').replace(this._currency, '').replace(this._group, '').replace(this._minusSign, '-').replace(this._decimal, '.').replace(this._numeral, this._index); if (filteredText) { if (filteredText === '-') // Minus sign return filteredText; var parsedValue = +filteredText; return isNaN(parsedValue) ? null : parsedValue; } return null; }, repeat: function repeat(event, interval, dir) { var _this = this; if (this.readonly) { return; } var i = interval || 500; this.clearTimer(); this.timer = setTimeout(function () { _this.repeat(event, 40, dir); }, i); this.spin(event, dir); }, addWithPrecision: function addWithPrecision(base, increment) { var baseStr = base.toString(); var stepStr = increment.toString(); var baseDecimalPlaces = baseStr.includes('.') ? baseStr.split('.')[1].length : 0; var stepDecimalPlaces = stepStr.includes('.') ? stepStr.split('.')[1].length : 0; var maxDecimalPlaces = Math.max(baseDecimalPlaces, stepDecimalPlaces); var precision = Math.pow(10, maxDecimalPlaces); return Math.round((base + increment) * precision) / precision; }, spin: function spin(event, dir) { if (this.$refs.input) { var step = this.step * dir; var currentValue = this.parseValue(this.$refs.input.$el.value) || 0; var newValue = this.validateValue(this.addWithPrecision(currentValue, step)); this.updateInput(newValue, null, 'spin'); this.updateModel(event, newValue); this.handleOnInput(event, currentValue, newValue); } }, onUpButtonMouseDown: function onUpButtonMouseDown(event) { if (!this.disabled) { this.$refs.input.$el.focus(); this.repeat(event, null, 1); event.preventDefault(); } }, onUpButtonMouseUp: function onUpButtonMouseUp() { if (!this.disabled) { this.clearTimer(); } }, onUpButtonMouseLeave: function onUpButtonMouseLeave() { if (!this.disabled) { this.clearTimer(); } }, onUpButtonKeyUp: function onUpButtonKeyUp() { if (!this.disabled) { this.clearTimer(); } }, onUpButtonKeyDown: function onUpButtonKeyDown(event) { if (event.code === 'Space' || event.code === 'Enter' || event.code === 'NumpadEnter') { this.repeat(event, null, 1); } }, onDownButtonMouseDown: function onDownButtonMouseDown(event) { if (!this.disabled) { this.$refs.input.$el.focus(); this.repeat(event, null, -1); event.preventDefault(); } }, onDownButtonMouseUp: function onDownButtonMouseUp() { if (!this.disabled) { this.clearTimer(); } }, onDownButtonMouseLeave: function onDownButtonMouseLeave() { if (!this.disabled) { this.clearTimer(); } }, onDownButtonKeyUp: function onDownButtonKeyUp() { if (!this.disabled) { this.clearTimer(); } }, onDownButtonKeyDown: function onDownButtonKeyDown(event) { if (event.code === 'Space' || event.code === 'Enter' || event.code === 'NumpadEnter') { this.repeat(event, null, -1); } }, onUserInput: function onUserInput() { if (this.isSpecialChar) { this.$refs.input.$el.value = this.lastValue; } this.isSpecialChar = false; }, onInputCompositionStart: function onInputCompositionStart(event) { // Snapshot the value and caret before IME composition begins so any // characters the IME commits can be filtered on composition end. this.compositionValue = event.target.value; this.compositionStart = event.target.selectionStart; this.compositionEnd = event.target.selectionEnd; }, onInputCompositionEnd: function onInputCompositionEnd(event) { var _this$compositionValu; if (this.readonly || this.disabled) { return; } // IME-composed text bypasses the keypress/keydown filtering. Restore the // value captured before composition and re-insert only the valid numeric // characters (digits and the locale decimal, group and minus signs), // ignoring letters and other symbols. var data = event.data || ''; event.target.value = (_this$compositionValu = this.compositionValue) !== null && _this$compositionValu !== void 0 ? _this$compositionValu : ''; event.target.setSelectionRange(this.compositionStart, this.compositionEnd); var _iterator = _createForOfIteratorHelper(data), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var _char = _step.value; if (this.isNumeralChar(_char)) { this.insert(event, _char, { isDecimalSign: this.isDecimalSign(_char), isMinusSign: this.isMinusSign(_char) }); } } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } }, onInputKeyDown: function onInputKeyDown(event) { if (this.readonly) { return; } // block composition input if (event.isComposing) { return; } if (event.altKey || event.ctrlKey || event.metaKey) { this.isSpecialChar = true; this.lastValue = this.$refs.input.$el.value; return; } this.lastValue = event.target.value; var selectionStart = event.target.selectionStart; var selectionEnd = event.target.selectionEnd; var selectionRange = selectionEnd - selectionStart; var inputValue = event.target.value; var newValueStr = null; var code = event.code || event.key; switch (code) { case 'ArrowUp': this.spin(event, 1); event.preventDefault(); break; case 'ArrowDown': this.spin(event, -1); event.preventDefault(); break; case 'ArrowLeft': if (selectionRange > 1) { var cursorPosition = this.isNumeralChar(inputValue.charAt(selectionStart)) ? selectionStart + 1 : selectionStart + 2; this.$refs.input.$el.setSelectionRange(cursorPosition, cursorPosition); } else if (!this.isNumeralChar(inputValue.charAt(selectionStart - 1))) { event.preventDefault(); } break; case 'ArrowRight': if (selectionRange > 1) { var _cursorPosition = selectionEnd - 1; this.$refs.input.$el.setSelectionRange(_cursorPosition, _cursorPosition); } else if (!this.isNumeralChar(inputValue.charAt(selectionStart))) { event.preventDefault(); } break; case 'Tab': case 'Enter': case 'NumpadEnter': newValueStr = this.validateValue(this.parseValue(inputValue)); this.$refs.input.$el.value = this.formatValue(newValueStr); this.$refs.input.$el.setAttribute('aria-valuenow', newValueStr); this.updateModel(event, newValueStr); break; case 'Backspace': { event.preventDefault(); if (selectionStart === selectionEnd) { if (selectionStart >= inputValue.length && this.suffixChar !== null) { selectionStart = inputValue.length - this.suffixChar.length; this.$refs.input.$el.setSelectionRange(selectionStart, selectionStart); } var deleteChar = inputValue.charAt(selectionStart - 1); var _this$getDecimalCharI = this.getDecimalCharIndexes(inputValue), decimalCharIndex = _this$getDecimalCharI.decimalCharIndex, decimalCharIndexWithoutPrefix = _this$getDecimalCharI.decimalCharIndexWithoutPrefix; if (this.isNumeralChar(deleteChar)) { var decimalLength = this.getDecimalLength(inputValue); if (this._group.test(deleteChar)) { this._group.lastIndex = 0; newValueStr = inputValue.slice(0, selectionStart - 2) + inputValue.slice(selectionStart - 1); } else if (this._decimal.test(deleteChar)) { this._decimal.lastIndex = 0; if (decimalLength) { this.$refs.input.$el.setSelectionRange(selectionStart - 1, selectionStart - 1); } else { newValueStr = inputValue.slice(0, selectionStart - 1) + inputValue.slice(selectionStart); } } else if (decimalCharIndex > 0 && selectionStart > decimalCharIndex) { var insertedText = this.isDecimalMode() && (this.minFractionDigits || 0) < decimalLength ? '' : '0'; newValueStr = inputValue.slice(0, selectionStart - 1) + insertedText + inputValue.slice(selectionStart); } else if (decimalCharIndexWithoutPrefix === 1) { newValueStr = inputValue.slice(0, selectionStart - 1) + '0' + inputValue.slice(selectionStart); newValueStr = this.parseValue(newValueStr) > 0 ? newValueStr : ''; } else { newValueStr = inputValue.slice(0, selectionStart - 1) + inputValue.slice(selectionStart); } } this.updateValue(event, newValueStr, null, 'delete-single'); } else { newValueStr = this.deleteRange(inputValue, selectionStart, selectionEnd); this.updateValue(event, newValueStr, null, 'delete-range'); } break; } case 'Delete': event.preventDefault(); if (selectionStart === selectionEnd) { var _deleteChar = inputValue.charAt(selectionStart); var _this$getDecimalCharI2 = this.getDecimalCharIndexes(inputValue), _decimalCharIndex = _this$getDecimalCharI2.decimalCharIndex, _decimalCharIndexWithoutPrefix = _this$getDecimalCharI2.decimalCharIndexWithoutPrefix; if (this.isNumeralChar(_deleteChar)) { var _decimalLength = this.getDecimalLength(inputValue); if (this._group.test(_deleteChar)) { this._group.lastIndex = 0; newValueStr = inputValue.slice(0, selectionStart) + inputValue.slice(selectionStart + 2); } else if (this._decimal.test(_deleteChar)) { this._decimal.lastIndex = 0; if (_decimalLength) { this.$refs.input.$el.setSelectionRange(selectionStart + 1, selectionStart + 1); } else { newValueStr = inputValue.slice(0, selectionStart) + inputValue.slice(selectionStart + 1); } } else if (_decimalCharIndex > 0 && selectionStart > _decimalCharIndex) { var _insertedText = this.isDecimalMode() && (this.minFractionDigits || 0) < _decimalLength ? '' : '0'; newValueStr = inputValue.slice(0, selectionStart) + _insertedText + inputValue.slice(selectionStart + 1); } else if (_decimalCharIndexWithoutPrefix === 1) { newValueStr = inputValue.slice(0, selectionStart) + '0' + inputValue.slice(selectionStart + 1); newValueStr = this.parseValue(newValueStr) > 0 ? newValueStr : ''; } else { newValueStr = inputValue.slice(0, selectionStart) + inputValue.slice(selectionStart + 1); } } this.updateValue(event, newValueStr, null, 'delete-back-single'); } else { newValueStr = this.deleteRange(inputValue, selectionStart, selectionEnd); this.updateValue(event, newValueStr, null, 'delete-range'); } break; case 'Home': event.preventDefault(); if (isNotEmpty(this.min)) { this.updateModel(event, this.min); } break; case 'End': event.preventDefault(); if (isNotEmpty(this.max)) { this.updateModel(event, this.max); } break; } }, onInputKeyPress: function onInputKeyPress(event) { if (this.readonly) { return; } var _char2 = event.key; var isDecimalSign = this.isDecimalSign(_char2); var isMinusSign = this.isMinusSign(_char2); if (event.code !== 'Enter') { event.preventDefault(); } if (Number(_char2) >= 0 && Number(_char2) <= 9 || isMinusSign || isDecimalSign) { this.insert(event, _char2, { isDecimalSign: isDecimalSign, isMinusSign: isMinusSign }); } }, onPaste: function onPaste(event) { if (this.readonly || this.disabled) { return; } event.preventDefault(); var data = (event.clipboardData || window['clipboardData']).getData('Text'); if (this.inputId === 'integeronly' && /[^\d-]/.test(data)) { return; } if (data) { var filteredData = this.parseValue(data); if (filteredData != null) { this.insert(event, filteredData.toString()); } } }, onClearClick: function onClearClick(event) { this.updateModel(event, null); this.$refs.input.$el.focus(); }, allowMinusSign: function allowMinusSign() { return this.min === null || this.min < 0; }, isMinusSign: function isMinusSign(_char3) { if (this._minusSign.test(_char3) || _char3 === '-') { this._minusSign.lastIndex = 0; return true; } return false; }, isDecimalSign: function isDecimalSign(_char4) { var _this$locale; if ((_this$locale = this.locale) !== null && _this$locale !== void 0 && _this$locale.includes('fr') && ['.', ','].includes(_char4) || this._decimal.test(_char4)) { this._decimal.lastIndex = 0; return true; } return false; }, isDecimalMode: function isDecimalMode() { return this.mode === 'decimal'; }, getDecimalCharIndexes: function getDecimalCharIndexes(val) { var decimalCharIndex = val.search(this._decimal); this._decimal.lastIndex = 0; var filteredVal = val.replace(this._prefix, '').trim().replace(/\s/g, '').replace(this._currency, ''); var decimalCharIndexWithoutPrefix = filteredVal.search(this._decimal); this._decimal.lastIndex = 0; return { decimalCharIndex: decimalCharIndex, decimalCharIndexWithoutPrefix: decimalCharIndexWithoutPrefix }; }, getCharIndexes: function getCharIndexes(val) { var decimalCharIndex = val.search(this._decimal); this._decimal.lastIndex = 0; var minusCharIndex = val.search(this._minusSign); this._minusSign.lastIndex = 0; var suffixCharIndex = val.search(this._suffix); this._suffix.lastIndex = 0; var currencyCharIndex = val.search(this._currency); this._currency.lastIndex = 0; return { decimalCharIndex: decimalCharIndex, minusCharIndex: minusCharIndex, suffixCharIndex: suffixCharIndex, currencyCharIndex: currencyCharIndex }; }, insert: function insert(event, text) { var sign = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : { isDecimalSign: false, isMinusSign: false }; var minusCharIndexOnText = text.search(this._minusSign); this._minusSign.lastIndex = 0; if (!this.allowMinusSign() && minusCharIndexOnText !== -1) { return; } var selectionStart = this.$refs.input.$el.selectionStart; var selectionEnd = this.$refs.input.$el.selectionEnd; var inputValue = this.$refs.input.$el.value.trim(); var _this$getCharIndexes = this.getCharIndexes(inputValue), decimalCharIndex = _this$getCharIndexes.decimalCharIndex, minusCharIndex = _this$getCharIndexes.minusCharIndex, suffixCharIndex = _this$getCharIndexes.suffixCharIndex, currencyCharIndex = _this$getCharIndexes.currencyCharIndex; var newValueStr; if (sign.isMinusSign) { var isNewMinusSign = minusCharIndex === -1; var prefixBoundary = (this.prefixChar || '').length; var isAtPrefixBoundary = prefixBoundary > 0 && selectionStart === prefixBoundary; if (selectionStart === 0 || selectionStart === currencyCharIndex + 1 || isAtPrefixBoundary) { newValueStr = inputValue; if (isNewMinusSign || selectionEnd !== 0) { newValueStr = this.insertText(inputValue, text, 0, selectionEnd); } this.updateValue(event, newValueStr, text, 'insert'); } } else if (sign.isDecimalSign) { if (decimalCharIndex > 0 && selectionStart === decimalCharIndex) { this.updateValue(event, inputValue, text, 'insert'); } else if (decimalCharIndex > selectionStart && decimalCharIndex < selectionEnd) { newValueStr = this.insertText(inputValue, text, selectionStart, selectionEnd); this.updateValue(event, newValueStr, text, 'insert'); } else if (decimalCharIndex === -1 && this.maxFractionDigits) { newValueStr = this.insertText(inputValue, text, selectionStart, selectionEnd); this.updateValue(event, newValueStr, text, 'insert'); } } else { var maxFractionDigits = this.numberFormat.resolvedOptions().maximumFractionDigits; var operation = selectionStart !== selectionEnd ? 'range-insert' : 'insert'; if (decimalCharIndex > 0 && selectionStart > decimalCharIndex) { if (selectionStart + text.length - (decimalCharIndex + 1) <= maxFractionDigits) { var charIndex = currencyCharIndex >= selectionStart ? currencyCharIndex - 1 : suffixCharIndex >= selectionStart ? suffixCharIndex : inputValue.length; newValueStr = inputValue.slice(0, selectionStart) + text + inputValue.slice(selectionStart + text.length, charIndex) + inputValue.slice(charIndex); this.updateValue(event, newValueStr, text, operation); } } else { newValueStr = this.insertText(inputValue, text, selectionStart, selectionEnd); this.updateValue(event, newValueStr, text, operation); } } }, insertText: function insertText(value, text, start, end) { var textSplit = text === '.' ? text : text.split('.'); if (textSplit.length === 2) { var decimalCharIndex = value.slice(start, end).search(this._decimal); this._decimal.lastIndex = 0; return decimalCharIndex > 0 ? value.slice(0, start) + this.formatValue(text) + value.slice(end) : this.formatValue(text) || value; } else if (end - start === value.length) { return this.formatValue(text); } else if (start === 0) { return text + value.slice(end); } else if (end === value.length) { return value.slice(0, start) + text; } else { return value.slice(0, start) + text + value.slice(end); } }, deleteRange: function deleteRange(value, start, end) { var newValueStr; if (end - start === value.length) newValueStr = '';else if (start === 0) newValueStr = value.slice(end);else if (end === value.length) newValueStr = value.slice(0, start);else newValueStr = value.slice(0, start) + value.slice(end); return newValueStr; }, initCursor: function initCursor() { var selectionStart = this.$refs.input.$el.selectionStart; var inputValue = this.$refs.input.$el.value; var valueLength = inputValue.length; var index = null; // remove prefix var prefixLength = (this.prefixChar || '').length; inputValue = inputValue.replace(this._prefix, ''); selectionStart = selectionStart - prefixLength; var _char5 = inputValue.charAt(selectionStart); if (this.isNumeralChar(_char5)) { return selectionStart + prefixLength; } //left var i = selectionStart - 1; while (i >= 0) { _char5 = inputValue.charAt(i); if (this.isNumeralChar(_char5)) { index = i + prefixLength; break; } else { i--; } } if (index !== null) { this.$refs.input.$el.setSelectionRange(index + 1, index + 1); } else { i = selectionStart; while (i < valueLength) { _char5 = inputValue.charAt(i); if (this.isNumeralChar(_char5)) { index = i + prefixLength; break; } else { i++; } } if (index !== null) { this.$refs.input.$el.setSelectionRange(index, index); } } return index || 0; }, onInputClick: function onInputClick() { var currentValue = this.$refs.input.$el.value; if (!this.readonly && currentValue !== getSelection()) { this.initCursor(); } }, isNumeralChar: function isNumeralChar(_char6) { if (_char6.length === 1 && (this._numeral.test(_char6) || this._decimal.test(_char6) || this._group.test(_char6) || this._minusSign.test(_char6))) { this.resetRegex(); return true; } return false; }, resetRegex: function resetRegex() { this._numeral.lastIndex = 0; this._decimal.lastIndex = 0; this._group.lastIndex = 0; this._minusSign.lastIndex = 0; }, updateValue: function updateValue(event, valueStr, insertedValueStr, operation) { var currentValue = this.$refs.input.$el.value; var newValue = null; if (valueStr != null) { newValue = this.parseValue(valueStr); newValue = !newValue && !this.allowEmpty ? 0 : newValue; this.updateInput(newValue, insertedValueStr, operation, valueStr); this.handleOnInput(event, currentValue, newValue); } }, handleOnInput: function handleOnInput(event, currentValue, newValue) { if (this.isValueChanged(currentValue, newValue)) { var _this$formField$onInp, _this$formField; this.$emit('input', { originalEvent: event, value: newValue, formattedValue: currentValue }); (_this$formField$onInp = (_this$formField = this.formField).onInput) === null || _this$formField$onInp === void 0 || _this$formField$onInp.call(_this$formField, { originalEvent: event, value: newValue }); } }, isValueChanged: function isValueChanged(currentValue, newValue) { if (newValue === null && currentValue !== null) { return true; } if (newValue != null) { var parsedCurrentValue = typeof currentValue === 'string' ? this.parseValue(currentValue) : currentValue; return newValue !== parsedCurrentValue; } return false; }, validateValue: function validateValue(value) { if (value === '-' || value == null) { return null; } if (this.min != null && value < this.min) { return this.min; } if (this.max != null && value > this.max) { return this.max; } return value; }, updateInput: function updateInput(value, insertedValueStr, operation, valueStr) { var _this$$refs$clearIcon3; insertedValueStr = insertedValueStr || ''; var inputValue = this.$refs.input.$el.value; var newValue = this.formatValue(value); var currentLength = inputValue.length; if (newValue !== valueStr) { newValue = this.concatValues(newValue, valueStr); } if (currentLength === 0) { this.$refs.input.$el.value = newValue; this.$refs.input.$el.setSelectionRange(0, 0); var index = this.initCursor(); var selectionEnd = index + insertedValueStr.length; this.$refs.input.$el.setSelectionRange(selectionEnd, selectionEnd); } else { var selectionStart = this.$refs.input.$el.selectionStart; var _selectionEnd = this.$refs.input.$el.selectionEnd; this.$refs.input.$el.value = newValue; var newLength = newValue.length; if (operation === 'range-insert') { var startValue = this.parseValue((inputValue || '').slice(0, selectionStart)); var startValueStr = startValue !== null ? startValue.toString() : ''; var startExpr = startValueStr.split('').join("(".concat(this.groupChar, ")?")); var sRegex = new RegExp(startExpr, 'g'); sRegex.test(newValue); var tExpr = insertedValueStr.split('').join("(".concat(this.groupChar, ")?")); var tRegex = new RegExp(tExpr, 'g'); tRegex.test(newValue.slice(sRegex.lastIndex)); _selectionEnd = sRegex.lastIndex + tRegex.lastIndex; this.$refs.input.$el.setSelectionRange(_selectionEnd, _selectionEnd); } else if (newLength === currentLength) { if (operation === 'insert' || operation === 'delete-back-single') { this.$refs.input.$el.setSelectionRange(_selectionEnd + 1, _selectionEnd + 1); } else if (operation === 'delete-single') { this.$refs.input.$el.setSelectionRange(_selectionEnd - 1, _selectionEnd - 1); } else if (operation === 'delete-range' || operation === 'spin') { this.$refs.input.$el.setSelectionRange(_selectionEnd, _selectionEnd); } } else if (operation === 'delete-back-single') { var prevChar = inputValue.charAt(_selectionEnd - 1); var nextChar = inputValue.charAt(_selectionEnd); var diff = currentLength - newLength; var isGroupChar = this._group.test(nextChar); if (isGroupChar && diff === 1) { _selectionEnd += 1; } else if (!isGroupChar && this.isNumeralChar(prevChar)) { _selectionEnd += -1 * diff + 1; } this._group.lastIndex = 0; this.$refs.input.$el.setSelectionRange(_selectionEnd, _selectionEnd); } else if (inputValue === '-' && operation === 'insert') { this.$refs.input.$el.setSelectionRange(0, 0); var _index = this.initCursor(); var _selectionEnd2 = _index + insertedValueStr.length + 1; this.$refs.input.$el.setSelectionRange(_selectionEnd2, _selectionEnd2); } else { _selectionEnd = _selectionEnd + (newLength - currentLength); this.$refs.input.$el.setSelectionRange(_selectionEnd, _selectionEnd); } } this.$refs.input.$el.setAttribute('aria-valuenow', value); if ((_this$$refs$clearIcon3 = this.$refs.clearIcon) !== null && _this$$refs$clearIcon3 !== void 0 && (_this$$refs$clearIcon3 = _this$$refs$clearIcon3.$el) !== null && _this$$refs$clearIcon3 !== void 0 && _this$$refs$clearIcon3.style) { this.$refs.clearIcon.$el.style.display = isEmpty(newValue) ? 'none' : 'block'; } }, concatValues: function concatValues(val1, val2) { if (val1 && val2) { var decimalCharIndex = val2.search(this._decimal); this._decimal.lastIndex = 0; if (this.suffixChar) { return decimalCharIndex !== -1 ? val1.replace(this.suffixChar, '').split(this._decimal)[0] + val2.replace(this.suffixChar, '').slice(decimalCharIndex) + this.suffixChar : val1; } else { return decimalCharIndex !== -1 ? val1.split(this._decimal)[0] + val2.slice(decimalCharIndex) : val1; } } return val1; }, getDecimalLength: function getDecimalLength(value) { if (value) { var valueSplit = value.split(this._decimal); if (valueSplit.length === 2) { return valueSplit[1].replace(this._suffix, '').trim().replace(/\s/g, '').replace(this._currency, '').length; } } return 0; }, updateModel: function updateModel(event, value) { this.writeValue(value, event); }, onInputFocus: function onInputFocus(event) { this.focused = true; if (!this.disabled && !this.readonly && this.$refs.input.$el.value !== getSelection() && this.highlightOnFocus) { event.target.select(); } this.$emit('focus', event); }, onInputBlur: function onInputBlur(event) { var _this$formField$onBlu, _this$formField2; this.focused = false; var input = event.target; var newValue = this.validateValue(this.parseValue(input.value)); this.$emit('blur', { originalEvent: event, value: input.value }); (_this$formField$onBlu = (_this$formField2 = this.formField).onBlur) === null || _this$formField$onBlu === void 0 || _this$formField$onBlu.call(_this$formField2, event); input.value = this.formatValue(newValue); input.setAttribute('aria-valuenow', newValue); this.updateModel(event, newValue); if (!this.disabled && !this.readonly && this.highlightOnFocus) { clearSelection(); } }, clearTimer: function clearTimer() { if (this.timer) { clearTimeout(this.timer); } }, maxBoundry: function maxBoundry() { return this.d_value >= this.max; }, minBoundry: function minBoundry() { return this.d_value <= this.min; } }, computed: { upButtonListeners: function upButtonListeners() { var _this2 = this; return { mousedown: function mousedown(event) { return _this2.onUpButtonMouseDown(event); }, mouseup: function mouseup(event) { return _this2.onUpButtonMouseUp(event); }, mouseleave: function mouseleave(event) { return _this2.onUpButtonMouseLeave(event); }, keydown: function keydown(event) { return _this2.onUpButtonKeyDown(event); }, keyup: function keyup(event) { return _this2.onUpButtonKeyUp(event); } }; }, downButtonListeners: function downButtonListeners() { var _this3 = this; return { mousedown: function mousedown(event) { return _this3.onDownButtonMouseDown(event); }, mouseup: function mouseup(event) { return _this3.onDownButtonMouseUp(event); }, mouseleave: function mouseleave(event) { return _this3.onDownButtonMouseLeave(event); }, keydown: function keydown(event) { return _this3.onDownButtonKeyDown(event); }, keyup: function keyup(event) { return _this3.onDownButtonKeyUp(event); } }; }, formattedValue: function formattedValue() { var val = !this.d_value && !this.allowEmpty ? 0 : this.d_value; return this.formatValue(val); }, getFormatter: function getFormatter() { return this.numberFormat; }, dataP: function dataP() { return cn(_defineProperty(_defineProperty({ invalid: this.$invalid, fluid: this.$fluid, filled: this.$variant === 'filled' }, this.size, this.size), this.buttonLayout, this.showButtons && this.buttonLayout)); } }, components: { InputText: InputText, AngleUp: AngleUp, AngleDown: AngleDown, Times: Times } }; var _hoisted_1 = ["data-p"]; var _hoisted_2 = ["data-p"]; var _hoisted_3 = ["disabled", "data-p"]; var _hoisted_4 = ["disabled", "data-p"]; var _hoisted_5 = ["disabled", "data-p"]; var _hoisted_6 = ["disabled", "data-p"]; function render(_ctx, _cache, $props, $setup, $data, $options) { var _component_InputText = resolveComponent("InputText"); var _component_Times = resolveComponent("Times"); return openBlock(), createElementBlock("span", mergeProps({ "class": _ctx.cx('root') }, _ctx.ptmi('root'), { "data-p": $options.dataP }), [createVNode(_component_InputText, { ref: "input", id: _ctx.inputId, name: _ctx.$formName, formControl: { novalidate: true }, role: "spinbutton", "class": normalizeClass([_ctx.cx('pcInputText'), _ctx.inputClass]), style: normalizeStyle(_ctx.inputStyle), defaultValue: $options.formattedValue, "aria-valuemin": _ctx.min, "aria-valuemax": _ctx.max, "aria-valuenow": _ctx.d_value, inputmode: _ctx.mode === 'decimal' && !_ctx.minFractionDigits ? 'numeric' : 'decimal', disabled: _ctx.disabled, readonly: _ctx.readonly, placeholder: _ctx.placeholder, "aria-labelledby": _ctx.ariaLabelledby, "aria-label": _ctx.ariaLabel, required: _ctx.required, size: _ctx.size, invalid: _ctx.$invalid, variant: _ctx.variant, onInput: $options.onUserInput, onKeydown: $options.onInputKeyDown, onKeypress: $options.onInputKeyPress, onCompositionstart: $options.onInputCompositionStart, onCompositionend: $options.onInputCompositionEnd, onPaste: $options.onPaste, onClick: $options.onInputClick, onFocus: $options.onInputFocus, onBlur: $options.onInputBlur, pt: _ctx.ptm('pcInputText'), unstyled: _ctx.unstyled, "data-p": $options.dataP }, null, 8, ["id", "name", "class", "style", "defaultValue", "aria-valuemin", "aria-valuemax", "aria-valuenow", "inputmode", "disabled", "readonly", "placeholder", "aria-labelledby", "aria-label", "required", "size", "invalid", "variant", "onInput", "onKeydown", "onKeypress", "onCompositionstart", "onCompositionend", "onPaste", "onClick", "onFocus", "onBlur", "pt", "unstyled", "data-p"]), _ctx.showClear && _ctx.buttonLayout !== 'vertical' ? renderSlot(_ctx.$slots, "clearicon", { key: 0, "class": normalizeClass(_ctx.cx('clearIcon')), clearCallback: $options.onClearClick }, function () { return [createVNode(_component_Times, mergeProps({ ref: "clearIcon", "class": [_ctx.cx('clearIcon')], onClick: $options.onClearClick }, _ctx.ptm('clearIcon')), null, 16, ["class", "onClick"])]; }) : createCommentVNode("", true), _ctx.showButtons && _ctx.buttonLayout === 'stacked' ? (openBlock(), createElementBlock("span", mergeProps({ key: 1, "class": _ctx.cx('buttonGroup') }, _ctx.ptm('buttonGroup'), { "data-p": $options.dataP }), [renderSlot(_ctx.$slots, "incrementbutton", { listeners: $options.upButtonListeners }, function () { return [createElementVNode("button", mergeProps({ "class": [_ctx.cx('incrementButton'), _ctx.incrementButtonClass] }, toHandlers($options.upButtonListeners, true), { disabled: _ctx.disabled, tabindex: -1, "aria-hidden": "true", type: "button" }, _ctx.ptm('incrementButton'), { "data-p": $options.dataP }), [renderSlot(_ctx.$slots, "incrementicon", {}, function () { return [(openBlock(), createBlock(resolveDynamicComponent(_ctx.incrementIcon ? 'span' : 'AngleUp'), mergeProps({ "class": _ctx.incrementIcon }, _ctx.ptm('incrementIcon'), { "data-pc-section": "incrementicon" }), null, 16, ["class"]))]; })], 16, _hoisted_3)]; }), renderSlot(_ctx.$slots, "decremen