@tagplus/components 1.2.17 → 2.0.1

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": "1.2.17",
11
+ "version": "2.0.1",
12
12
  "main": "./dist/tp.common.js",
13
13
  "directories": {
14
14
  "lib": "src/lib"
@@ -19,7 +19,10 @@
19
19
  "src"
20
20
  ],
21
21
  "engines": {
22
- "node": ">=10.0"
22
+ "node": ">=14.0"
23
+ },
24
+ "lint-staged": {
25
+ "*.{js,vue,css}": "yarn lint"
23
26
  },
24
27
  "jest": {
25
28
  "testEnvironment": "node"
@@ -40,43 +43,48 @@
40
43
  "install:clear": "yarn install:clean",
41
44
  "test": "jest",
42
45
  "test:coverage": "jest --collectCoverage",
43
- "test:unit": "vue-cli-service test:unit"
46
+ "test:unit": "vue-cli-service test:unit",
47
+ "prepare": "husky install"
44
48
  },
45
49
  "dependencies": {
46
- "axios": "^0.27.0",
47
- "core-js": "^3.21.1",
50
+ "@vue/babel-preset-app": "^5.0.8",
51
+ "axios": "^0.27.2",
52
+ "core-js": "^3.25.0",
48
53
  "element-theme-chalk": "^2.13",
49
54
  "element-ui": "2.15.8",
50
55
  "js-cookie": "^3.0.1",
51
- "vue": "^2.6.14",
56
+ "vue": "^2.7.10",
52
57
  "vue-axios": "^2.1.5",
53
- "vue-i18n": "^8.14.0"
58
+ "vue-i18n": "^8.15.3"
54
59
  },
55
60
  "devDependencies": {
56
- "@babel/core": "^7.18.5",
57
- "@babel/eslint-parser": "^7.17.0",
58
- "@vue/cli-plugin-babel": "^5.0.3",
59
- "@vue/cli-plugin-unit-jest": "^5.0.3",
60
- "@vue/cli-service": "^5.0.3",
61
+ "@babel/core": "^7.18.13",
62
+ "@babel/eslint-parser": "^7.18.9",
63
+ "@vue/cli-plugin-babel": "^5.0.8",
64
+ "@vue/cli-plugin-unit-jest": "^5.0.8",
65
+ "@vue/cli-service": "^5.0.8",
61
66
  "@vue/test-utils": "^1.0.0-beta.31",
62
67
  "@vuese/cli": "^2.10.0",
63
68
  "babel-jest": "^24.9.0",
64
- "babel-plugin-module-resolver": "^3.2.0",
69
+ "babel-plugin-module-resolver": "^4.1.0",
65
70
  "babel-plugin-require-context-hook": "^1.0.0",
66
- "eslint": "^8.9.0",
71
+ "eslint": "^8.23.0",
67
72
  "eslint-config-prettier": "^8.4.0",
68
73
  "eslint-config-standard": "^17.0.0",
69
74
  "eslint-import-resolver-babel-module": "^5.3.1",
70
75
  "eslint-plugin-import": "^2.25.2",
71
- "eslint-plugin-n": "^15.0.0",
72
- "eslint-plugin-prettier": "^4.0.0",
73
- "eslint-plugin-promise": "^6.0.0",
74
- "eslint-plugin-vue": "^9.1.1",
75
- "node-sass": "^4.14.1",
76
- "nodemon": "^2.0.2",
77
- "prettier": "^2.5.1",
78
- "sass-loader": "^7.1.0",
79
- "vue-template-compiler": "^2.6.10",
80
- "webpack": "4.46.0"
76
+ "eslint-plugin-n": "^15.2.5",
77
+ "eslint-plugin-prettier": "^4.2.1",
78
+ "eslint-plugin-promise": "^6.0.1",
79
+ "eslint-plugin-vue": "^9.4.0",
80
+ "husky": "^8.0.1",
81
+ "jest": "^27.1.0",
82
+ "lint-staged": "^13.0.2",
83
+ "node-sass": "^7.0.1",
84
+ "nodemon": "^2.0.19",
85
+ "prettier": "^2.7.1",
86
+ "sass-loader": "^13.0.2",
87
+ "vue-template-compiler": "^2.7.10",
88
+ "webpack": "^5.74.0"
81
89
  }
