@kigi/components 1.52.0 → 1.53.0-beta.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kigi/components",
3
- "version": "1.52.0",
3
+ "version": "1.53.0-beta.1",
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>
@@ -9,8 +9,11 @@ class MbgInputTagsController {
9
9
  private ngKeyup
10
10
  private props
11
11
  private inputValue: string
12
+ private maxlength: number
13
+ private ngKeypress
14
+ private ngPaste
12
15
 
13
- constructor(public $scope, public $element, public $attrs) {
16
+ constructor(public $scope, public $element, public $attrs, public $timeout) {
14
17
  if ($attrs.ngRequired === '') { this.ngRequired = true }
15
18
  if ($attrs.ngDisabled === '') { this.ngDisabled = true }
16
19
  this.props = {
@@ -39,6 +42,35 @@ class MbgInputTagsController {
39
42
  }
40
43
  }
41
44
 
45
+ onKeypress(param) {
46
+ const evt = param.$event
47
+ if (evt.target && evt.target.value && this.maxlength && this.validadeLength(evt.target.value) >= this.maxlength) {
48
+ param.$event.preventDefault()
49
+ param.$event.stopPropagation()
50
+ return
51
+ }
52
+ if (this.ngKeypress) {
53
+ this.ngKeypress(param)
54
+ }
55
+ }
56
+
57
+ onPaste(param) {
58
+ let currentInputValue = this.inputValue;
59
+ let actualLength = (this.inputValue || '').length
60
+
61
+ navigator.clipboard.readText().then(text => {
62
+ let pastedValue = text;
63
+ let pastedLength = pastedValue.length;
64
+ if (pastedLength + actualLength > this.maxlength) {
65
+ this.$timeout(() => {
66
+ let partiallyPastedValue = pastedValue.slice(0, this.maxlength - actualLength);
67
+ this.inputValue = `${currentInputValue}${partiallyPastedValue}`
68
+ this.ngPaste && this.ngPaste(param);
69
+ })
70
+ }
71
+ })
72
+ }
73
+
42
74
  addTag(str: string) {
43
75
  const newTag = str.trim()
44
76
  if ((this.ngModel || []).filter((tag) => tag === newTag).length === 0) {
@@ -50,9 +82,14 @@ class MbgInputTagsController {
50
82
  this.ngModel.splice(index, 1)
51
83
  }
52
84
 
85
+ validadeLength(currentInputValue) {
86
+ const inputValueLength = (currentInputValue || this.inputValue || '').length
87
+ return this.ngModel.reduce((total, keyword) => total + keyword.length, 0) + inputValueLength
88
+ }
89
+
53
90
  }
54
91
 
55
- MbgInputTagsController.$inject = ['$scope', '$element', '$attrs']
92
+ MbgInputTagsController.$inject = ['$scope', '$element', '$attrs', '$timeout']
56
93
 
57
94
  const mbgInputTags = {
58
95
  bindings: {
@@ -66,6 +103,7 @@ const mbgInputTags = {
66
103
  ngKeypress: '&?',
67
104
  ngKeydown: '&?',
68
105
  inputValue: '=?',
106
+ maxlength: '=?'
69
107
  },
70
108
  template,
71
109
  controller: MbgInputTagsController,