@tagplus/components 4.7.12 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/dist/tp.common.js +2 -1
  2. package/dist/tp.common.js.LICENSE.txt +9 -0
  3. package/dist/tp.common.js.map +1 -1
  4. package/dist/tp.common.lang-en-js.js +2 -0
  5. package/dist/tp.common.lang-en-js.js.map +1 -0
  6. package/dist/tp.css +11 -167
  7. package/dist/tp.umd.js +2 -1
  8. package/dist/tp.umd.js.LICENSE.txt +9 -0
  9. package/dist/tp.umd.js.map +1 -1
  10. package/dist/tp.umd.lang-en-js.js +2 -0
  11. package/dist/tp.umd.lang-en-js.js.map +1 -0
  12. package/dist/tp.umd.min.js +2 -1
  13. package/dist/tp.umd.min.js.LICENSE.txt +9 -0
  14. package/dist/tp.umd.min.js.map +1 -1
  15. package/dist/tp.umd.min.lang-en-js.js +2 -0
  16. package/dist/tp.umd.min.lang-en-js.js.map +1 -0
  17. package/package.json +51 -50
  18. package/src/assets/scss/_fonts.scss +24 -23
  19. package/src/assets/scss/_helpers.scss +4 -0
  20. package/src/assets/scss/_mixins.scss +2 -2
  21. package/src/assets/scss/_overrides.scss +5 -52
  22. package/src/assets/scss/_resass.scss +21 -12
  23. package/src/assets/scss/_variables.scss +0 -1
  24. package/src/assets/scss/index.scss +1 -4
  25. package/src/components/Autosuggest/Autosuggest.vue +340 -767
  26. package/src/components/Autosuggest/Multisuggest.vue +22 -0
  27. package/src/components/Autosuggest/autosuggest-props.js +210 -0
  28. package/src/components/Autosuggest/autosuggest-style.scss +127 -0
  29. package/src/components/Autosuggest/core.js +63 -0
  30. package/src/components/Autosuggest/index.js +2 -0
  31. package/src/components/Autosuggest/multisuggest-props.js +9 -0
  32. package/src/components/Autosuggest/option.vue +136 -0
  33. package/src/components/Autosuggest/select-dropdown.vue +64 -0
  34. package/src/components/Autosuggest/useOption.js +120 -0
  35. package/src/components/Autosuggest/useSelect.js +1133 -0
  36. package/src/components/AutosuggestTest.vue +56 -0
  37. package/src/components/CardExemplo.vue +49 -0
  38. package/src/components/CodeSample.vue +78 -0
  39. package/src/components/Inline/Inline.vue +24 -32
  40. package/src/components/InputNumber/InputNumber.vue +329 -378
  41. package/src/components/InputNumber/input-number.js +135 -0
  42. package/src/components/Loader/Loader.vue +42 -53
  43. package/src/components/Loader/animations.scss +13 -0
  44. package/src/components/Money/Money.vue +11 -20
  45. package/src/components/Multisuggest/index.js +2 -3
  46. package/src/components/MultisuggestTest.vue +56 -0
  47. package/src/components/OptionsList/OptionsList.vue +7 -6
  48. package/src/components/OptionsListItem/OptionsListItem.vue +46 -42
  49. package/src/components/Percent/Percent.vue +8 -14
  50. package/src/components/Skeleton/Skeleton.vue +16 -11
  51. package/src/components/Step/Step.vue +42 -35
  52. package/src/components/Steps/Steps.vue +4 -7
  53. package/src/components/TesteToCurrency.vue +171 -0
  54. package/src/components/Tip/Tip.vue +45 -30
  55. package/src/components/ValueSelector.vue +60 -0
  56. package/src/components/autosuggestMixin.js +301 -0
  57. package/src/components/index.js +4 -1
  58. package/src/locale/i18n.js +114 -0
  59. package/src/locale/lang/en.js +3 -2
  60. package/src/locale/lang/pt-br.js +3 -2
  61. package/src/main.js +9 -14
  62. package/src/mixins/floatFormatter.js +12 -16
  63. package/src/plugins/currency.js +100 -0
  64. package/src/utils/browser.js +6 -0
  65. package/src/utils/constants.js +3 -0
  66. package/src/utils/error.js +22 -0
  67. package/src/utils/filters.js +1 -14
  68. package/src/utils/helpers.js +41 -0
  69. package/src/utils/i18n.js +2 -0
  70. package/src/utils/icon.js +35 -0
  71. package/src/utils/index.js +20 -0
  72. package/src/utils/objects.js +17 -0
  73. package/src/utils/runtime.js +86 -0
  74. package/src/utils/scroll.js +100 -0
  75. package/src/utils/strings.js +17 -0
  76. package/src/utils/style.js +80 -0
  77. package/src/utils/types.js +39 -0
  78. package/src/utils/use-derived-namespace.js +112 -0
  79. package/src/utils/use-form-common-props.js +41 -0
  80. package/src/utils/use-form-item.js +80 -0
  81. package/src/utils/use-id.js +40 -0
  82. package/src/utils/use-input.js +33 -0
  83. package/src/components/Dialog/Dialog.vue +0 -253
  84. package/src/components/Dialog/index.js +0 -3
  85. package/src/components/Multisuggest/Multisuggest.vue +0 -858
  86. package/src/locale/index.js +0 -78
  87. package/src/mixins/locale.js +0 -9
  88. package/src/utils/currency.js +0 -180