82
90
  }
@@ -298,6 +298,7 @@ export default {
298
298
  */
299
299
  formatedValue () {
300
300
  let newVal = ''
301
+
301
302
  if (typeof this.value === 'boolean') {
302
303
  newVal = ''
303
304
  } else if (Array.isArray(this.value)) {
@@ -323,39 +324,47 @@ export default {
323
324
  const hasExistingOption = this.options
324
325
  .filter(option => !option.created)
325
326
  .some(option => option.currentLabel === this.query)
327
+
326
328
  return this.filterable && this.allowCreate && !hasExistingOption
327
329
  },
328
330
  // Monta a lista com ou sem "Cadastrar Novo Item"
329
331
  suggestionsList () {
330
332
  if (this.loading) return []
333
+
331
334
  // transformando em Array
332
335
  const list =
333
336
  typeof this.suggestions === 'object'
334
337
  ? Object.values(this.suggestions)
335
338
  : this.suggestions
339
+
336
340
  if (this.allowCreate) {
337
341
  const createdSuggestion = { created: true }
342
+
338
343
  createdSuggestion[this.valueKey] = this.query !== '' ? this.query : null
339
344
  createdSuggestion[this.labelKey] = ''
340
345
  list.push(createdSuggestion)
341
346
  }
347
+
342
348
  return list
343
349
  },
344
350
 
345
351
  emptyText () {
346
352
  if (this.loading) {
347
353
  return this.loadingText || this.t('el.select.loading')
348
- } else {
349
- if (this.remote && this.query === '' && this.options.length === 0) {
350
- return this.noDataText || this.$tpI18n.t('autosuggests.sem_dados')
351
- }
352
- if (this.filterable && this.query && this.options.length > 0 && this.filteredOptionsCount === 0) {
353
- return this.noMatchText || this.t('el.select.noMatch')
354
- }
355
- if (this.options.length === 0) {
356
- return this.noDataText || this.$tpI18n.t('autosuggests.sem_dados')
357
- }
358
354
  }
355
+
356
+ if (this.remote && this.query === '' && this.options.length === 0) {
357
+ return this.noDataText || this.$tpI18n.t('autosuggests.sem_dados')
358
+ }
359
+
360
+ if (this.filterable && this.query && this.options.length > 0 && this.filteredOptionsCount === 0) {
361
+ return this.noMatchText || this.t('el.select.noMatch')
362
+ }
363
+
364
+ if (this.options.length === 0) {
365
+ return this.noDataText || this.$tpI18n.t('autosuggests.sem_dados')
366
+ }
367
+
359
368
  return null
360
369
  }
361
370
  },
@@ -372,6 +381,7 @@ export default {
372
381
  this.selectedLabel = e.target.value
373
382
  }
374
383
  }
384
+
375
385
  this.onInputChange(e)
376
386
  })
377
387
  },
