@kigi/components 1.53.0 → 1.54.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.
package/package.json
CHANGED
|
@@ -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.
|
|
12
|
-
ng-keydown="$ctrl.
|
|
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,
|
|
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,
|