@kigi/components 1.55.0 → 1.56.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.55.0",
3
+ "version": "1.56.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
+ }
@@ -12,7 +12,7 @@
12
12
  ng-focus="$ctrl.ngFocus({ $event })"
13
13
  ng-keyup="$ctrl.ngKeyup({ $event })"
14
14
  ng-keypress="$ctrl.ngKeypress({ $event })"
15
- ng-keydown="$ctrl.ngKeydown({ $event })"
15
+ ng-keydown="$ctrl.onInputKeydown($event)"
16
16
  ui-date-mask="{{ $ctrl.format }}" />
17
17
  <!-- with calendar -->
18
18
  <input type="text"
@@ -27,7 +27,7 @@
27
27
  ng-focus="$ctrl.handleFocus({ $event })"
28
28
  ng-keyup="$ctrl.ngKeyup({ $event })"
29
29
  ng-keypress="$ctrl.ngKeypress({ $event })"
30
- ng-keydown="$ctrl.ngKeydown({ $event })"
30
+ ng-keydown="$ctrl.onInputKeydown($event)"
31
31
  ui-date-mask="{{ $ctrl.format }}"
32
32
  only-month-year="$ctrl.onlyMonthYear"
33
33
  ng-class="{'input-date':$ctrl.titleMode}"
@@ -46,7 +46,7 @@
46
46
  ng-focus="$ctrl.handleFocus({ $event })"
47
47
  ng-keyup="$ctrl.ngKeyup({ $event })"
48
48
  ng-keypress="$ctrl.ngKeypress({ $event })"
49
- ng-keydown="$ctrl.ngKeydown({ $event })"
49
+ ng-keydown="$ctrl.onInputKeydown($event)"
50
50
  ui-date-mask="{{ $ctrl.format }}"
51
51
  on-select="$ctrl.onSelectStart()"
52
52
  only-month-year="$ctrl.onlyMonthYear"
@@ -65,7 +65,7 @@
65
65
  ng-focus="$ctrl.handleFocus({ $event })"
66
66
  ng-keyup="$ctrl.ngKeyup({ $event })"
67
67
  ng-keypress="$ctrl.ngKeypress({ $event })"
68
- ng-keydown="$ctrl.ngKeydown({ $event })"
68
+ ng-keydown="$ctrl.onInputKeydown($event)"
69
69
  ui-date-mask="{{ $ctrl.format }}"
70
70
  on-select="$ctrl.onSelectEnd()"
71
71
  only-month-year="$ctrl.onlyMonthYear"
@@ -1,5 +1,6 @@
1
- import './mbg-input-date.scss'
1
+ import { focusNextElement, getNextFocusableElement } from '../../helpers/custom-key-down'
2
2
  import template from './mbg-input-date.html'
3
+ import './mbg-input-date.scss'
3
4
  declare let $
4
5
 
