@kigi/components 1.56.0-beta.1 → 1.56.0-beta.2

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kigi/components",
3
- "version": "1.56.0-beta.1",
3
+ "version": "1.56.0-beta.2",
4
4
  "description": "@kigi/components",
5
5
  "main": "src/components/index.ts",
6
6
  "scripts": {
@@ -100,4 +100,4 @@
100
100
  "webpack": "^2.5.1",
101
101
  "webpack-dev-server": "^2.6.1"
102
102
  }
103
- }
103
+ }
@@ -8,8 +8,9 @@
8
8
  ng-blur="$ctrl.ngBlur({ $event })"
9
9
  ng-focus="$ctrl.ngFocus({ $event })"
10
10
  ng-keyup="$ctrl.onKeyUp({ $event })"
11
- ng-keypress="$ctrl.ngKeypress({ $event })"
12
- ng-keydown="$ctrl.ngKeydown({ $event })"
11
+ ng-keypress="$ctrl.onKeypress({ $event })"
12
+ ng-keydown="$ctrl.onKeydown({ $event })"
13
+ ng-paste="$ctrl.onPaste({$event})"
13
14
  placeholder="{{ $ctrl.props.placeholder }}" />
14
15
  <div class="mbg-input-tags-content">
15
16
  <div ng-repeat="tag in $ctrl.ngModel track by $index">
@@ -41,4 +42,7 @@
41
42
  </div>
42
43
  </div>
43
44
  </div>
44
- </div>
45
+ </div>
46
+ <span class="flex justify-end">
47
+ {{$ctrl.validadeLength() }} / {{$ctrl.maxlength}} Caracteres
48
+ </span>
@@ -1,5 +1,6 @@
1
1
  import './mbg-input-tags.scss'
2
2
  import template from './mbg-input-tags.html'
3
+ import { HelperNotificationService } from 'modules/helpers/services/notification.service'
3
4
 
