@sankhyalabs/core 0.0.0-bugfix-dev-KB-17130.1 → 0.0.0-bugfix-dev-KB-35840.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.
Files changed (152) hide show
  1. package/.docs/README.md +3 -1
  2. package/.docs/classes/ApplicationContext.md +31 -32
  3. package/.docs/classes/ArrayUtils.md +183 -41
  4. package/.docs/classes/AuthorizedServiceCaller.md +25 -34
  5. package/.docs/classes/Change.md +59 -74
  6. package/.docs/classes/DataUnit.md +1025 -1078
  7. package/.docs/classes/DataUnitAction.md +25 -42
  8. package/.docs/classes/DataUnitStorage.md +40 -43
  9. package/.docs/classes/DateUtils.md +140 -133
  10. package/.docs/classes/ElementIDUtils.md +123 -122
  11. package/.docs/classes/ErrorException.md +67 -88
  12. package/.docs/classes/ErrorTracking.md +20 -23
  13. package/.docs/classes/FieldComparator.md +35 -39
  14. package/.docs/classes/FloatingManager.md +195 -198
  15. package/.docs/classes/HTMLBuilder.md +14 -20
  16. package/.docs/classes/HttpProvider.md +45 -41
  17. package/.docs/classes/IDBRepository.md +179 -196
  18. package/.docs/classes/JSUtils.md +82 -58
  19. package/.docs/classes/KeyboardManager.md +95 -87
  20. package/.docs/classes/{MaskFormatter-1.md → MaskFormatter.md} +81 -120
  21. package/.docs/classes/NumberUtils.md +163 -152
  22. package/.docs/classes/ObjectUtils.md +82 -61
  23. package/.docs/classes/OnboardingUtils.md +36 -51
  24. package/.docs/classes/OverflowWatcher.md +269 -0
  25. package/.docs/classes/PromiseSync.md +25 -42
  26. package/.docs/classes/ReadyUtil.md +31 -41
  27. package/.docs/classes/RequestMetadata.md +29 -30
  28. package/.docs/classes/SearchUtils.md +41 -0
  29. package/.docs/classes/SelectionInfo.md +59 -74
  30. package/.docs/classes/SkwHttpProvider.md +33 -45
  31. package/.docs/classes/StringUtils.md +397 -268
  32. package/.docs/classes/TimeFormatter.md +43 -44
  33. package/.docs/classes/UserAgentUtils.md +17 -20
  34. package/.docs/classes/VersionUtils.md +15 -18
  35. package/.docs/classes/WaitingChangeException.md +63 -84
  36. package/.docs/classes/WarningException.md +67 -88
  37. package/.docs/enumerations/Action.md +297 -0
  38. package/.docs/enumerations/ChangeOperation.md +47 -0
  39. package/.docs/enumerations/DataType.md +57 -0
  40. package/.docs/enumerations/DependencyType.md +37 -0
  41. package/.docs/enumerations/OverflowDirection.md +29 -0
  42. package/.docs/enumerations/SelectionMode.md +27 -0
  43. package/.docs/enumerations/SortMode.md +27 -0
  44. package/.docs/enumerations/UserInterface.md +177 -0
  45. package/.docs/functions/defaultDataLoader.md +25 -0
  46. package/.docs/{modules.md → globals.md} +22 -37
  47. package/.docs/interfaces/ChildDescriptor.md +12 -16
  48. package/.docs/interfaces/ChildLink.md +9 -12
  49. package/.docs/interfaces/DUActionInterceptor.md +10 -14
  50. package/.docs/interfaces/ExecutionContext.md +17 -32
  51. package/.docs/interfaces/FieldDescriptor.md +52 -66
  52. package/.docs/interfaces/Filter.md +13 -17
  53. package/.docs/interfaces/IElementIDInfo.md +11 -14
  54. package/.docs/interfaces/ILoadResult.md +11 -16
  55. package/.docs/interfaces/IRepository.md +88 -93
  56. package/.docs/interfaces/IRepositoryIndex.md +23 -30
  57. package/.docs/interfaces/LoadDataRequest.md +36 -45
  58. package/.docs/interfaces/LoadDataResponse.md +11 -14
  59. package/.docs/interfaces/PageRequest.md +16 -20
  60. package/.docs/interfaces/PaginationInfo.md +24 -31
  61. package/.docs/interfaces/PromiseSyncCallback.md +13 -17
  62. package/.docs/interfaces/QuickFilter.md +17 -21
  63. package/.docs/interfaces/Record.md +26 -33
  64. package/.docs/interfaces/SavedRecord.md +33 -41
  65. package/.docs/interfaces/Sort.md +12 -16
  66. package/.docs/interfaces/SortingProvider.md +10 -13
  67. package/.docs/interfaces/UnitMetadata.md +16 -21
  68. package/.docs/interfaces/WaitingChange.md +16 -20
  69. package/.docs/namespaces/MaskFormatter/README.md +17 -0
  70. package/.docs/namespaces/MaskFormatter/type-aliases/MaskCharacter.md +13 -0
  71. package/.docs/namespaces/MaskFormatter/variables/MaskCharacter.md +13 -0
  72. package/.docs/type-aliases/OnOverflowCallBack.md +25 -0
  73. package/.releaserc +10 -10
  74. package/dist/dataunit/DataUnit.d.ts +24 -2
  75. package/dist/dataunit/DataUnit.js +49 -9
  76. package/dist/dataunit/DataUnit.js.map +1 -1
  77. package/dist/dataunit/formatting/PrettyFormatter.js +9 -5
  78. package/dist/dataunit/formatting/PrettyFormatter.js.map +1 -1
  79. package/dist/dataunit/metadata/DataType.js +10 -1
  80. package/dist/dataunit/metadata/DataType.js.map +1 -1
  81. package/dist/dataunit/state/action/DataUnitAction.d.ts +3 -1
  82. package/dist/dataunit/state/action/DataUnitAction.js +2 -0
  83. package/dist/dataunit/state/action/DataUnitAction.js.map +1 -1
  84. package/dist/dataunit/state/slice/ChangesSlice.js +12 -11
  85. package/dist/dataunit/state/slice/ChangesSlice.js.map +1 -1
  86. package/dist/dataunit/state/slice/InvalidFieldsSlice.js +2 -0
  87. package/dist/dataunit/state/slice/InvalidFieldsSlice.js.map +1 -1
  88. package/dist/dataunit/state/slice/LoadingProperties.d.ts +9 -0
  89. package/dist/dataunit/state/slice/LoadingProperties.js +31 -0
  90. package/dist/dataunit/state/slice/LoadingProperties.js.map +1 -0
  91. package/dist/dataunit/state/slice/SelectionSlice.js +3 -2
  92. package/dist/dataunit/state/slice/SelectionSlice.js.map +1 -1
  93. package/dist/index.d.ts +3 -1
  94. package/dist/index.js +3 -1
  95. package/dist/index.js.map +1 -1
  96. package/dist/utils/ArrayUtils.d.ts +39 -0
  97. package/dist/utils/ArrayUtils.js +69 -0
  98. package/dist/utils/ArrayUtils.js.map +1 -1
  99. package/dist/utils/DateUtils.js +4 -0
  100. package/dist/utils/DateUtils.js.map +1 -1
  101. package/dist/utils/JSUtils.d.ts +7 -0
  102. package/dist/utils/JSUtils.js +16 -0
  103. package/dist/utils/JSUtils.js.map +1 -1
  104. package/dist/utils/ObjectUtils.d.ts +8 -0
  105. package/dist/utils/ObjectUtils.js +10 -0
  106. package/dist/utils/ObjectUtils.js.map +1 -1
  107. package/dist/utils/OverflowWatcher/index.d.ts +31 -0
  108. package/dist/utils/OverflowWatcher/index.js +107 -0
  109. package/dist/utils/OverflowWatcher/index.js.map +1 -0
  110. package/dist/utils/OverflowWatcher/types/overflow-callback.d.ts +6 -0
  111. package/dist/utils/OverflowWatcher/types/overflow-callback.js +2 -0
  112. package/dist/utils/OverflowWatcher/types/overflow-callback.js.map +1 -0
  113. package/dist/utils/OverflowWatcher/types/overflow-direction.d.ts +7 -0
  114. package/dist/utils/OverflowWatcher/types/overflow-direction.js +9 -0
  115. package/dist/utils/OverflowWatcher/types/overflow-direction.js.map +1 -0
  116. package/dist/utils/SearchUtils.d.ts +6 -0
  117. package/dist/utils/SearchUtils.js +17 -0
  118. package/dist/utils/SearchUtils.js.map +1 -0
  119. package/dist/utils/StringUtils.d.ts +7 -0
  120. package/dist/utils/StringUtils.js +97 -0
  121. package/dist/utils/StringUtils.js.map +1 -1
  122. package/jest.config.ts +1 -1
  123. package/package.json +11 -4
  124. package/sonar-project.properties +7 -0
  125. package/src/dataunit/DataUnit.ts +57 -10
  126. package/src/dataunit/formatting/PrettyFormatter.ts +8 -5
  127. package/src/dataunit/metadata/DataType.ts +10 -1
  128. package/src/dataunit/state/action/DataUnitAction.ts +3 -1
  129. package/src/dataunit/state/slice/ChangesSlice.ts +15 -14
  130. package/src/dataunit/state/slice/InvalidFieldsSlice.ts +2 -0
  131. package/src/dataunit/state/slice/LoadingProperties.ts +37 -0
  132. package/src/dataunit/state/slice/SelectionSlice.ts +3 -2
  133. package/src/index.ts +6 -0
  134. package/src/utils/ArrayUtils.ts +73 -0
  135. package/src/utils/DateUtils.ts +2 -0
  136. package/src/utils/JSUtils.ts +18 -0
  137. package/src/utils/ObjectUtils.ts +11 -0
  138. package/src/utils/OverflowWatcher/index.ts +151 -0
  139. package/src/utils/OverflowWatcher/types/overflow-callback.ts +6 -0
  140. package/src/utils/OverflowWatcher/types/overflow-direction.ts +7 -0
  141. package/src/utils/SearchUtils.ts +18 -0
  142. package/src/utils/StringUtils.ts +124 -0
  143. package/test/util/OverflowWatcher.spec.ts +118 -0
  144. package/.docs/.nojekyll +0 -1
  145. package/.docs/enums/Action.md +0 -305
  146. package/.docs/enums/ChangeOperation.md +0 -52
  147. package/.docs/enums/DataType.md +0 -63
  148. package/.docs/enums/DependencyType.md +0 -41
  149. package/.docs/enums/SelectionMode.md +0 -30
  150. package/.docs/enums/SortMode.md +0 -30
  151. package/.docs/enums/UserInterface.md +0 -195
  152. package/.docs/modules/MaskFormatter.md +0 -37