@@ -1,46 +1,60 @@
1
1
  <template>
2
2
  <div
3
3
  :class="[
4
- 'el-input-number',
5
- inputNumberSize ? 'el-input-number--' + inputNumberSize : '',
6
- { 'is-disabled': inputNumberDisabled },
7
- { 'is-without-controls': !controls },
8
- { 'is-controls-right': controlsAtRight }
4
+ ns.b(),
5
+ ns.m(inputNumberSize),
6
+ ns.is('disabled', inputNumberDisabled),
7
+ ns.is('without-controls', !controls),
8
+ ns.is('controls-right', controlsAtRight),
9
9
  ]"
10
10
  @dragstart.prevent
11
11
  >
12
12
  <span
13
13
  v-if="controls"
14
14
  v-repeat-click="decrease"
15
- class="el-input-number__decrease"
16
15
  role="button"
17
- :class="{'is-disabled': minDisabled}"
16
+ :aria-label="t('el.inputNumber.decrease')"
17
+ :class="[ns.e('decrease'), ns.is('disabled', minDisabled)]"
18
18
  @keydown.enter="decrease"
19
19
  >
20
- <em :class="`el-icon-${controlsAtRight ? 'arrow-down' : 'minus'}`" />
20
+ <el-icon>
21
+ <arrow-down v-if="controlsAtRight" />
22
+ <minus v-else />
23
+ </el-icon>
21
24
  </span>
22
25
  <span
23
26
  v-if="controls"
24
27
  v-repeat-click="increase"
25
- class="el-input-number__increase"
26
28
  role="button"
27
- :class="{'is-disabled': maxDisabled}"
29
+ :aria-label="t('el.inputNumber.increase')"
30
+ :class="[ns.e('increase'), ns.is('disabled', maxDisabled)]"
28
31
  @keydown.enter="increase"
29
32
  >
30
- <em :class="`el-icon-${controlsAtRight ? 'arrow-up' : 'plus'}`" />
33
+ <el-icon>
34
+ <arrow-up v-if="controlsAtRight" />
35
+ <plus v-else />
36
+ </el-icon>
31
37
  </span>
32
38
  <el-input
39
+ :id="id"
33
40
  ref="input"
34
- :value="displayValue"
41
+ :key="key"
42
+ :step="step"
43
+ :model-value="displayValue"
44
+ :formatter="displayFormatter"
45
+ :parser="inputParser"
35
46
  :placeholder="placeholder"
