@tagplus/components 4.8.2 → 4.8.5

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.
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "email": "bruno@tagplus.com.br"
9
9
  }
10
10
  ],
11
- "version": "4.8.2",
11
+ "version": "4.8.5",
12
12
  "main": "./dist/tp.common.js",
13
13
  "directories": {
14
14
  "lib": "src/lib"
@@ -2,13 +2,12 @@
2
2
  <el-input
3
3
  :id="`${_id}`"
4
4
  class="tp-money"
5
- :value="isTyping ? rawValue : formattedValue"
5
+ :value="formattedValue"
6
6
  v-bind="$attrs"
7
7
  :maxlength="maxlength"
8
- @input="handleInput"
8
+ @input="input"
9
9
  @change="handleChange"
10
- @focus="handleFocus"
11
- @blur="handleBlur"
10
+ @focus="$event.target.select()"
12
11
  >
13
12
  <template
14
13
  v-if="!removePrepend"
@@ -26,14 +25,6 @@
26
25
  v-bind="scope"
27
26
  />
28
27
  </template>
29
-
30
- <template
31
- slot="append"
32
- >
33
- <slot
34
- name="append"
35
- />
36
- </template>
37
28
  </el-input>
38
29
  </template>
39
30
 
@@ -45,7 +36,6 @@ export default {
45
36
  name: 'TpMoney',
46
37
 
47
38
  mixins: [Locale, floatFormatterMixin],
48
-
49
39
  props: {
50
40
  id: {
51
41
  type: String,
@@ -729,6 +729,38 @@ export default {
729
729
  ) {
730
730
  this.checkDefaultFirstOption()
731
731
  }
732
+ },
733
+
734
+ handleOptionSelect (option, byClick) {
735
+ if (this.multiple) {
736
+ const value = (this.value || []).slice()
737
+ const optionIndex = this.getValueIndex(value, option.value)
738
+ if (optionIndex > -1) {
739
+ value.splice(optionIndex, 1)
740
+ } else if (this.multipleLimit <= 0 || value.length < this.multipleLimit) {
741
+ value.push(option.value)
742
+ }
743
+ this.$emit('input', value)
744
+ this.emitChange(value)
745
+ this.query = ''
746
+ if (option.created) {
747
+ this.handleQueryChange('')
748
+ this.inputLength = 20
749
+ }
750
+ if (this.filterable) {
751
+ this.$refs.input.focus()
752
+ }
753
+ } else {
754
+ this.$emit('input', option.value)
755
+ this.emitChange(option.value)
756
+ this.visible = false
757
+ }
758
+ this.isSilentBlur = byClick
759
+ this.setSoftFocus()
760
+ if (this.visible) return
761
+ this.$nextTick(() => {
762
+ this.scrollToOption(option)
763
+ })
732
764
  }
733
765
  }
734
766
  }
@@ -1,14 +1,12 @@
1
1
  import { formatMoney } from 'tp-ui/utils/currency'
2
2
 
3
3
  /**
4
- * Mixin para formatar valores float.
4
+ * Eventos para componentes tp-money e tp-percent mostratem o número formatado com a precisão correta e devolver float sem arredondar
5
5
  */
6
6
  export default {
7
7
  data () {
8
8
  return {
9
- formattedValue: this.value,
10
- isTyping: false,
11
- rawValue: ''
9
+ formattedValue: this.value
12
10
  }
13
11
  },
14
12
 
@@ -17,6 +15,7 @@ export default {
17
15
  type: Boolean,
18
16
  default: false
19
17
  },
18
+
20
19
  customPrecision: {
21
20
  default: false
22
21
  }
@@ -39,80 +38,16 @@ export default {
39
38
  },
40
39
 
41
40
  methods: {
42
- /**
43
- * Converte o valor de entrada para float.
44
- * @param {string} value - O valor de entrada.
45
- * @returns {number} O valor float convertido.
46
- */
47
- parseValue (value) {
48
- if (!value) return 0
49
- const parts = value.split(',')
50
- if (parts.length > 1) {
51
- const precision = this.customPrecision !== false ? this.customPrecision : 2
52
- parts[1] = parts[1].slice(0, precision)
53
- }
54
- return parseFloat(parts.join('.')) || 0
55
- },
56
-
57
- /**
58
- * Manipula o valor de entrada sanitizando-o, limitando a precisão decimal e emitindo o número analisado.
59
- *
60
- * Esta função executa os seguintes passos:
61
- * 1. Remove todos os caracteres do valor de entrada que não são dígitos ou a primeira vírgula.
62
- * 2. Garante que há no máximo uma vírgula no valor sanitizado.
63
- * 3. Divide o valor sanitizado em partes inteiras e fracionárias com base na vírgula.
64
- * 4. Limita a parte fracionária a uma precisão especificada (o padrão é 2 se `customPrecision` não estiver definido).
65
- * 5. Junta as partes inteiras e fracionárias novamente e atualiza `rawValue`.
66
- * 6. Converte o `rawValue` para um número float e o emite usando o evento `input`.
67
- *
68
- * @param {string} value - O valor de entrada a ser manipulado.
69
- * @emits input - Emite o valor numérico analisado.
70
- */
71
- handleInput (value) {
72
- // remove todos os caracteres que não são números ou a primeira vírgula
73
- const sanitized = value.replace(/[^\d,]/g, '')
74
- const commaCount = (sanitized.match(/,/g) || []).length
75
-
76
- if (commaCount > 1) return
77
-
78
- const parts = sanitized.split(',')
79
- if (parts.length > 1) {
80
- const precision = this.customPrecision !== false ? this.customPrecision : 2
81
- parts[1] = parts[1].slice(0, precision)
82
- this.rawValue = parts.join(',')
83
- } else {
84
- this.rawValue = sanitized
85
- }
86
-
87
- const numberValue = this.parseValue(this.rawValue)
88
- this.$emit('input', numberValue)
89
- },
41
+ input (evt) {
42
+ this.formattedValue = formatMoney(evt, true, this.locale, this.customPrecision)
43
+ const moneyFormatado = formatMoney(evt, false, this.locale, this.customPrecision)
90
44
 
91
- /**
92
- * Ao focar o input, o valor existente é selecionado e
93
- * caso o usuário comece a digitar, o valor é substituído.
94
- * @param {Event} event - O evento de foco.
95
- */
96
- handleFocus (event) {
97
- this.isTyping = true
98
- this.rawValue = this.formattedValue
99
- event.target.select()
100
- },
101
-
102
- /**
103
- * Função responsável por formatar o valor de acordo com a locale
104
- * e emitir o valor convertido, após o usuário sair do input.
105
- */
106
- handleBlur () {
107
- this.isTyping = false
108
- const value = this.parseValue(this.rawValue)
109
- this.formattedValue = formatMoney(value, true, this.locale, this.customPrecision)
110
- this.$emit('input', value)
45
+ this.$emit('input', moneyFormatado)
111
46
  },
112
47
 
113
48
  handleChange (evt) {
114
- const value = this.parseValue(evt)
115
- this.$emit('change', value)
49
+ this.$emit('change', formatMoney(evt, false, this.locale, this.customPrecision))
116
50
  }
117
51
  }
52
+
118
53
  }