@tagplus/components 4.8.3 → 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.3",
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="handleInputMoney"
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
  }
@@ -5,7 +5,7 @@
5
5
  :value="formattedValue"
6
6
  v-bind="$attrs"
7
7
  :maxlength="maxlength"
8
- @input="inputPercent"
8
+ @input="input"
9
9
  @change="handleChange"
10
10
  @focus="$event.target.select()"
11
11
  >
@@ -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,87 +38,16 @@ export default {
39
38
  },
40
39
 
41
40
  methods: {
42
- inputPercent (evt) {
41
+ input (evt) {
43
42
  this.formattedValue = formatMoney(evt, true, this.locale, this.customPrecision)
44
43
  const moneyFormatado = formatMoney(evt, false, this.locale, this.customPrecision)
45
44
 
46
45
  this.$emit('input', moneyFormatado)
47
46
  },
48
47
 
49
- /**
50
- * Converte o valor de entrada para float.
51
- * @param {string} value - O valor de entrada.
52
- * @returns {number} O valor float convertido.
53
- */
54
- parseValue (value) {
55
- if (!value) return 0
56
- const parts = value.split(',')
57
- if (parts.length > 1) {
58
- const precision = this.customPrecision !== false ? this.customPrecision : 2
59
- parts[1] = parts[1].slice(0, precision)
60
- }
61
- return parseFloat(parts.join('.')) || 0
62
- },
63
-
64
- /**
65
- * Manipula o valor de entrada sanitizando-o, limitando a precisão decimal e emitindo o número analisado.
66
- *
67
- * Esta função executa os seguintes passos:
68
- * 1. Remove todos os caracteres do valor de entrada que não são dígitos ou a primeira vírgula.
69
- * 2. Garante que há no máximo uma vírgula no valor sanitizado.
70
- * 3. Divide o valor sanitizado em partes inteiras e fracionárias com base na vírgula.
71
- * 4. Limita a parte fracionária a uma precisão especificada (o padrão é 2 se `customPrecision` não estiver definido).
72
- * 5. Junta as partes inteiras e fracionárias novamente e atualiza `rawValue`.
73
- * 6. Converte o `rawValue` para um número float e o emite usando o evento `input`.
74
- *
75
- * @param {string} value - O valor de entrada a ser manipulado.
76
- * @emits input - Emite o valor numérico analisado.
77
- */
78
- handleInputMoney (value) {
79
- // remove todos os caracteres que não são números ou a primeira vírgula
80
- const sanitized = value.replace(/[^\d,]/g, '')
81
- const commaCount = (sanitized.match(/,/g) || []).length
82
-
83
- if (commaCount > 1) return
84
-
85
- const parts = sanitized.split(',')
86
- if (parts.length > 1) {
87
- const precision = this.customPrecision !== false ? this.customPrecision : 2
88
- parts[1] = parts[1].slice(0, precision)
89
- this.rawValue = parts.join(',')
90
- } else {
91
- this.rawValue = sanitized
92
- }
93
-
94
- const numberValue = this.parseValue(this.rawValue)
95
- this.$emit('input', numberValue)
96
- },
97
-
98
- /**
99
- * Ao focar o input, o valor existente é selecionado e
100
- * caso o usuário comece a digitar, o valor é substituído.
101
- * @param {Event} event - O evento de foco.
102
- */
103
- handleFocus (event) {
104
- this.isTyping = true
105
- this.rawValue = this.formattedValue
106
- event.target.select()
107
- },
108
-
109
- /**
110
- * Função responsável por formatar o valor de acordo com a locale
111
- * e emitir o valor convertido, após o usuário sair do input.
112
- */
113
- handleBlur () {
114
- this.isTyping = false
115
- const value = this.parseValue(this.rawValue)
116
- this.formattedValue = formatMoney(value, true, this.locale, this.customPrecision)
117
- this.$emit('input', value)
118
- },
119
-
120
48
  handleChange (evt) {
121
- const value = this.parseValue(evt)
122
- this.$emit('change', value)
49
+ this.$emit('change', formatMoney(evt, false, this.locale, this.customPrecision))
123
50
  }
124
51
  }
52
+
125
53
  }