@@ -393,6 +403,7 @@ export default {
393
403
  this.$nextTick(() => {
394
404
  // Componente tooltip -> autosuggest -> input
395
405
  const componenteInputInterno = this.$children[1].$refs.input
406
+
396
407
  // Mostra o tooltip só quando
397
408
  this.createHandler(componenteInputInterno, 'mouseenter', () => {
398
409
  if (this.selectedLabel) {
@@ -425,7 +436,7 @@ export default {
425
436
  if (el) {
426
437
  el.addEventListener(
427
438
  ev,
428
- function () {
439
+ () => {
429
440
  func()
430
441
  },
431
442
  false
@@ -459,6 +470,7 @@ export default {
459
470
 
460
471
  // Eventos ao limpar
461
472
  this.$emit('input', null)
473
+
462
474
  if (typeof this.value === 'undefined') {
463
475
  this.$emit('change', null, null)
464
476
  } else {
@@ -488,6 +500,7 @@ export default {
488
500
  if (this.value[this.labelKey]) {
489
501
  initialLabel = this.value[this.labelKey]
490
502
  }
503
+
491
504
  value = this.value[this.valueKey]
492
505
  }
493
506
  } else {
@@ -503,26 +516,32 @@ export default {
503
516
  const isUndefined =
504
517
  Object.prototype.toString.call(value).toLowerCase() ===
505
518
  '[object undefined]'
519
+
506
520
  for (let i = 0; i <= this.cachedOptions.length - 1; i++) {
507
521
  const cachedOption = this.cachedOptions[i]
508
522
  const isEqual = isObject
509
523
  ? getValueByPath(cachedOption.value, this.valueKey) ===
510
524
  getValueByPath(value, this.valueKey)
511
525
  : cachedOption.value === value
526
+
512
527
  if (isEqual) {
513
528
  option = cachedOption
514
529
  break
515
530
  }
516
531
  }
532
+
517
533
  if (option) return option
534
+
518
535
  const label = !isObject && !isNull && !isUndefined ? value : ''
519
536
  const newOption = {
520
537
  value,
521
538
  currentLabel: initialLabel || label
522
539
  }
540
+
523
541
  if (this.multiple) {
524
542
  newOption.hitState = false
525
543
  }
544
+
526
545
  return newOption
527
546
  },
528
547
  checkDefaultFirstOption () {
@@ -531,6 +550,7 @@ export default {
531
550
 
532
551
  for (let i = 0; i !== this.options.length; ++i) {
533
552
  const option = this.options[i]
553
+
534
554
  if (this.query) {
535
555
  // highlight first options that passes the filter
536
556
  if (!option.disabled && !option.groupDisabled && option.visible) {
@@ -558,10 +578,12 @@ export default {
558
578
  } else {
559
579
  this.visible = !this.visible
560
580
  }
581
+
561
582
  if (this.doRequest) {
562
583
  this.handleQueryChange(this.query)
563
584
  this.doRequest = false
564
585
  }
586
+
565
587
  (this.$refs.input || this.$refs.reference).focus()
566
588
  }
567
589
  },
@@ -577,27 +599,33 @@ export default {
577
599
  */
578
600
  handleQueryChange (val) {
579
601
  const _this6 = this
602
+
580
603
  // Correção aqui para forçar primeeira request com createOnLoad = false
581
604
  if (
582
605
  (!this.doRequest && this.previousQuery === val) ||
583
606
  this.isOnComposition
584
607
  ) { return }
608
+
585
609
  if (
586
610
  this.previousQuery === null &&
587
611
  (typeof this.filterMethod === 'function' ||
588
612
  typeof this.remoteMethod === 'function')
589
613
  ) {
590
614
  this.previousQuery = val
615
+
591
616
  return
592
617
  }
618
+
593
619
  this.previousQuery = val
594
- this.$nextTick(function () {
620
+ this.$nextTick(() => {
595
621
  if (_this6.visible) _this6.broadcast('ElSelectDropdown', 'updatePopper')
596
622
  })
597
623
  this.hoverIndex = -1
624
+
598
625
  if (this.multiple && this.filterable) {
599
- this.$nextTick(function () {
626
+ this.$nextTick(() => {
600
627
  const length = _this6.$refs.input.value.length * 15 + 20
628
+
601
629
  _this6.inputLength = _this6.collapseTags
602
630
  ? Math.min(50, length)
603
631
  : length
@@ -605,6 +633,7 @@ export default {
605
633
  _this6.resetInputHeight()
606
634
  })
607
635
  }
636
+
608
637
  if (this.remote && typeof this.remoteMethod === 'function') {
609
638
  this.hoverIndex = -1
610
639
  this.remoteMethod(val)
@@ -616,6 +645,7 @@ export default {
616
645
  this.broadcast('ElOption', 'queryChange', val)
617
646
  this.broadcast('ElOptionGroup', 'queryChange')
618
647
  }
648
+
619
649
  if (
620
650
  this.defaultFirstOption &&
621
651
  (this.filterable || this.remote) &&
@@ -633,6 +663,7 @@ export default {
633
663
  const elInput = document.querySelector(
634
664
  '.el-select[data-is-search="true"]:hover input[readonly]'
635
665
  )
666
+
636
667
  if (elInput) {
637
668
  elInput.readOnly = false
638
669
  elInput.blur()
@@ -720,7 +751,6 @@ input.el-input__inner {
720
751
  padding-left: 20px;
721
752
 
722
753
  &::before {
723
- content: "";
724
754
  position: absolute;
725
755
  display: inline-block;
726
756
  width: 4px;
@@ -104,7 +104,10 @@ export default {
104
104
  default: true
105
105
  },
106
106
 
107
- width: String,
107
+ width: {
108
+ type: String,
109
+ default: 'auto'
110
+ },
108
111
 
109
112
  fullscreen: Boolean,
110
113
 
@@ -117,7 +120,12 @@ export default {
117
120
  type: String,
118
121
  default: '15vh'
119
122
  },
120
- beforeClose: Function,
123
+
124
+ beforeClose: {
125
+ type: Function,
126
+ default: () => {}
127
+ },
128
+
121
129
  center: {
122
130
  type: Boolean,
123
131
  default: false
@@ -136,12 +144,15 @@ export default {
136
144
  computed: {
137
145
  style () {
138
146
  const style = {}
147
+
139
148
  if (!this.fullscreen) {
140
149
  style.marginTop = this.top
150
+
141
151
  if (this.width) {
142
152
  style.width = this.width
143
153
  }
144
154
  }
155
+
145
156
  return style
146
157
  }
147
158
  },
@@ -160,12 +171,15 @@ export default {
160
171
  this.$nextTick(() => {
161
172
  this.$refs.dialog.scrollTop = 0
162
173
  })
174
+
163
175
  if (this.appendToBody) {
164
176
  document.body.appendChild(this.$el)
165
177
  }
166
178
  } else {
167
179
  this.$el.removeEventListener('scroll', this.updatePopper)
180
+
168
181
  if (!this.closed) this.$emit('close')
182
+
169
183
  if (this.destroyOnClose) {
170
184
  this.$nextTick(() => {
171
185
  this.key++
@@ -181,6 +195,7 @@ export default {
181
195
  if (this.visible) {
182
196
  this.rendered = true
183
197
  this.open()
198
+
184
199
  if (this.appendToBody) {
185
200
  document.body.appendChild(this.$el)
186
201
  }
@@ -204,6 +219,7 @@ export default {
204
219
  },
205
220
  handleWrapperClick () {
206
221
  if (!this.closeOnClickModal) return
222
+
207
223
  this.handleClose()
208
224
  },
209
225
  handleClose () {
@@ -97,6 +97,7 @@ export default {
97
97
  this.hideInput = true
98
98
  } else if (!this.readonly) {
99
99
  this.hideInput = status
100
+
100
101
  if (!this.hideInput) {
101
102
  this.$nextTick(function () {
102
103
  this.$refs.inlineInput.focus()
@@ -92,9 +92,15 @@ export default {
92
92
  type: Number,
93
93
  default: -Infinity
94
94
  },
95
- value: {},
95
+ value: {
96
+ type: [Number, String],
97
+ default: null
98
+ },
96
99
  disabled: Boolean,
97
- size: String,
100
+ size: {
101
+ type: [String, Boolean],
102
+ default: false
103
+ },
98
104
  controls: {
99
105
  type: Boolean,
100
106
  default: true
@@ -103,11 +109,21 @@ export default {
103
109
  type: String,
104
110
  default: ''
105
111
  },
106
- name: String,
107
- label: String,
108
- placeholder: String,
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
+ },
109
124
  precision: {
110
125
  type: Number,
126
+ default: 2,
111
127
  validator (val) {
112
128
  return val >= 0 && val === parseInt(val, 10)
113
129
  }
@@ -148,14 +164,16 @@ export default {
148
164
  numPrecision () {
149
165
  const { value, step, getPrecision, precision } = this
150
166
  const stepPrecision = getPrecision(step)
167
+
151
168
  if (precision !== undefined) {
152
169
  if (stepPrecision > precision) {
153
170
  console.warn('[Element Warn][InputNumber]precision should not be less than the decimal places of step')
154
171
  }
172
+
155
173
  return precision
156
- } else {
157
- return Math.max(getPrecision(value), stepPrecision)
158
174
  }
175
+
176
+ return Math.max(getPrecision(value), stepPrecision)
159
177
  },
160
178
  controlsAtRight () {
161
179
  return this.controls && this.controlsPosition === 'right'
@@ -167,7 +185,7 @@ export default {
167
185
  return this.size || this._elFormItemSize || (this.$ELEMENT || {}).size
168
186
  },
169
187
  inputNumberDisabled () {
170
- return this.disabled || !!(this.elForm || {}).disabled
188
+ return this.disabled || Boolean((this.elForm || {}).disabled)
171
189
  },
172
190
  /**
173
191
  * Sobrescrito do element
@@ -178,10 +196,12 @@ export default {
178
196
  if (!this.stringDefaultsZero && this.userInput === '') {
179
197
  this.currentValue = ''
180
198
  }
199
+
181
200
  return this.userInput
182
201
  }
183
202
 
184
203
  let currentValue
204
+
185
205
  if (this.value === '' && !this.stringDefaultsZero) {
186
206
  currentValue = ''
187
207
  } else {
@@ -192,6 +212,7 @@ export default {
192
212
  if (this.stepStrictly) {
193
213
  const stepPrecision = this.getPrecision(this.step)
194
214
  const precisionFactor = Math.pow(10, stepPrecision)
215
+
195
216
  currentValue =
196
217
  (Math.round(currentValue / this.step) *
197
218
  precisionFactor *
@@ -205,8 +226,9 @@ export default {
205
226
  }
206
227
 
207
228
  if (this.usarVirgula) {
208
- currentValue = (currentValue + '').replace('.', ',')
229
+ currentValue = (`${currentValue }`).replace('.', ',')
209
230
  }
231
+
210
232
  return currentValue
211
233
  }
212
234
  },
@@ -219,6 +241,7 @@ export default {
219
241
  immediate: true,
220
242
  handler (value) {
221
243
  let newVal
244
+
222
245
  if (value === undefined) {
223
246
  newVal = value
224
247
  } else if (!this.stringDefaultsZero && value === '') {
@@ -235,6 +258,7 @@ export default {
235
258
  if (this.stepStrictly) {
236
259
  const stepPrecision = this.getPrecision(this.step)
237
260
  const precisionFactor = Math.pow(10, stepPrecision)
261
+
238
262
  newVal = Math.round(newVal / this.step) * precisionFactor * this.step / precisionFactor
239
263
  }
240
264
 
@@ -242,8 +266,11 @@ export default {
242
266
  newVal = this.toPrecision(newVal, this.precision)
243
267
  }
244
268
  }
269
+
245
270
  if (newVal >= this.max) newVal = this.max
271
+
246
272
  if (newVal <= this.min) newVal = this.min
273
+
247
274
  this.currentValue = newVal
248
275
  this.userInput = null
249
276
  this.$emit('input', newVal)
@@ -253,6 +280,7 @@ export default {
253
280
 
254
281
  mounted () {
255
282
  const innerInput = this.$refs.input.$refs.input
283
+
256
284
  innerInput.setAttribute('role', 'spinbutton')
257
285
  innerInput.setAttribute('aria-valuemax', this.max)
258
286
  innerInput.setAttribute('aria-valuemin', this.min)
@@ -262,29 +290,36 @@ export default {
262
290
 
263
291
  updated () {
264
292
  if (!this.$refs || !this.$refs.input) return
293
+
265
294
  const innerInput = this.$refs.input.$refs.input
295
+
266
296
  innerInput.setAttribute('aria-valuenow', this.currentValue)
267
297
  },
268
298
 
269
299
  methods: {
270
300
  toPrecision (num, precision) {
271
301
  if (precision === undefined) precision = this.numPrecision
302
+
272
303
  return parseFloat(Math.round(num * Math.pow(10, precision)) / Math.pow(10, precision))
273
304
  },
274
305
  getPrecision (value) {
275
306
  if (value === undefined) return 0
307
+
276
308
  const valueString = value.toString()
277
309
  const dotPosition = valueString.indexOf('.')
278
310
  let precision = 0
311
+
279
312
  if (dotPosition !== -1) {
280
313
  precision = valueString.length - dotPosition - 1
281
314
  }
315
+
282
316
  return precision
283
317
  },
284
318
  _increase (val, step) {
285
319
  if (typeof val !== 'number' && val !== undefined) return this.currentValue
286
320
 
287
321
  const precisionFactor = Math.pow(10, this.numPrecision)
322
+
288
323
  // Solve the accuracy problem of JS decimal calculation by converting the value to integer.
289
324
  return this.toPrecision((precisionFactor * val + precisionFactor * step) / precisionFactor)
290
325
  },
@@ -297,14 +332,18 @@ export default {
297
332
  },
298
333
  increase () {
299
334
  if (this.inputNumberDisabled || this.maxDisabled) return
335
+
300
336
  const value = this.value || 0
301
337
  const newVal = this._increase(value, this.step)
338
+
302
339
  this.setCurrentValue(newVal)
303
340
  },
304
341
  decrease () {
305
342
  if (this.inputNumberDisabled || this.minDisabled) return
343
+
306
344
  const value = this.value || 0
307
345
  const newVal = this._decrease(value, this.step)
346
+
308
347
  this.setCurrentValue(newVal)
309
348
  },
310
349
  handleBlur (event) {
@@ -320,6 +359,7 @@ export default {
320
359
  handleInput (value) {
321
360
  this.userInput = value
322
361
  let newVal
362
+
323
363
  if (value === '' && this.stringDefaultsZero) {
324
364
  newVal = Number(value.replace(',', '.'))
325
365
  } else {
@@ -334,6 +374,7 @@ export default {
334
374
  */
335
375
  handleInputChange (value) {
336
376
  let newVal
377
+
337
378
  if (value === '') {
338
379
  // Por padrão converte '' para 0
339
380
  if (this.stringDefaultsZero) {
@@ -348,6 +389,7 @@ export default {
348
389
  if (!isNaN(newVal) || value === '') {
349
390
  this.setCurrentValue(newVal)
350
391
  }
392
+
351
393
  this.userInput = null
352
394
  },
353
395
 
@@ -356,12 +398,17 @@ export default {
356
398
  */
357
399
  setCurrentValue (newVal) {
358
400
  const oldVal = this.currentValue
401
+
359
402
  if (typeof newVal === 'number' && this.precision !== undefined) {
360
403
  newVal = this.toPrecision(newVal, this.precision)
361
404
  }
405
+
362
406
  if (newVal >= this.max) newVal = this.max
407
+
363
408
  if (newVal <= this.min) newVal = this.min
409
+
364
410
  if (oldVal === newVal && newVal === this.value) return
411
+
365
412
  this.userInput = null
366
413
  this.$emit('input', newVal)
367
414
  this.$emit('change', newVal, oldVal)