@@ -0,0 +1,151 @@
1
+ import { JSUtils } from "../JSUtils.js";
2
+ import { OverflowDirection } from "./types/overflow-direction.js"
3
+ import { OnOverflowCallBack } from "./types/overflow-callback.js"
4
+
5
+ export * from "./types/overflow-direction.js";
6
+ export * from "./types/overflow-callback.js";
7
+
8
+ export default class OverflowWatcher {
9
+ private _onResize:OnOverflowCallBack;
10
+ private _resizeObserver:ResizeObserver;
11
+ private _lastContentRect:DOMRectReadOnly|undefined = undefined;
12
+ private _scrollDirection = OverflowDirection.HORIZONTAL;
13
+ private _propSize:string;
14
+ private _hiddenItems:Element[] = [];
15
+ private _deltaSize:number;
16
+
17
+ /**
18
+ * Cria uma instancia do OverflowWatcher
19
+ *
20
+ * @param element - Elemento HTML que o overflow será observado.
21
+ * @param callback - Função que sera chamada quando ocorrer overflow no elemento.
22
+ * @param overFlowDirection - Indica direção que o overflow será monitorado.
23
+ * @param deltaSize - Variação de tamanho que será considerada como overflow.
24
+ */
25
+ constructor(element:HTMLElement,
26
+ callback:OnOverflowCallBack,
27
+ overFlowDirection:OverflowDirection = OverflowDirection.HORIZONTAL,
28
+ deltaSize:number = 10){
29
+ this._onResize = callback;
30
+ this._scrollDirection = overFlowDirection;
31
+ this._resizeObserver = new ResizeObserver(JSUtils.debounce((entries: ResizeObserverEntry[]) => this.handleResize(entries), 200));
32
+ this._resizeObserver.observe(element);
33
+ this._propSize = this.getPropSizeByDirection();
34
+ this._deltaSize = deltaSize;
35
+ }
36
+
37
+ public destroy(){
38
+ this._resizeObserver.disconnect();
39
+ }
40
+
41
+ private handleResize(entries: ResizeObserverEntry[]){
42
+
43
+ if(!entries || entries.length === 0){
44
+ return;
45
+ }
46
+
47
+ const resizeItem = entries[0];
48
+ const contentRect:any = resizeItem.contentRect;
49
+
50
+ if(this.isChangedSize(contentRect)){
51
+ const children:Element[] = Array.from(resizeItem.target.children);
52
+ this.proccessElements(contentRect[this._propSize], children);
53
+ this._lastContentRect = contentRect;
54
+ }
55
+ }
56
+
57
+ private isChangedSize(newContentRect:DOMRectReadOnly):boolean{
58
+ if(this._lastContentRect == undefined){
59
+ return true;
60
+ }
61
+ return Math.abs((newContentRect as any)[this._propSize] - (this._lastContentRect as any)[this._propSize]) >= this._deltaSize;
62
+ }
63
+
64
+
65
+ private getPropSizeByDirection():string{
66
+ if(OverflowDirection.HORIZONTAL === this._scrollDirection){
67
+ return "width"
68
+ }
69
+
70
+ return "height";
71
+ }
72
+
73
+ private proccessElements(elementSize:number, children:Element[]){
74
+
75
+ if(children.length === 0){
76
+ return;
77
+ }
78
+
79
+ const childrenSize = this.calcChildrenSize(children);
80
+
81
+ let diff = Number((elementSize - childrenSize).toFixed(4));
82
+
83
+ if(diff > 0){
84
+ this.proccessElementsWithoutOverFlow(diff);
85
+ return;
86
+ }
87
+
88
+ this.proccessElementsOverFlow(children, diff);
89
+ }
90
+
91
+ private proccessElementsWithoutOverFlow(diff:number){
92
+ this._hiddenItems.forEach((item:any) => {
93
+
94
+ if(item.getBoundingClientRect().width < diff){
95
+ this._hiddenItems.pop();
96
+ }
97
+
98
+ });
99
+
100
+ this._onResize(this._hiddenItems);
101
+ }
102
+
103
+ private proccessElementsOverFlow(children:Element[], diff:number){
104
+ const elementsOverflow = [];
105
+ let sumRemovedItems = 0;
106
+
107
+ while(elementsOverflow.length < children.length && sumRemovedItems < (diff * -1) ) {
108
+ const itemToRemove = children.pop();
109
+
110
+ if(itemToRemove != undefined && (itemToRemove as any).style.display === 'none'){
111
+ continue;
112
+ }
113
+
114
+ if(itemToRemove != undefined){
115
+ elementsOverflow.push(itemToRemove);
116
+ sumRemovedItems += (itemToRemove.getBoundingClientRect() as any)[this._propSize];
117
+ }
118
+ }
119
+
120
+
121
+ this._hiddenItems = elementsOverflow;
122
+ this._onResize(elementsOverflow);
123
+
124
+ }
125
+
126
+ private calcChildrenSize(children:Element[]):number{
127
+ let sumChildren = 0;
128
+
129
+ Array.from(children).forEach(el => {
130
+ sumChildren += (el.getBoundingClientRect() as any)[this._propSize];
131
+ sumChildren += this.calcMarginSize(el);
132
+ });
133
+
134
+ if(sumChildren > 0){
135
+ sumChildren += this._deltaSize;
136
+ }
137
+
138
+ return sumChildren;
139
+ }
140
+
141
+ private calcMarginSize(el:Element){
142
+ const computedStyle = getComputedStyle(el);
143
+
144
+ if(OverflowDirection.HORIZONTAL === this._scrollDirection){
145
+ return (parseInt(computedStyle.marginLeft || '0') + parseInt(computedStyle.marginRight || '0'));
146
+ }
147
+
148
+ return (parseInt(computedStyle.marginTop || '0') + parseInt(computedStyle.marginBottom || '0'));
149
+ }
150
+
151
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Callback que será chamado quando o overflow de um elemento for alterado.
3
+ *
4
+ * @param elementsOverFlow - Conjunto de elementos filhos que estão causando overflow no elemento pai.
5
+ */
6
+ export type OnOverflowCallBack = (elementsOverFlow:Array<Element>) => void;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Define em qual direção o overflow será observado
3
+ */
4
+ export enum OverflowDirection {
5
+ 'VERTICAL',
6
+ 'HORIZONTAL'
7
+ }
@@ -0,0 +1,18 @@
1
+ import { StringUtils } from "./StringUtils.js";
2
+
3
+ /**
4
+ * `Search`: Utilizado para manipulação de do objeto de pesquisa.
5
+ */
6
+ export class SearchUtils {
7
+
8
+ public static buildDetails(argument: String, fields: any, item: any) {
9
+ let details:any = {};
10
+ for (let index = 0; (index < fields.length); index++) {
11
+ const field = fields[index];
12
+ const itemValue = item[field.fieldName];
13
+ const optionValue = field.options ? field.options[itemValue] || itemValue : itemValue;
14
+ details[field.description] = StringUtils.highlightValue(argument, item['__matchFields'], optionValue, fields, true);
15
+ }
16
+ return details;
17
+ }
18
+ }
@@ -1,4 +1,6 @@
1
1
  import { v4 as uuid } from "uuid";
2
+ import ArrayUtils from "./ArrayUtils.js";
3
+ import { JSUtils } from "./JSUtils.js";
2
4
 
3
5
  /**
4
6
  * `StringUtils`: Utilizado para manipulação de Strings.
@@ -414,4 +416,126 @@ export class StringUtils {
414
416
  static getOppositeCase(original: string): string {
415
417
  return this.isLowerCase(original) ? original.toUpperCase() : original.toLowerCase()
416
418
  }
419
+
420
+ public static replaceToSpace(source: string, replaceList: string[] = []) {
421
+ if (source == undefined) {
422
+ return source;
423
+ }
424
+
425
+ replaceList.forEach((word: string) => {
426
+ const wordAux = new RegExp(word, 'g');
427
+ let whiteSpace = '';
428
+ for (let i = 0; i < word.length; i++) {
429
+ whiteSpace += ' ';
430
+ }
431
+ source = String(source).replace(wordAux, whiteSpace);
432
+ });
433
+
434
+ return source;
435
+ }
436
+
437
+ public static replaceAccentuatedCharsHtmlEntities(source: string) {
438
+ const charsWithoutAccentuation = "AEIOU_AO_AEIOU_AEIOU_U_C_aeiou_ao_aeiou_aeiou_u_c";
439
+ if (source == undefined) {
440
+ return source;
441
+ }
442
+
443
+ const replaceList = ['&amp;', '&lt;', '&gt;', '&quot;'];
444
+ const sourceAux = StringUtils.replaceToSpace(source, replaceList);
445
+
446
+ return sourceAux.replace(/[^\w ]/g, (char: string) => {
447
+ let index = charsWithoutAccentuation.indexOf(char);
448
+
449
+ if (index > -1) {
450
+ char = charsWithoutAccentuation.charAt(index);
451
+ }
452
+
453
+ return char || '';
454
+ });
455
+ }
456
+
457
+ public static getSpecialCharacters(str: string) {
458
+ const specialCharsRegex = /[[.\-\$\+\*,_\&\(\)%\/\\#@!:\|\=\'\"]/gmi;
459
+ let match: any;
460
+ let charList = [];
461
+ while ((match = specialCharsRegex.exec(str))) {
462
+ charList.push(str[match.index]);
463
+ }
464
+ return charList;
465
+ }
466
+
467
+ public static replaceAll(str: string, strFrom: string, strTo: string) {
468
+ let pos = (str != undefined ? str : '').indexOf(strFrom);
469
+ while (pos > -1) {
470
+ str = str.replace(strFrom, strTo);
471
+ pos = str.indexOf(strFrom);
472
+ }
473
+ return (str);
474
+ }
475
+
476
+ public static removeSpecialCharacters(str: string) {
477
+ let specialChars = StringUtils.getSpecialCharacters(str);
478
+ specialChars.forEach((ch: string) => {
479
+ str = StringUtils.replaceAll(str, ch, '');
480
+ });
481
+
482
+ return str;
483
+ }
484
+
485
+ public static getArgumentNumber(argument: String) {
486
+ return Number(argument || undefined);
487
+ }
488
+
489
+ public static highlightValue(argument: String, matchFields: any, value: string, fieldMD: any, forceMatch: boolean) {
490
+ const startHighlightTag = "<span class='card-item__highlight'>";
491
+ const endHighlightTag = "</span>";
492
+ let valueAux = JSUtils.replaceHtmlEntities(value);
493
+
494
+ if (argument && (forceMatch || ArrayUtils.isIn(matchFields, fieldMD.fieldName))) {
495
+ const argumentNumber = StringUtils.getArgumentNumber(argument);
496
+
497
+ let replacements = (isNaN(argumentNumber) ? argument : argumentNumber.toString()).split(/%|,|\s+/);
498
+ let lastMatchIndex = 0;
499
+ let cleanText = StringUtils.replaceAccentuatedCharsHtmlEntities(valueAux);
500
+
501
+ replacements.forEach((r: string) => {
502
+ if (r) {
503
+ r = StringUtils.replaceAccentuatedCharsHtmlEntities(r);
504
+
505
+ let specialChars = StringUtils.getSpecialCharacters(r);
506
+
507
+ if (specialChars != undefined && specialChars.length > 0) {
508
+ r = StringUtils.removeSpecialCharacters(r);
509
+ }
510
+
511
+ if (fieldMD.mask || fieldMD.uiType === 'CGC_CPF' || fieldMD.uiType === 'Phone') {
512
+ //Fazemos isso para descondirerar os caracteres especiais de formatação da string
513
+ r = r.split('').join('\\.?\\-?\\/?\\(?\\)?');
514
+ }
515
+
516
+ let regex = new RegExp(r, "ig");
517
+ regex.lastIndex = lastMatchIndex;
518
+ let match = regex.exec(cleanText);
519
+
520
+ if (match && match.length > 0) {
521
+ lastMatchIndex = match.index;
522
+ let sizeMatch = match[0].length;
523
+
524
+ let txtToColor = valueAux.substring(lastMatchIndex, lastMatchIndex + sizeMatch);
525
+ let txtColored = txtToColor?.trim() ? startHighlightTag + txtToColor + endHighlightTag : '';
526
+
527
+ let start = valueAux.substring(0, lastMatchIndex);
528
+ let end = valueAux.substring(lastMatchIndex + sizeMatch);
529
+
530
+ valueAux = start + txtColored + end;
531
+ lastMatchIndex = lastMatchIndex + txtColored.length;
532
+
533
+ cleanText = StringUtils.replaceAccentuatedCharsHtmlEntities(valueAux);
534
+ }
535
+ }
536
+ });
537
+ }
538
+
539
+ return valueAux;
540
+ }
417
541
  }
@@ -0,0 +1,118 @@
1
+ import OverFlowWatcher, { OnOverflowCallBack, OverflowDirection } from '../../src/utils/OverflowWatcher';
2
+
3
+ describe('OverflowWatcher', function () {
4
+
5
+ let element: HTMLElement;
6
+ let callbackHorizontalDirection: OnOverflowCallBack;
7
+ let watcherHorizontalDirection: OverFlowWatcher;
8
+ let callbackVerticalDirection: OnOverflowCallBack;
9
+ let watcherVerticallDirection: OverFlowWatcher;
10
+ let child1:HTMLDivElement;
11
+ let child2:HTMLDivElement;
12
+
13
+ beforeEach(() => {
14
+
15
+ global.ResizeObserver = jest.fn().mockImplementation(() => ({
16
+ observe: jest.fn(),
17
+ unobserve: jest.fn(),
18
+ disconnect: jest.fn(),
19
+ }))
20
+
21
+ element = document.createElement('div');
22
+
23
+ //Horizontal
24
+ callbackHorizontalDirection = jest.fn();
25
+ watcherHorizontalDirection = new OverFlowWatcher(element, callbackHorizontalDirection);
26
+
27
+
28
+ //Vertical
29
+ callbackVerticalDirection = jest.fn();
30
+ watcherVerticallDirection = new OverFlowWatcher(element, callbackVerticalDirection, OverflowDirection.VERTICAL);
31
+
32
+ child1 = document.createElement('div');
33
+ child2 = document.createElement('div');
34
+
35
+ child1.style.width = '50px';
36
+ child2.style.width = '100px';
37
+ child1.style.height = '50px';
38
+ child2.style.height = '100px';
39
+
40
+ //TODO: No futuro utilizar JSDOM para não precisar fazer mock dessas coisas
41
+ child1['getBoundingClientRect'] = () => {
42
+ return {
43
+ width: 50,
44
+ height: 50,
45
+ } as DOMRect;
46
+ }
47
+
48
+ child2['getBoundingClientRect'] = () => {
49
+ return {
50
+ width: 100,
51
+ height: 100,
52
+ } as DOMRect;
53
+ }
54
+
55
+ element.appendChild(child1);
56
+ element.appendChild(child2);
57
+ });
58
+
59
+ afterEach(() => {
60
+ watcherHorizontalDirection.destroy();
61
+ watcherVerticallDirection.destroy();
62
+ });
63
+
64
+ test('constructor initializes properties correctly', () => {
65
+ expect(watcherHorizontalDirection['_onResize']).toBe(callbackHorizontalDirection);
66
+ expect(watcherHorizontalDirection['_scrollDirection']).toBe(OverflowDirection.HORIZONTAL);
67
+ expect(watcherHorizontalDirection['_deltaSize']).toBe(10);
68
+ });
69
+
70
+ test('handleResize horizontal calls callback with hidden items', () => {
71
+ const entries: any[] = [{
72
+ contentRect: {
73
+ width: 120
74
+ },
75
+ target: element
76
+ }];
77
+
78
+ watcherHorizontalDirection['handleResize'](entries);
79
+
80
+ expect(callbackHorizontalDirection).toHaveBeenCalledWith([child2]);
81
+
82
+ entries[0].contentRect.width = 100;
83
+ watcherHorizontalDirection['handleResize'](entries);
84
+
85
+ expect(callbackHorizontalDirection).toHaveBeenCalledWith([child2]);
86
+ });
87
+
88
+ test('handleResize vertical calls callback with hidden items', () => {
89
+ const entries: any[] = [{
90
+ contentRect: {
91
+ height: 120
92
+ },
93
+ target: element
94
+ }];
95
+
96
+ watcherVerticallDirection['handleResize'](entries);
97
+
98
+ expect(callbackVerticalDirection).toHaveBeenCalledWith([child2]);
99
+ });
100
+
101
+ test('isChangedSize returns true if no previous size', () => {
102
+ const newContentRect: DOMRectReadOnly = { width: 100 } as DOMRectReadOnly;
103
+ watcherHorizontalDirection['_lastContentRect'] = undefined;
104
+
105
+ const result = watcherHorizontalDirection['isChangedSize'](newContentRect);
106
+
107
+ expect(result).toBe(true);
108
+ });
109
+
110
+ test('prevent resize without entries', () => {
111
+ const entries: any[] = [];
112
+
113
+ watcherHorizontalDirection['handleResize'](entries);
114
+
115
+ expect(callbackHorizontalDirection).toHaveBeenCalledTimes(0);
116
+ });
117
+
118
+ });
package/.docs/.nojekyll DELETED
@@ -1 +0,0 @@
1
- TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.