47
+ :readonly="readonly"
36
48
  :disabled="inputNumberDisabled"
37
49
  :size="inputNumberSize"
38
50
  :max="max"
39
51
  :min="min"
40
52
  :name="name"
41
53
  :label="label"
42
- @keydown.up.native.prevent="increase"
43
- @keydown.down.native.prevent="decrease"
54
+ :validate-event="false"
55
+ @wheel.prevent
56
+ @keydown.up.prevent="increase"
57
+ @keydown.down.prevent="decrease"
44
58
  @blur="handleBlur"
45
59
  @focus="handleFocus"
46
60
  @input="handleInput"
@@ -48,383 +62,320 @@
48
62
  />
49
63
  </div>
50
64
  </template>
51
-
52
- <script>
53
- import ElInput from 'element-ui/packages/input'
54
- import Focus from 'element-ui/src/mixins/focus'
55
- import RepeatClick from 'element-ui/src/directives/repeat-click'
56
-
57
- export default {
65
+ <script setup>
66
+ import { computed, onMounted, onUpdated, reactive, ref, watch, getCurrentInstance } from 'vue'
67
+ import { isNil } from 'lodash-unified'
68
+ import {
69
+ useFormDisabled,
70
+ useFormItem,
71
+ useFormSize,
72
+ debugWarn,
73
+ isNumber,
74
+ isString,
75
+ isUndefined,
76
+ throwError,
77
+ } from '@/utils'
78
+ import { vRepeatClick } from 'element-plus'
79
+ import { useLocale, useNamespace } from 'element-plus/es/hooks/index'
80
+ import { ArrowDown, ArrowUp, Minus, Plus } from '@element-plus/icons-vue'
81
+ import { inputNumberEmits, inputNumberProps } from '@/components/InputNumber/input-number'
82
+ const props = defineProps(inputNumberProps)
83
+ const emit = defineEmits(inputNumberEmits)
84
+ const UPDATE_MODEL_EVENT = 'update:modelValue'
85
+ const CHANGE_EVENT = 'change'
86
+ const INPUT_EVENT = 'input'
87
+
88
+ defineOptions({
58
89
  name: 'TpInputNumber',
59
-
60
- directives: {
61
- repeatClick: RepeatClick
62
- },
63
-
64
- components: {
65
- ElInput
66
- },
67
-
68
- mixins: [Focus('input')],
69
- inject: {
70
- elForm: {
71
- default: ''
72
- },
73
- elFormItem: {
74
- default: ''
90
+ })
91
+
92
+ const { t } = useLocale()
93
+ const ns = useNamespace('input-number')
94
+ const input = ref()
95
+ const vm = getCurrentInstance().proxy
96
+ const key = ref(1)
97
+
98
+ // eslint-disable-next-line vue/no-setup-props-destructure
99
+ const data = reactive({
100
+ currentValue: props.modelValue,
101
+ userInput: null,
102
+ })
103
+
104
+ const { formItem } = useFormItem()
105
+
106
+ const minDisabled = computed(
107
+ () => isNumber(props.modelValue) && props.modelValue <= props.min
108
+ )
109
+ const maxDisabled = computed(
110
+ () => isNumber(props.modelValue) && props.modelValue >= props.max
111
+ )
112
+
113
+ const numPrecision = computed(() => {
114
+ const stepPrecision = getPrecision(props.step)
115
+ if (!isUndefined(props.precision)) {
116
+ if (stepPrecision > props.precision) {
117
+ debugWarn(
118
+ 'InputNumber',
119
+ 'precision should not be less than the decimal places of step'
120
+ )
75
121
  }
76
- },
122
+ return props.precision
123
+ } else {
124
+ return Math.max(getPrecision(props.modelValue), stepPrecision)
125
+ }
126
+ })
127
+ const controlsAtRight = computed(() => {
128
+ return props.controls && props.controlsPosition === 'right'
129
+ })
130
+
131
+ const inputNumberSize = useFormSize()
132
+ const inputNumberDisabled = useFormDisabled()
133
+
134
+ /**
135
+ * @tagplus
136
+ * Modificado para permitir um valor padrão vazio ou 0 de acordo com a prop
137
+ */
138
+ const displayValue = computed(() => {
139
+ if (data.userInput !== null) {
140
+ return data.userInput
141
+ }
142
+ let currentValue = data.currentValue
77
143
 
78
- props: {
79
- step: {
80
- type: Number,
81
- default: 1
82
- },
83
- stepStrictly: {
84
- type: Boolean,
85
- default: false
86
- },
87
- max: {
88
- type: Number,
89
- default: Infinity
90
- },
91
- min: {
92
- type: Number,
93
- default: -Infinity
94
- },
95
- value: {
96
- type: [Number, String],
97
- default: null
98
- },
99
- disabled: Boolean,
100
- size: {
101
- type: [String, Boolean],
102
- default: false
103
- },
104
- controls: {
105
- type: Boolean,
106
- default: true
107
- },
108
- controlsPosition: {
109
- type: String,
110
- default: ''
111
- },
112
- name: {
113
- type: [String, Boolean],
114
- default: false
115
- },
116
- label: {
117
- type: [String],
118
- default: ''
119
- },
120
- placeholder: {
121
- type: [String, Boolean],
122
- default: false
123
- },
124
- precision: {
125
- type: Number,
126
- default: 2,
127
- validator (val) {
128
- return val >= 0 && val === parseInt(val, 10)
129
- }
130
- },
131
- // Customizada
132
- usarVirgula: {
133
- type: Boolean,
134
- default: true
135
- },
136
- // Customizada - Se false permite campo vazio
137
- stringDefaultsZero: {
138
- type: Boolean,
139
- default: true
140
- }
141
- },
144
+ const fallbackValue = props.stringDefaultsZero ? 0 : ''
145
+ if (props.modelValue === '' || isNil(currentValue) || currentValue === ''){
146
+ return fallbackValue
147
+ }
142
148
 
143
- data () {
144
- return {
145
- currentValue: '',
146
- userInput: null
149
+ if (isNumber(currentValue)) {
150
+ if (Number.isNaN(currentValue)) return fallbackValue
151
+ if (!isUndefined(props.precision)) {
152
+ currentValue = currentValue.toFixed(props.precision)
147
153
  }
148
- },
149
-
150
- computed: {
151
- /**
152
- * Sobrescrito do element
153
- */
154
- minDisabled () {
155
- return this.value < this.min
156
- },
157
-
158
- /**
159
- * Sobrescrito do element
160
- */
161
- maxDisabled () {
162
- return this.value > this.max
163
- },
164
- numPrecision () {
165
- const { value, step, getPrecision, precision } = this
166
- const stepPrecision = getPrecision(step)
167
-
168
- if (precision !== undefined) {
169
- if (stepPrecision > precision) {
170
- console.warn('[Element Warn][InputNumber]precision should not be less than the decimal places of step')
171
- }
172
-
173
- return precision
174
- }
175
-
176
- return Math.max(getPrecision(value), stepPrecision)
177
- },
178
- controlsAtRight () {
179
- return this.controls && this.controlsPosition === 'right'
180
- },
181
- _elFormItemSize () {
182
- return (this.elFormItem || {}).elFormItemSize
183
- },
184
- inputNumberSize () {
185
- return this.size || this._elFormItemSize || (this.$ELEMENT || {}).size
186
- },
187
- inputNumberDisabled () {
188
- return this.disabled || Boolean((this.elForm || {}).disabled)
189
- },
190
- /**
191
- * Sobrescrito do element
192
- */
193
- displayValue () {
194
- if (this.userInput !== null) {
195
- // corrige o bug para deixar limpar o campo
196
- if (!this.stringDefaultsZero && this.userInput === '') {
197
- this.currentValue = ''
198
- }
199
-
200
- return this.userInput
201
- }
202
-
203
- let currentValue
204
-
205
- if (this.value === '' && !this.stringDefaultsZero) {
206
- currentValue = ''
207
- } else {
208
- currentValue = this.currentValue
209
- }
210
-
211
- if (typeof currentValue === 'number') {
212
- if (this.stepStrictly) {
213
- const stepPrecision = this.getPrecision(this.step)
214
- const precisionFactor = Math.pow(10, stepPrecision)
215
-
216
- currentValue =
217
- (Math.round(currentValue / this.step) *
218
- precisionFactor *
219
- this.step) /
220
- precisionFactor
221
- }
222
-
223
- if (this.precision !== undefined) {
224
- currentValue = currentValue.toFixed(this.precision)
225
- }
226
- }
227
-
228
- if (this.usarVirgula) {
229
- currentValue = (`${currentValue }`).replace('.', ',')
230
- }
231
-
232
- return currentValue
154
+ }
155
+ return currentValue
156
+ })
157
+
158
+ /**
159
+ * @tagplus
160
+ * Criado para simular o comportamento do type=number porque ele não deixa
161
+ * exibir os valores formatados no padrão pt-br 100.555,55
162
+ */
163
+ const displayFormatter = computed(() => {
164
+ const decimalChar = vm.$t('locale.number.decimal')
165
+ const thousandsChar = vm.$t('locale.number.thousands')
166
+ return (value) => {
167
+ // Essa linha simula o comportamento do type="number" para não deixar digitar letras
168
+ const noLetters = value.replaceAll(/[a-zA-Z]/g, '')
169
+ const res = noLetters.replace('.', decimalChar).replace(/\B(?=(\d{3})+(?!\d))/g, thousandsChar)
170
+ return res
171
+ }
172
+ })
173
+
174
+ /**
175
+ * @tagplus
176
+ * Criado em conjunto do displayFormatter para simular o type="number"
177
+ * @see displayFormatter
178
+ */
179
+ const inputParser = computed(() => {
180
+ const decimalChar = vm.$t('locale.number.decimal')
181
+ const thousandsChar = vm.$t('locale.number.thousands')
182
+ return (value) => {
183
+ const regexThou = `/\$\s?|(${thousandsChar}*)/g`
184
+ const res = value.replace(regexThou, '').replace(decimalChar, '.')
185
+ return res
186
+ }
187
+ })
188
+
189
+ const toPrecision = (num, pre) => {
190
+ // eslint-disable-next-line no-param-reassign
191
+ if (isUndefined(pre)) pre = numPrecision.value
192
+ if (pre === 0) return Math.round(num)
193
+ let snum = String(num)
194
+ const pointPos = snum.indexOf('.')
195
+ if (pointPos === -1) return num
196
+ const nums = snum.replace('.', '').split('')
197
+ const datum = nums[pointPos + pre]
198
+ if (!datum) return num
199
+ const length = snum.length
200
+ if (snum.charAt(length - 1) === '5') {
201
+ snum = `${snum.slice(0, Math.max(0, length - 1))}6`
202
+ }
203
+ return Number.parseFloat(Number(snum).toFixed(pre))
204
+ }
205
+ const getPrecision = (value) => {
206
+ if (isNil(value)) return 0
207
+ const valueString = value.toString()
208
+ const dotPosition = valueString.indexOf('.')
209
+ let precision = 0
210
+ if (dotPosition !== -1) {
211
+ precision = valueString.length - dotPosition - 1
212
+ }
213
+ return precision
214
+ }
215
+ const ensurePrecision = (val, coefficient = 1) => {
216
+ if (!isNumber(val)) return data.currentValue
217
+ // Solve the accuracy problem of JS decimal calculation by converting the value to integer.
218
+ return toPrecision(val + props.step * coefficient)
219
+ }
220
+ const increase = () => {
221
+ if (props.readonly || inputNumberDisabled.value || maxDisabled.value) return
222
+ const value = Number(displayValue.value) || 0
223
+ const newVal = ensurePrecision(value)
224
+ setCurrentValue(newVal)
225
+ emit(INPUT_EVENT, data.currentValue)
226
+ setCurrentValueToModelValue()
227
+ }
228
+ const decrease = () => {
229
+ if (props.readonly || inputNumberDisabled.value || minDisabled.value) return
230
+ const value = Number(displayValue.value) || 0
231
+ const newVal = ensurePrecision(value, -1)
232
+ setCurrentValue(newVal)
233
+ emit(INPUT_EVENT, data.currentValue)
234
+ setCurrentValueToModelValue()
235
+ }
236
+ const verifyValue = (value, update) => {
237
+ const { max, min, step, precision, stepStrictly, valueOnClear } = props
238
+ if (max < min) {
239
+ throwError('InputNumber', 'min should not be greater than max.')
240
+ }
241
+ let newVal = Number(value)
242
+ if (isNil(value) || Number.isNaN(newVal)) {
243
+ return null
244
+ }
245
+ if (value === '') {
246
+ if (valueOnClear === null) {
247
+ return null
233
248
  }
234
- },
235
-
236
- watch: {
237
- /**
238
- * Sobrescrito do element
239
- */
240
- value: {
241
- immediate: true,
242
- handler (value) {
243
- let newVal
244
-
245
- if (value === undefined) {
246
- newVal = value
247
- } else if (!this.stringDefaultsZero && value === '') {
248
- newVal = ''
249
- } else {
250
- newVal = Number(value)
251
- }
252
-
253
- if (newVal !== undefined) {
254
- if (isNaN(newVal)) {
255
- return
256
- }
257
-
258
- if (this.stepStrictly) {
259
- const stepPrecision = this.getPrecision(this.step)
260
- const precisionFactor = Math.pow(10, stepPrecision)
249
+ newVal = isString(valueOnClear) ? { min, max }[valueOnClear] : valueOnClear
250
+ }
251
+ if (stepStrictly) {
252
+ newVal = toPrecision(Math.round(newVal / step) * step, precision)
253
+ }
254
+ if (!isUndefined(precision)) {
255
+ newVal = toPrecision(newVal, precision)
256
+ }
257
+ if (newVal > max || newVal < min) {
258
+ newVal = newVal > max ? max : min
259
+ update && emit(UPDATE_MODEL_EVENT, newVal)
260
+ }
261
+ return newVal
262
+ }
263
+ const setCurrentValue = (value, emitChange = true) => {
264
+ const oldVal = data.currentValue
265
+ const newVal = verifyValue(value)
266
+ if (!emitChange) {
267
+ emit(UPDATE_MODEL_EVENT, newVal)
268
+ return
269
+ }
270
+ if (oldVal === newVal) return
271
+ data.userInput = null
272
+ emit(UPDATE_MODEL_EVENT, newVal)
273
+ emit(CHANGE_EVENT, newVal, oldVal)
274
+ if (props.validateEvent) {
275
+ formItem?.validate?.('change').catch((err) => debugWarn(err))
276
+ }
277
+ data.currentValue = newVal
278
+ }
279
+ const handleInput = (value) => {
280
+ data.userInput = value
281
+ const newVal = value === '' ? null : Number(value)
282
+ emit(INPUT_EVENT, newVal)
283
+ setCurrentValue(newVal, false)
284
+ }
285
+ const handleInputChange = (value) => {
286
+ const newVal = value !== '' ? Number(value) : ''
287
+ if ((isNumber(newVal) && !Number.isNaN(newVal)) || value === '') {
288
+ setCurrentValue(newVal)
289
+ }
290
+ setCurrentValueToModelValue()
291
+ data.userInput = null
292
+ }
261
293
 
262
- newVal = Math.round(newVal / this.step) * precisionFactor * this.step / precisionFactor
263
- }
294
+ const focus = () => {
295
+ input.value?.focus?.()
296
+ }
264
297
 
265
- if (this.precision !== undefined) {
266
- newVal = this.toPrecision(newVal, this.precision)
267
- }
268
- }
298
+ const blur = () => {
299
+ input.value?.blur?.()
300
+ }
269
301
 
270
- if (newVal >= this.max) newVal = this.max
302
+ const handleFocus = (event) => {
303
+ emit('focus', event)
304
+ }
271
305
 
272
- if (newVal <= this.min) newVal = this.min
306
+ const handleBlur = (event) => {
307
+ data.userInput = null
308
+ emit('blur', event)
309
+ if (props.validateEvent) {
310
+ formItem?.validate?.('blur').catch((err) => debugWarn(err))
311
+ }
312
+ }
273
313
 
274
- this.currentValue = newVal
275
- this.userInput = null
276
- this.$emit('input', newVal)
277
- }
314
+ const setCurrentValueToModelValue = () => {
315
+ if (data.currentValue !== props.modelValue) {
316
+ data.currentValue = props.modelValue
317
+ }
318
+ }
319
+ watch(
320
+ () => props.modelValue,
321
+ (value, oldValue) => {
322
+ const newValue = verifyValue(value, true)
323
+ if (data.userInput === null && newValue !== oldValue) {
324
+ data.currentValue = newValue
278
325
  }
279
326
  },
280
-
281
- mounted () {
282
- const innerInput = this.$refs.input.$refs.input
283
-
284
- innerInput.setAttribute('role', 'spinbutton')
285
- innerInput.setAttribute('aria-valuemax', this.max)
286
- innerInput.setAttribute('aria-valuemin', this.min)
287
- innerInput.setAttribute('aria-valuenow', this.currentValue)
288
- innerInput.setAttribute('aria-disabled', this.inputNumberDisabled)
289
- },
290
-
291
- updated () {
292
- if (!this.$refs || !this.$refs.input) return
293
-
294
- const innerInput = this.$refs.input.$refs.input
295
-
296
- innerInput.setAttribute('aria-valuenow', this.currentValue)
297
- },
298
-
299
- methods: {
300
- toPrecision (num, precision) {
301
- if (precision === undefined) precision = this.numPrecision
302
-
303
- return parseFloat(Math.round(num * Math.pow(10, precision)) / Math.pow(10, precision))
304
- },
305
- getPrecision (value) {
306
- if (value === undefined) return 0
307
-
308
- const valueString = value.toString()
309
- const dotPosition = valueString.indexOf('.')
310
- let precision = 0
311
-
312
- if (dotPosition !== -1) {
313
- precision = valueString.length - dotPosition - 1
314
- }
315
-
316
- return precision
317
- },
318
- _increase (val, step) {
319
- if (typeof val !== 'number' && val !== undefined) return this.currentValue
320
-
321
- const precisionFactor = Math.pow(10, this.numPrecision)
322
-
323
- // Solve the accuracy problem of JS decimal calculation by converting the value to integer.
324
- return this.toPrecision((precisionFactor * val + precisionFactor * step) / precisionFactor)
325
- },
326
- _decrease (val, step) {
327
- if (typeof val !== 'number' && val !== undefined) return this.currentValue
328
-
329
- const precisionFactor = Math.pow(10, this.numPrecision)
330
-
331
- return this.toPrecision((precisionFactor * val - precisionFactor * step) / precisionFactor)
332
- },
333
- increase () {
334
- if (this.inputNumberDisabled || this.maxDisabled) return
335
-
336
- const value = this.value || 0
337
- const newVal = this._increase(value, this.step)
338
-
339
- this.setCurrentValue(newVal)
340
- },
341
- decrease () {
342
- if (this.inputNumberDisabled || this.minDisabled) return
343
-
344
- const value = this.value || 0
345
- const newVal = this._decrease(value, this.step)
346
-
347
- this.setCurrentValue(newVal)
348
- },
349
- handleBlur (event) {
350
- if (!this.value && this.stringDefaultsZero && !this.precision) {
351
- this.currentValue = 0
352
- }
353
-
354
- this.$emit('blur', event)
355
- },
356
- handleFocus (event) {
357
- if (!this.value && !this.precision) {
358
- this.currentValue = ''
359
- }
360
-
361
- this.$emit('focus', event)
362
- },
363
-
364
- /**
365
- * Sobrescrito do element
366
- */
367
- handleInput (value) {
368
- this.userInput = value
369
- let newVal
370
-
371
- if (value === '' && this.stringDefaultsZero) {
372
- newVal = Number(value.replace(',', '.'))
373
- } else {
374
- newVal = value
375
- }
376
-
377
- this.$emit('change', newVal)
378
- },
379
-
380
- /**
381
- * Sobrescrito do element
382
- */
383
- handleInputChange (value) {
384
- let newVal
385
-
386
- if (value === '') {
387
- // Por padrão converte '' para 0
388
- if (this.stringDefaultsZero) {
389
- newVal = 0
390
- } else {
391
- newVal = ''
392
- }
393
- } else {
394
- newVal = Number(value.replace(',', '.'))
395
- }
396
-
397
- if (!isNaN(newVal) || value === '') {
398
- this.setCurrentValue(newVal)
399
- }
400
-
401
- this.userInput = null
402
- },
403
-
404
- /**
405
- * Sobrescrito do element
406
- */
407
- setCurrentValue (newVal) {
408
- const oldVal = this.currentValue
409
-
410
- if (typeof newVal === 'number' && this.precision !== undefined) {
411
- newVal = this.toPrecision(newVal, this.precision)
412
- }
413
-
414
- if (newVal >= this.max) newVal = this.max
415
-
416
- if (newVal <= this.min) newVal = this.min
417
-
418
- if (oldVal === newVal && newVal === this.value) return
419
-
420
- this.userInput = null
421
- this.$emit('input', newVal)
422
- this.$emit('change', newVal, oldVal)
423
- },
424
-
425
- select () {
426
- this.$refs.input.select()
327
+ { immediate: true }
328
+ )
329
+
330
+ /**
331
+ * @tagplus
332
+ * Criado para observar se a lang mudou para reformatar o displayValue
333
+ */
334
+ watch(
335
+ () => vm.$i18nHelper.hooks.onLanguageChanged,
336
+ (value, oldValue) => {
337
+ key.value++
338
+ }
339
+ )
340
+
341
+ onMounted(() => {
342
+ const { min, max, modelValue } = props
343
+ const innerInput = input.value?.input
344
+ innerInput.setAttribute('role', 'spinbutton')
345
+ if (Number.isFinite(max)) {
346
+ innerInput.setAttribute('aria-valuemax', String(max))
347
+ } else {
348
+ innerInput.removeAttribute('aria-valuemax')
349
+ }
350
+ if (Number.isFinite(min)) {
351
+ innerInput.setAttribute('aria-valuemin', String(min))
352
+ } else {
353
+ innerInput.removeAttribute('aria-valuemin')
354
+ }
355
+ innerInput.setAttribute(
356
+ 'aria-valuenow',
357
+ data.currentValue || data.currentValue === 0
358
+ ? String(data.currentValue)
359
+ : ''
360
+ )
361
+ innerInput.setAttribute('aria-disabled', String(inputNumberDisabled.value))
362
+ // eslint-disable-next-line no-eq-null, eqeqeq
363
+ if (!isNumber(modelValue) && modelValue != null) {
364
+ let val = Number(modelValue)
365
+ if (Number.isNaN(val)) {
366
+ val = null
427
367
  }
368
+ emit(UPDATE_MODEL_EVENT, val)
428
369
  }
429
- }
370
+ })
371
+ onUpdated(() => {
372
+ const innerInput = input.value?.input
373
+ innerInput?.setAttribute('aria-valuenow', `${data.currentValue ?? ''}`)
374
+ })
375
+ defineExpose({
376
+ /** @description get focus the input component */
377
+ focus,
378
+ /** @description remove focus the input component */
379
+ blur,
380
+ })
430
381
  </script>