4
5
  class MbgInputTagsController {
5
6
  private ngChange
@@ -9,8 +10,15 @@ class MbgInputTagsController {
9
10
  private ngKeyup
10
11
  private props
11
12
  private inputValue: string
13
+ private maxlength: number
14
+ private ngKeypress
15
+ private ngPaste
12
16
 
13
- constructor(public $scope, public $element, public $attrs) {
17
+ constructor(public $scope,
18
+ public $element,
19
+ public $attrs,
20
+ public $timeout,
21
+ public helperNotificationService: HelperNotificationService) {
14
22
  if ($attrs.ngRequired === '') { this.ngRequired = true }
15
23
  if ($attrs.ngDisabled === '') { this.ngDisabled = true }
16
24
  this.props = {
@@ -39,8 +47,58 @@ class MbgInputTagsController {
39
47
  }
40
48
  }
41
49
 
50
+ onKeypress(param) {
51
+ const evt = param.$event
52
+
53
+ let keywordsTotalLength = this.ngModel.reduce((total, keyword) => total + keyword.length, 0)
54
+ if (keywordsTotalLength === this.maxlength) {
55
+ this.inputValue = '';
56
+ param.$event.preventDefault()
57
+ this.helperNotificationService.error('Limite de caracteres atingido!')
58
+ return
59
+ }
60
+ if (evt.target && evt.target.value && this.maxlength && this.validadeLength(evt.target.value, keywordsTotalLength) >= this.maxlength) {
61
+ param.$event.preventDefault()
62
+ param.$event.stopPropagation()
63
+ return
64
+ }
65
+ if (this.ngKeypress) {
66
+ this.ngKeypress(param)
67
+ }
68
+ }
69
+
70
+
71
+ onPaste(param) {
72
+ const evt = param.$event;
73
+ const currentInputValue = this.inputValue || '';
74
+ const keywordsTotalLength = this.ngModel.reduce((total, keyword) => total + keyword.length, 0);
75
+ const actualLength = currentInputValue.length;
76
+ const maxLengthRemaining = this.maxlength - keywordsTotalLength;
77
+
78
+ navigator.clipboard.readText().then((text) => {
79
+ const pastedValue = text || '';
80
+
81
+ let spaceLeft = maxLengthRemaining - actualLength;
82
+
83
+ if (spaceLeft > 0) {
84
+ this.$timeout(() => {
85
+ const partiallyPastedValue = pastedValue.slice(0, spaceLeft);
86
+ this.inputValue = `${currentInputValue}${partiallyPastedValue}`;
87
+ this.ngPaste && this.ngPaste(param);
88
+ });
89
+ } else {
90
+ this.inputValue = '';
91
+ evt.preventDefault();
92
+ this.helperNotificationService.error('Limite de caracteres atingido!')
93
+ }
94
+ }).catch((err) => {
95
+ console.error('Erro ao acessar o texto do clipboard:', err);
96
+ });
97
+ }
98
+
42
99
  addTag(str: string) {
43
100
  const newTag = str.trim()
101
+ if (!newTag) { return }
44
102
  if ((this.ngModel || []).filter((tag) => tag === newTag).length === 0) {
45
103
  this.ngModel.push(newTag)
46
104
  }
@@ -50,9 +108,14 @@ class MbgInputTagsController {
50
108
  this.ngModel.splice(index, 1)
51
109
  }
52
110
 
111
+ validadeLength(currentInputValue, keywordsTotalLength) {
112
+ const inputValueLength = (currentInputValue || this.inputValue || '').length
113
+ return this.ngModel.reduce((total, keyword) => total + keyword.length, 0) + inputValueLength
114
+ }
115
+
53
116
  }
54
117
 
55
- MbgInputTagsController.$inject = ['$scope', '$element', '$attrs']
118
+ MbgInputTagsController.$inject = ['$scope', '$element', '$attrs', '$timeout', 'helperNotificationService']
56
119
 
57
120
  const mbgInputTags = {
58
121
  bindings: {
@@ -66,6 +129,7 @@ const mbgInputTags = {
66
129
  ngKeypress: '&?',
67
130
  ngKeydown: '&?',
68
131
  inputValue: '=?',
132
+ maxlength: '=?'
69
133
  },
70
134
  template,
71
135
  controller: MbgInputTagsController,
@@ -41,10 +41,11 @@
41
41
  </path>
42
42
  </svg>
43
43
  <i class="fa fa-caret-down mbg-icon-select"
44
- ng-show="!$ctrl.ngModel && !$ctrl.isLoading"
44
+ ng-show="(!$ctrl.ngModel && !$ctrl.isLoading) || $ctrl.disableClearButton"
45
45
  ng-click="$ctrl.clickArrow()"
46
46
  aria-hidden="true"></i>
47
47
  <i class="fa fa-times mbg-icon-select"
48
+ ng-if="!$ctrl.disableClearButton"
48
49
  ng-show="$ctrl.ngModel && !$ctrl.isLoading"
49
50
  aria-hidden="true"
50
51
  ng-click="$ctrl.clearNgModel(true)"></i>
@@ -52,6 +52,7 @@ class MbgSelectController {
52
52
  private callBackFavorite: Function
53
53
  private favoriteModel
54
54
  private productKitList: boolean
55
+ private disableClearButton: boolean
55
56
  private focusableElements
56
57
  private nextIndex
57
58
 
@@ -68,6 +69,7 @@ class MbgSelectController {
68
69
  this.fixedValue = this.ngValue || 'id'
69
70
  this.inputValue = ''
70
71
  this.enableAdd = this.enableAdd || false
72
+ this.disableClearButton = this.disableClearButton || false
71
73
  this.observeModel()
72
74
  this.updateInputValue()
73
75
  this.findTransclude()
@@ -759,6 +761,7 @@ const mbgSelect = {
759
761
  mountValue: '&?',
760
762
  callBackFavorite: '&?',
761
763
  productKitList: '=?',
764
+ disableClearButton: '=?',
762
765
  },
763
766
  controller: MbgSelectController,
764
767
  template,