5
6
  class MbgInputDateController {
@@ -17,7 +18,7 @@ class MbgInputDateController {
17
18
  public betweenText: string
18
19
  public filterDate: Function
19
20
  public onlyMonthYear: boolean
20
-
21
+ private ngKeydown: Function
21
22
 
22
23
  constructor(public $scope, public $element, public $attrs, public $timeout) {
23
24
  if ($attrs.ngRequired === '') {
@@ -110,6 +111,25 @@ class MbgInputDateController {
110
111
  this.ngModel.end ? this.ngModel.end.getTime() >= new Date(date).getTime() : true,
111
112
  })
112
113
  }
114
+
115
+ onInputKeydown(evt) {
116
+ if (this.ngDisabled) {
117
+ return
118
+ }
119
+
120
+ switch (evt.keyCode) {
121
+ case 9: // TAB
122
+ evt.preventDefault()
123
+ evt.stopPropagation()
124
+ const { focusableElements, nextIndex } = getNextFocusableElement(this.$element)
125
+ focusNextElement(focusableElements, nextIndex)
126
+ break
127
+ }
128
+
129
+ if (this.ngKeydown) {
130
+ this.ngKeydown({ $event: evt })
131
+ }
132
+ }
113
133
  }
114
134
 
115
135
  MbgInputDateController['$inject'] = ['$scope', '$element', '$attrs', '$timeout']
@@ -2,13 +2,14 @@
2
2
  tabindex="-1"
3
3
  ng-click="$ctrl.selectInput()"
4
4
  ng-if="$ctrl.props">
5
- <input type="text"
6
- ng-model="$ctrl.ngModel"
7
- ng-change="$ctrl.onChange()"
8
- ng-required="$ctrl.ngRequired"
9
- ng-disabled="$ctrl.ngDisabled"
10
- ng-blur="$ctrl.ngBlur({ $event })"
11
- ng-focus="$ctrl.ngFocus({ $event })"
12
- ui-money-mask="{{ $ctrl.props.precision }}"
13
- placeholder="{{ $ctrl.props.placeholder }}" />
5
+ <input type="text"
6
+ ng-model="$ctrl.ngModel"
7
+ ng-change="$ctrl.onChange()"
8
+ ng-required="$ctrl.ngRequired"
9
+ ng-disabled="$ctrl.ngDisabled"
10
+ ng-blur="$ctrl.ngBlur({ $event })"
11
+ ng-focus="$ctrl.ngFocus({ $event })"
12
+ ng-keydown="$ctrl.onInputKeydown($event)"
13
+ ui-money-mask="{{ $ctrl.props.precision }}"
14
+ placeholder="{{ $ctrl.props.placeholder }}" />
14
15
  </div>
@@ -1,54 +1,79 @@
1
- import './mbg-input-money.scss'
1
+ import { focusNextElement, getNextFocusableElement } from '../../helpers/custom-key-down'
2
2
  import template from './mbg-input-money.html'
3
+ import './mbg-input-money.scss'
3
4
 
4
5
  class MbgInputMoneyController {
5
- private ngChange
6
- private ngModel
7
- private ngRequired
8
- private ngDisabled
9
- private props
10
- private ngKeyup: Function
11
-
12
- constructor(public $scope, public $element, public $attrs) {
13
- if ($attrs.ngRequired === '') { this.ngRequired = true }
14
- if ($attrs.ngDisabled === '') { this.ngDisabled = true }
15
- this.props = {
16
- placeholder: $attrs.placeholder || '',
17
- prefix: $attrs.prefix || 'R$ ',
18
- decimal: $attrs.decimal || ',',
19
- thousands: $attrs.decimal || '.',
20
- precision: this.$scope.$parent.$eval($attrs.precision) || 2,
21
- allowNegative: $attrs.allowNegative ? JSON.parse($attrs.allowNegative) : true,
22
- allowZero: $attrs.allowZero ? JSON.parse($attrs.allowZero) : false,
23
- allowEmpty: $attrs.allowEmpty ? JSON.parse($attrs.allowEmpty) : false,
24
- }
6
+ private ngChange
7
+ private ngModel
8
+ private ngRequired
9
+ private ngDisabled
10
+ private props
11
+ private ngKeyup: Function
12
+ private ngKeydown: Function
13
+
14
+ constructor(public $scope, public $element, public $attrs) {
15
+ if ($attrs.ngRequired === '') {
16
+ this.ngRequired = true
17
+ }
18
+ if ($attrs.ngDisabled === '') {
19
+ this.ngDisabled = true
20
+ }
21
+ this.props = {
22
+ placeholder: $attrs.placeholder || '',
23
+ prefix: $attrs.prefix || 'R$ ',
24
+ decimal: $attrs.decimal || ',',
25
+ thousands: $attrs.decimal || '.',
26
+ precision: this.$scope.$parent.$eval($attrs.precision) || 2,
27
+ allowNegative: $attrs.allowNegative ? JSON.parse($attrs.allowNegative) : true,
28
+ allowZero: $attrs.allowZero ? JSON.parse($attrs.allowZero) : false,
29
+ allowEmpty: $attrs.allowEmpty ? JSON.parse($attrs.allowEmpty) : false,
25
30
  }
31
+ }
26
32
 
27
- onChange() {
28
- if (this.ngChange) {
29
- this.ngChange({})
30
- }
33
+ onChange() {
34
+ if (this.ngChange) {
35
+ this.ngChange({})
31
36
  }
37
+ }
32
38
 
33
- selectInput() {
34
- this.$element.find('input').select()
39
+ selectInput() {
40
+ this.$element.find('input').select()
41
+ }
42
+
43
+ onInputKeydown(evt) {
44
+ if (this.ngDisabled) {
45
+ return
46
+ }
47
+
48
+ switch (evt.keyCode) {
49
+ case 9: // TAB
50
+ evt.preventDefault()
51
+ evt.stopPropagation()
52
+ const { focusableElements, nextIndex } = getNextFocusableElement(this.$element)
53
+ focusNextElement(focusableElements, nextIndex)
54
+ break
35
55
  }
36
56
 
57
+ if (this.ngKeydown) {
58
+ this.ngKeydown({ $event: evt })
59
+ }
60
+ }
37
61
  }
38
62
 
39
- MbgInputMoneyController.$inject = ['$scope', '$element', '$attrs']
63
+ MbgInputMoneyController['$inject'] = ['$scope', '$element', '$attrs']
40
64
 
41
65
  const mbgInputMoney = {
42
- bindings: {
43
- ngModel: '=',
44
- ngChange: '&?',
45
- ngRequired: '=?',
46
- ngDisabled: '=?',
47
- ngBlur: '&?',
48
- ngFocus: '&?'
49
- },
50
- template,
51
- controller: MbgInputMoneyController,
66
+ bindings: {
67
+ ngModel: '=',
68
+ ngChange: '&?',
69
+ ngRequired: '=?',
70
+ ngDisabled: '=?',
71
+ ngBlur: '&?',
72
+ ngFocus: '&?',
73
+ ngKeydown: '&?',
74
+ },
75
+ template,
76
+ controller: MbgInputMoneyController,
52
77
  }
53
78
 
54
79
  export { mbgInputMoney }
@@ -8,9 +8,8 @@
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.onKeypress({ $event })"
12
- ng-keydown="$ctrl.onKeydown({ $event })"
13
- ng-paste="$ctrl.onPaste({$event})"
11
+ ng-keypress="$ctrl.ngKeypress({ $event })"
12
+ ng-keydown="$ctrl.ngKeydown({ $event })"
14
13
  placeholder="{{ $ctrl.props.placeholder }}" />
15
14
  <div class="mbg-input-tags-content">
16
15
  <div ng-repeat="tag in $ctrl.ngModel track by $index">
@@ -42,7 +41,4 @@
42
41
  </div>
43
42
  </div>
44
43
  </div>
45
- </div>
46
- <span class="flex justify-end">
47
- {{$ctrl.validadeLength() }} / {{$ctrl.maxlength}} Caracteres
48
- </span>
44
+ </div>
@@ -1,6 +1,5 @@
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'
4
3
 
5
4
  class MbgInputTagsController {
6
5
  private ngChange
@@ -10,15 +9,8 @@ class MbgInputTagsController {
10
9
  private ngKeyup
11
10
  private props
12
11
  private inputValue: string
13
- private maxlength: number
14
- private ngKeypress
15
- private ngPaste
16
12
 
17
- constructor(public $scope,
18
- public $element,
19
- public $attrs,
20
- public $timeout,
21
- public helperNotificationService: HelperNotificationService) {
13
+ constructor(public $scope, public $element, public $attrs) {
22
14
  if ($attrs.ngRequired === '') { this.ngRequired = true }
23
15
  if ($attrs.ngDisabled === '') { this.ngDisabled = true }
24
16
  this.props = {
@@ -47,58 +39,8 @@ class MbgInputTagsController {
47
39
  }
48
40
  }
49
41
 
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
-
99
42
  addTag(str: string) {
100
43
  const newTag = str.trim()
101
- if (!newTag) { return }
102
44
  if ((this.ngModel || []).filter((tag) => tag === newTag).length === 0) {
103
45
  this.ngModel.push(newTag)
104
46
  }
@@ -108,14 +50,9 @@ class MbgInputTagsController {
108
50
  this.ngModel.splice(index, 1)
109
51
  }
110
52
 
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
-
116
53
  }
117
54
 
118
- MbgInputTagsController.$inject = ['$scope', '$element', '$attrs', '$timeout', 'helperNotificationService']
55
+ MbgInputTagsController.$inject = ['$scope', '$element', '$attrs']
119
56
 
120
57
  const mbgInputTags = {
121
58
  bindings: {
@@ -129,7 +66,6 @@ const mbgInputTags = {
129
66
  ngKeypress: '&?',
130
67
  ngKeydown: '&?',
131
68
  inputValue: '=?',
132
- maxlength: '=?'
133
69
  },
134
70
  template,
135
71
  controller: MbgInputTagsController,
@@ -3,6 +3,7 @@
3
3
  <input type="text"
4
4
  ng-model="$ctrl.ngModel"
5
5
  ng-change="$ctrl.onChange($event)"
6
+ ng-keydown="$ctrl.onInputKeydown($event)"
6
7
  ng-required="$ctrl.ngRequired"
7
8
  ng-disabled="$ctrl.ngDisabled"
8
9
  ng-blur="$ctrl.ngBlur({ $event })"
@@ -1,7 +1,7 @@
1
- import './mbg-input-text.scss'
2
- import * as angular from 'angular'
3
- import template from './mbg-input-text.html'
4
1
  import { Capitalize } from '../../helpers/capitalize'
2
+ import { focusNextElement, getNextFocusableElement } from '../../helpers/custom-key-down'
3
+ import template from './mbg-input-text.html'
4
+ import './mbg-input-text.scss'
5
5
 
6
6
  class MbgInputTextController {
7
7
  private ngChange
@@ -12,6 +12,8 @@ class MbgInputTextController {
12
12
  private ngKeydown
13
13
  private ngValue
14
14
  private capitalize
15
+ private focusableElements
16
+ private nextIndex
15
17
 
16
18
  constructor(public $scope, public $element, public $attrs) {
17
19
  if ($attrs.ngRequired === '') {
@@ -49,14 +51,27 @@ class MbgInputTextController {
49
51
  }
50
52
  }
51
53
 
52
- onKeydown($event: Event) {
53
- $event.stopPropagation()
54
+ onInputKeydown(evt) {
55
+ if (this.ngDisabled) {
56
+ return
57
+ }
58
+
59
+ switch (evt.keyCode) {
60
+ case 9: // TAB
61
+ evt.preventDefault()
62
+ evt.stopPropagation()
63
+ const { focusableElements, nextIndex } = getNextFocusableElement(this.$element)
64
+ focusNextElement(focusableElements, nextIndex)
65
+ break
66
+ }
67
+
54
68
  if (this.ngKeydown) {
55
- this.ngKeydown({ $event })
69
+ this.ngKeydown({ $event: evt })
56
70
  }
57
71
  }
58
72
  }
59
- MbgInputTextController.$inject = ['$scope', '$element', '$attrs']
73
+
74
+ MbgInputTextController['$inject'] = ['$scope', '$element', '$attrs']
60
75
 
61
76
  const mbgInputText = {
62
77
  bindings: {
@@ -83,6 +83,7 @@
83
83
  <input ng-model="$ctrl.inputValue"
84
84
  ng-keydown="$ctrl.onInputKeydown($event)"
85
85
  ng-blur="$ctrl.onInputBlur()"
86
+ ng-disabled="$ctrl.ngDisabled"
86
87
  placeholder="Digite algo para pesquisar..."
87
88
  ng-change="$ctrl.onInputChange()" />
88
89
  </div>
@@ -1,10 +1,11 @@
1
- import { Capitalize } from '../../helpers/capitalize'
2
1
  import * as angular from 'angular'
3
- import './mbg-select.scss'
4
- import template from './mbg-select.html'
2
+ import { AbsPosition } from '../../helpers/abs-position'
3
+ import { Capitalize } from '../../helpers/capitalize'
5
4
  import { MbgCookie } from '../../helpers/cookie'
5
+ import { focusNextElement, getNextFocusableElement } from '../../helpers/custom-key-down'
6
6
  import { UtilUID } from '../../helpers/util-uid'
7
- import { AbsPosition } from '../../helpers/abs-position'
7
+ import template from './mbg-select.html'
8
+ import './mbg-select.scss'
8
9
 
9
10
  class MbgSelectController {
10
11
  private data: any
@@ -51,6 +52,8 @@ class MbgSelectController {
51
52
  private callBackFavorite: Function
52
53
  private favoriteModel
53
54
  private productKitList: boolean
55
+ private focusableElements
56
+ private nextIndex
54
57
 
55
58
  constructor(
56
59
  public $scope,
@@ -357,7 +360,10 @@ class MbgSelectController {
357
360
  this.moveToDown()
358
361
  break
359
362
  case 9: // TAB
363
+ evt.preventDefault()
364
+ evt.stopPropagation()
360
365
  this.setModel()
366
+ focusNextElement(this.focusableElements, this.nextIndex)
361
367
  break
362
368
  case 8: // BACKSPACE
363
369
  this.cancelBeforePromise()
@@ -506,6 +512,9 @@ class MbgSelectController {
506
512
  }
507
513
 
508
514
  addInBody() {
515
+ const { focusableElements, nextIndex } = getNextFocusableElement(this.$element)
516
+ this.focusableElements = focusableElements
517
+ this.nextIndex = nextIndex
509
518
  const body = angular.element(document).find('body')
510
519
  const list = this.$element.find('.mbg-select-list')
511
520
  list.attr('uid', this.uid)
@@ -0,0 +1,28 @@
1
+ import * as angular from 'angular'
2
+
3
+ export function getNextFocusableElement(element) {
4
+ var input = element.find('input')[0]
5
+ const focusableSelectors = 'input, select, textarea, button, a[href]'
6
+ const focusableElements = Array.from(document.querySelectorAll(focusableSelectors)).filter(
7
+ (el: any) => {
8
+ const notDisabled = !el.disabled && el.tabIndex !== -1
9
+ const isVisible = !!(el.offsetWidth || el.offsetHeight || el.getClientRects().length)
10
+ const isNotButton = el.tagName.toLowerCase() !== 'button'
11
+ return notDisabled && isVisible && isNotButton
12
+ },
13
+ )
14
+
15
+ const currentIndex = focusableElements.indexOf(input)
16
+ const nextIndex = (currentIndex + 1) % focusableElements.length
17
+ return { focusableElements, nextIndex }
18
+ }
19
+
20
+ export function focusNextElement(focusableElements, nextIndex) {
21
+ const nextElement = focusableElements[nextIndex]
22
+ const nextScope = angular.element(focusableElements[nextIndex]).scope()
23
+ if (nextScope && nextScope.$ctrl && nextScope.$ctrl.clickInputFake) {
24
+ nextScope.$ctrl.clickInputFake()
25
+ } else {
26
+ nextElement.focus()
27
+ }
28
+ }