@sankhyalabs/core 5.20.0-dev.9 → 5.20.0-ms.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.
Files changed (180) hide show
  1. package/.docs/classes/Base64Utils.md +39 -0
  2. package/.docs/classes/Change.md +11 -11
  3. package/.docs/classes/ColumnFilterManager.md +145 -0
  4. package/.docs/classes/DataUnit.md +429 -139
  5. package/.docs/classes/DataUnitInMemoryLoader.md +303 -0
  6. package/.docs/classes/DataUnitLoaderUtils.md +151 -0
  7. package/.docs/classes/DateUtils.md +8 -8
  8. package/.docs/classes/FieldComparator.md +2 -2
  9. package/.docs/classes/IDBRepository.md +22 -0
  10. package/.docs/classes/LockManager.md +249 -0
  11. package/.docs/classes/MaskFormatter.md +66 -14
  12. package/.docs/classes/ObjectUtils.md +141 -0
  13. package/.docs/classes/OverflowWatcher.md +310 -46
  14. package/.docs/classes/SelectionInfo.md +25 -11
  15. package/.docs/classes/ServiceCanceledException.md +193 -0
  16. package/.docs/classes/ServiceUtils.md +67 -0
  17. package/.docs/classes/SilentException.md +193 -0
  18. package/.docs/classes/StringUtils.md +24 -0
  19. package/.docs/classes/UserAgentUtils.md +15 -1
  20. package/.docs/enumerations/Action.md +41 -21
  21. package/.docs/enumerations/ChangeOperation.md +4 -4
  22. package/.docs/enumerations/LockManagerOperation.md +33 -0
  23. package/.docs/enumerations/RECORD_DATE_FORMAT.md +27 -0
  24. package/.docs/enumerations/SelectionMode.md +2 -2
  25. package/.docs/enumerations/StorageType.md +37 -0
  26. package/.docs/globals.md +19 -0
  27. package/.docs/interfaces/DUActionInterceptor.md +1 -1
  28. package/.docs/interfaces/DataUnitInMemoryLoaderConfig.md +37 -0
  29. package/.docs/interfaces/IRepository.md +18 -0
  30. package/.docs/interfaces/LoadDataRequest.md +1 -1
  31. package/.docs/interfaces/OverFlowWatcherParams.md +67 -0
  32. package/.docs/interfaces/PageRequest.md +3 -3
  33. package/.docs/interfaces/PaginationInfo.md +25 -0
  34. package/.docs/interfaces/PaginationInfoBuilderParams.md +37 -0
  35. package/.docs/interfaces/QuickFilter.md +3 -3
  36. package/.docs/interfaces/Record.md +4 -4
  37. package/.docs/interfaces/SavedRecord.md +5 -5
  38. package/.docs/interfaces/WaitingChange.md +3 -3
  39. package/.docs/namespaces/MaskFormatter/type-aliases/MaskCharacter.md +1 -1
  40. package/.docs/namespaces/MaskFormatter/variables/MaskCharacter.md +1 -1
  41. package/.docs/type-aliases/DataUnitEventOptions.md +17 -0
  42. package/.docs/variables/OVERFLOWED_CLASS_NAME.md +13 -0
  43. package/.releaserc +1 -0
  44. package/bun.lockb +0 -0
  45. package/dist/dataunit/DataUnit.d.ts +92 -13
  46. package/dist/dataunit/DataUnit.js +219 -71
  47. package/dist/dataunit/DataUnit.js.map +1 -1
  48. package/dist/dataunit/DataUnitHelper.js +6 -5
  49. package/dist/dataunit/DataUnitHelper.js.map +1 -1
  50. package/dist/dataunit/formatting/PrettyFormatter.js +14 -6
  51. package/dist/dataunit/formatting/PrettyFormatter.js.map +1 -1
  52. package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.d.ts +9 -0
  53. package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.js +6 -0
  54. package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.js.map +1 -0
  55. package/dist/dataunit/loader/dataUnitInMemoryLoader.d.ts +25 -0
  56. package/dist/dataunit/loader/dataUnitInMemoryLoader.js +131 -0
  57. package/dist/dataunit/loader/dataUnitInMemoryLoader.js.map +1 -0
  58. package/dist/dataunit/loader/utils/dataUnitLoaderUtils.d.ts +20 -0
  59. package/dist/dataunit/loader/utils/dataUnitLoaderUtils.js +62 -0
  60. package/dist/dataunit/loader/utils/dataUnitLoaderUtils.js.map +1 -0
  61. package/dist/dataunit/loading/LoadDataRequest.d.ts +1 -1
  62. package/dist/dataunit/loading/PaginationInfo.d.ts +8 -0
  63. package/dist/dataunit/metadata/DataType.js +3 -0
  64. package/dist/dataunit/metadata/DataType.js.map +1 -1
  65. package/dist/dataunit/sorting/FieldComparator.d.ts +2 -2
  66. package/dist/dataunit/sorting/FieldComparator.js +4 -9
  67. package/dist/dataunit/sorting/FieldComparator.js.map +1 -1
  68. package/dist/dataunit/state/action/DataUnitAction.d.ts +2 -0
  69. package/dist/dataunit/state/action/DataUnitAction.js +2 -0
  70. package/dist/dataunit/state/action/DataUnitAction.js.map +1 -1
  71. package/dist/dataunit/state/slice/LoadingControlSlice.js +16 -0
  72. package/dist/dataunit/state/slice/LoadingControlSlice.js.map +1 -1
  73. package/dist/dataunit/state/slice/RecordsSlice.js +1 -1
  74. package/dist/dataunit/state/slice/RecordsSlice.js.map +1 -1
  75. package/dist/dataunit/state/slice/SelectionSlice.js +4 -4
  76. package/dist/dataunit/state/slice/SelectionSlice.js.map +1 -1
  77. package/dist/exceptions/ServiceCanceledException.d.ts +14 -0
  78. package/dist/exceptions/ServiceCanceledException.js +13 -0
  79. package/dist/exceptions/ServiceCanceledException.js.map +1 -0
  80. package/dist/exceptions/SilentException.d.ts +14 -0
  81. package/dist/exceptions/SilentException.js +13 -0
  82. package/dist/exceptions/SilentException.js.map +1 -0
  83. package/dist/index.d.ts +13 -3
  84. package/dist/index.js +12 -2
  85. package/dist/index.js.map +1 -1
  86. package/dist/repository/IRepository.d.ts +6 -0
  87. package/dist/repository/indexeddb/IDBRepository.d.ts +1 -0
  88. package/dist/repository/indexeddb/IDBRepository.js +3 -0
  89. package/dist/repository/indexeddb/IDBRepository.js.map +1 -1
  90. package/dist/utils/Base64Utils.d.ts +7 -0
  91. package/dist/utils/Base64Utils.js +13 -0
  92. package/dist/utils/Base64Utils.js.map +1 -0
  93. package/dist/utils/CacheManager/index.d.ts +52 -0
  94. package/dist/utils/CacheManager/index.js +101 -0
  95. package/dist/utils/CacheManager/index.js.map +1 -0
  96. package/dist/utils/CacheManager/interfaces/index.d.ts +5 -0
  97. package/dist/utils/CacheManager/interfaces/index.js +7 -0
  98. package/dist/utils/CacheManager/interfaces/index.js.map +1 -0
  99. package/dist/utils/ColumnFilterManager.d.ts +19 -0
  100. package/dist/utils/ColumnFilterManager.js +73 -0
  101. package/dist/utils/ColumnFilterManager.js.map +1 -0
  102. package/dist/utils/DateUtils.js +3 -0
  103. package/dist/utils/DateUtils.js.map +1 -1
  104. package/dist/utils/ElementUtils.d.ts +2 -0
  105. package/dist/utils/ElementUtils.js +9 -0
  106. package/dist/utils/ElementUtils.js.map +1 -0
  107. package/dist/utils/LockManager.d.ts +58 -0
  108. package/dist/utils/LockManager.js +188 -0
  109. package/dist/utils/LockManager.js.map +1 -0
  110. package/dist/utils/MaskFormatter.d.ts +16 -1
  111. package/dist/utils/MaskFormatter.js +82 -2
  112. package/dist/utils/MaskFormatter.js.map +1 -1
  113. package/dist/utils/ObjectUtils.d.ts +38 -0
  114. package/dist/utils/ObjectUtils.js +51 -0
  115. package/dist/utils/ObjectUtils.js.map +1 -1
  116. package/dist/utils/OnboardingUtils.js +1 -1
  117. package/dist/utils/OnboardingUtils.js.map +1 -1
  118. package/dist/utils/OverflowWatcher/index.d.ts +35 -7
  119. package/dist/utils/OverflowWatcher/index.js +140 -59
  120. package/dist/utils/OverflowWatcher/index.js.map +1 -1
  121. package/dist/utils/ServiceUtils.d.ts +24 -0
  122. package/dist/utils/ServiceUtils.js +40 -0
  123. package/dist/utils/ServiceUtils.js.map +1 -0
  124. package/dist/utils/SortingUtils.d.ts +9 -0
  125. package/dist/utils/SortingUtils.js +24 -0
  126. package/dist/utils/SortingUtils.js.map +1 -0
  127. package/dist/utils/StringUtils.d.ts +6 -0
  128. package/dist/utils/StringUtils.js +11 -0
  129. package/dist/utils/StringUtils.js.map +1 -1
  130. package/dist/utils/UserAgentUtils/index.d.ts +1 -0
  131. package/dist/utils/UserAgentUtils/index.js +5 -0
  132. package/dist/utils/UserAgentUtils/index.js.map +1 -1
  133. package/jest.config.ts +2 -0
  134. package/package.json +2 -1
  135. package/reports/test-report.xml +215 -0
  136. package/setupTests.js +7 -0
  137. package/sonar-project.properties +6 -3
  138. package/src/dataunit/DataUnit.ts +268 -86
  139. package/src/dataunit/DataUnitHelper.ts +6 -5
  140. package/src/dataunit/formatting/PrettyFormatter.ts +15 -6
  141. package/src/dataunit/loader/DataUnitInMemoryLoaderConfig.ts +10 -0
  142. package/src/dataunit/loader/dataUnitInMemoryLoader.ts +176 -0
  143. package/src/dataunit/loader/utils/dataUnitLoaderUtils.ts +86 -0
  144. package/src/dataunit/loading/LoadDataRequest.ts +1 -1
  145. package/src/dataunit/loading/PaginationInfo.ts +10 -0
  146. package/src/dataunit/metadata/DataType.ts +3 -0
  147. package/src/dataunit/sorting/FieldComparator.ts +18 -32
  148. package/src/dataunit/state/action/DataUnitAction.ts +2 -0
  149. package/src/dataunit/state/slice/LoadingControlSlice.ts +42 -0
  150. package/src/dataunit/state/slice/RecordsSlice.ts +1 -1
  151. package/src/dataunit/state/slice/SelectionSlice.ts +4 -4
  152. package/src/dataunit/state/slice/test/RecordsSlice.spec.ts +45 -0
  153. package/src/dataunit/test/DataUnit.spec.ts +44 -0
  154. package/src/exceptions/ServiceCanceledException.ts +25 -0
  155. package/src/exceptions/SilentException.ts +25 -0
  156. package/src/index.ts +30 -3
  157. package/src/repository/IRepository.ts +7 -0
  158. package/src/repository/indexeddb/IDBRepository.ts +4 -0
  159. package/src/utils/Base64Utils.ts +13 -0
  160. package/src/utils/CacheManager/index.ts +103 -0
  161. package/src/utils/CacheManager/interfaces/index.ts +5 -0
  162. package/src/utils/ColumnFilterManager.ts +104 -0
  163. package/src/utils/DateUtils.ts +3 -0
  164. package/src/utils/ElementUtils.ts +10 -0
  165. package/src/utils/LockManager.ts +208 -0
  166. package/src/utils/MaskFormatter.ts +93 -2
  167. package/src/utils/ObjectUtils.ts +56 -0
  168. package/src/utils/OnboardingUtils.ts +1 -1
  169. package/src/utils/OverflowWatcher/index.ts +170 -78
  170. package/src/utils/ServiceUtils.ts +36 -0
  171. package/src/utils/SortingUtils.ts +30 -0
  172. package/src/utils/StringUtils.ts +13 -0
  173. package/src/utils/UserAgentUtils/index.ts +6 -1
  174. package/src/utils/test/objectUtils.spec.ts +109 -0
  175. package/test/dataunit/formatting/PrettyFormatter.spec.ts +177 -0
  176. package/test/dataunit/loader/dataUnitInMemoryLoader.spec.ts +221 -0
  177. package/test/dataunit/loader/utils/dataUnitLoaderUtils.spec.ts +158 -0
  178. package/test/util/ColumnFilterManager.spec.ts +133 -0
  179. package/test/util/ElementUtils.spec.ts +34 -0
  180. package/test/util/OverflowWatcher.spec.ts +152 -118
@@ -58,7 +58,8 @@ export class MaskFormatter {
58
58
  "cnpj": "##.###.###/####-##",
59
59
  "cpf": "###.###.###-##",
60
60
  "phone": "(##) ####-####",
61
- "cep": "##.###-###"
61
+ "cep": "##.###-###",
62
+ "cor_rgb" : "'#AAAAAA"
62
63
  };
63
64
 
64
65
 
@@ -92,13 +93,103 @@ export class MaskFormatter {
92
93
  this.mask = mask;
93
94
  }
94
95
 
96
+
97
+ /**
98
+ * Aplica a máscara quando o input é alterado
99
+ *
100
+ * @param value Valor a ser aplicado com a máscara.
101
+ * @return O valor processado de acordo com o padrão.
102
+ */
103
+ public applyMask(value: string) {
104
+ if (this.mask === MaskFormatter.DEFAULT_MASKS.cor_rgb) {
105
+ value = value.replace("#", "")
106
+
107
+ const expectedFormattedValue = this.format(value.replace(/\s/g, ""));
108
+
109
+ if (value === expectedFormattedValue) {
110
+ return value;
111
+ }
112
+
113
+ if (value.length >= 6) {
114
+ const formattedValue = this.format(value);
115
+ return formattedValue;
116
+ } else {
117
+ return value;
118
+ }
119
+ }
120
+
121
+ const expectedFormattedValue = this.format(value.replace(/\s/g, ""));
122
+
123
+ if (value === expectedFormattedValue) {
124
+ return value;
125
+ }
126
+ const maskPlaceholders = this.mask.match(/[UAL#?*']/g) || [];
127
+ const placeholderCount = maskPlaceholders.length;
128
+
129
+ const validValue = value.split('').filter((char, index) => {
130
+ const placeholder = maskPlaceholders[index];
131
+ if (!placeholder) return false;
132
+
133
+ switch (placeholder) {
134
+ case MaskFormatter.DIGIT_KEY:
135
+ return /\d/.test(char);
136
+ case MaskFormatter.UPPERCASE_KEY:
137
+ return /[a-zA-Z]/.test(char);
138
+ case MaskFormatter.LOWERCASE_KEY:
139
+ return /[a-zA-Z]/.test(char);
140
+ case MaskFormatter.ALPHA_NUMERIC_KEY:
141
+ return /[a-zA-Z0-9]/.test(char);
142
+ case MaskFormatter.CHARACTER_KEY:
143
+ return /[a-zA-Z]/.test(char);
144
+ case MaskFormatter.ANYTHING_KEY:
145
+ return true;
146
+ case MaskFormatter.LITERAL_KEY:
147
+ const literalChar = this.mask.charAt(index);
148
+ return char === literalChar;
149
+ default:
150
+ return false;
151
+ }
152
+ });
153
+
154
+ if (validValue.length >= placeholderCount) {
155
+ const formattedValue = this.format(validValue.join(''));
156
+ return formattedValue;
157
+ } else {
158
+ const partialValue = validValue.join('');
159
+ return partialValue;
160
+ }
161
+ }
162
+
163
+ /**
164
+ * Remove a máscara formatando a string retornando sem máscara
165
+ *
166
+ * @param value Valor a ser formatado com máscara.
167
+ * @return O valor processado de acordo com o padrão.
168
+ */
169
+ public removeMask(value: string): string {
170
+ const maskString = this.mask.replace("#", "");
171
+ const maskElements = maskString.split("");
172
+
173
+ let valueMapped = value
174
+
175
+ maskElements.forEach(maskChar => {
176
+ valueMapped = valueMapped.replace(maskChar, "")
177
+ })
178
+
179
+ return valueMapped;
180
+ }
181
+
95
182
  /**
96
183
  * Formata a string passada baseada na máscara definda pelo atributo mask.
97
184
  *
98
185
  * @param value Valor a ser formatado.
186
+ * @param trimBefore Executa um trim para remover espaços em branco.
99
187
  * @return O valor processado de acordo com o padrão.
100
188
  */
101
- public format(value: string): string {
189
+ public format(value: string, trimBefore: boolean = false): string {
190
+ if(trimBefore){
191
+ value = value.trim();
192
+ }
102
193
  let result: string = '';
103
194
  const index: Array<number> = [0];
104
195
 
@@ -84,4 +84,60 @@ export default class ObjectUtils{
84
84
  public static equals(obj1: any, obj2: any): any {
85
85
  return ObjectUtils.objectToString(obj1) === ObjectUtils.objectToString(obj2);
86
86
  }
87
+
88
+ /**
89
+ * Compara se o valor de dois items são equivalentes.
90
+ * Comparando tanto o valor do item em si, quanto sua propriedade "value"
91
+ *
92
+ * @param obj1 - Objeto a ser comparado.
93
+ * @param obj2 - Objeto a ser comparado.
94
+ * @param propToCompare - propriedade que deve ser comparada.
95
+ * @returns - Se o objeto 1 é equivalente ao objeto 2.
96
+ *
97
+ * * @example
98
+ * hasEquivalentProps('123', {value: '123', label: teste}, 'value') | Retorna: true
99
+ * @example
100
+ * hasEquivalentProps('xpto', {value: '123', label: teste}, 'propName') | Retorna: false
101
+ */
102
+ public static hasEquivalentProps(obj1: any, obj2: any, propToCompare:string = "value"): boolean{
103
+ return this.getComparableProp(obj1, propToCompare) == this.getComparableProp(obj2, propToCompare);
104
+ }
105
+
106
+ private static getComparableProp(value: any, propToCompare:string = "value"): boolean{
107
+ if (typeof value === 'object' && value !== null && propToCompare in value) {
108
+ return value[propToCompare];
109
+ }
110
+ return value;
111
+ }
112
+
113
+ /**
114
+ * Verifica se o objeto está vazio (sem atributos).
115
+ *
116
+ * @param obj - Objeto a ser verificado.
117
+ * @returns - True caso o objeto esteja vazio.
118
+ */
119
+ public static isEmpty(obj: object): boolean{
120
+ return Object.keys(obj).length === 0 && obj.constructor === Object;
121
+ }
122
+
123
+ /**
124
+ * Verifica se o objeto NÃO está vazio (sem atributos).
125
+ *
126
+ * @param obj - Objeto a ser verificado.
127
+ * @returns - True caso o objeto NÃO esteja vazio
128
+ */
129
+ public static isNotEmpty(obj: object): boolean{
130
+ return !this.isEmpty(obj);
131
+ }
132
+
133
+ /**
134
+ * Busca a propriedade de um objeto baseado em seu caminho.
135
+ *
136
+ * @param obj - Objeto a ser verificado.
137
+ * @param keyPath - Caminho da propriedade a ser buscada.
138
+ * @returns - O valor da propriedade caso ela exista.
139
+ */
140
+ public static getProp(obj: Record<string, any>, keyPath: string): Record<string, any> | undefined {
141
+ return keyPath.split('.').reduce((previous, current) => previous?.[current], obj);
142
+ }
87
143
  }
@@ -32,7 +32,7 @@ export class OnboardingUtils {
32
32
  }
33
33
 
34
34
  private register(ctx: EnvironmentContext){
35
- (window as any).userGuiding.identify(`${ctx.userID}-${ctx.userName}-${ctx.clientGaId}`, ctx);
35
+ (window as any).userGuiding.identify(`${encodeURIComponent(ctx.userID)}-${encodeURIComponent(ctx.userName)}-${encodeURIComponent(ctx.clientGaId)}`, ctx);
36
36
  }
37
37
  }
38
38
 
@@ -1,151 +1,243 @@
1
1
  import { JSUtils } from "../JSUtils.js";
2
2
  import { OverflowDirection } from "./types/overflow-direction.js"
3
3
  import { OnOverflowCallBack } from "./types/overflow-callback.js"
4
+ import { calcMarginSize } from '../ElementUtils.js';
4
5
 
5
6
  export * from "./types/overflow-direction.js";
6
7
  export * from "./types/overflow-callback.js";
7
8
 
9
+ export const OVERFLOWED_CLASS_NAME = 'overflowed';
10
+
8
11
  export default class OverflowWatcher {
9
12
  private _onResize:OnOverflowCallBack;
10
13
  private _resizeObserver:ResizeObserver;
11
- private _lastContentRect:DOMRectReadOnly|undefined = undefined;
14
+ private _lastContainerSize:number|undefined = undefined;
15
+ private _lastContainerInstance: HTMLElement | undefined = undefined;
12
16
  private _scrollDirection = OverflowDirection.HORIZONTAL;
13
17
  private _propSize:string;
14
- private _hiddenItems:Element[] = [];
18
+ private _hiddenItemsProps:Map<Element, SizeProps> = new Map();
19
+ private _notOverFlowPros:Map<string, SizeProps> = new Map();
15
20
  private _deltaSize:number;
21
+ private _notOverFlow: string[] = [];
22
+
23
+ readonly DATA_ELEMENT_ID = 'data-element-id';
16
24
 
17
25
  /**
18
- * Cria uma instancia do OverflowWatcher
19
- *
26
+ * Cria uma instancia do OverflowWatcher
27
+ *
20
28
  * @param element - Elemento HTML que o overflow será observado.
21
29
  * @param callback - Função que sera chamada quando ocorrer overflow no elemento.
22
30
  * @param overFlowDirection - Indica direção que o overflow será monitorado.
23
31
  * @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){
32
+ * @param debounce - Tempo até execução do callback em milissegundos.
33
+ * @param notOverFlow - Lista de ids ou data-element-ids dos elementos que não devem sofrer overFlow.
34
+ */
35
+ constructor({
36
+ element,
37
+ callback,
38
+ overFlowDirection = OverflowDirection.HORIZONTAL,
39
+ debounce = 200,
40
+ deltaSize = 0,
41
+ notOverFlow = []
42
+ }: OverFlowWatcherParams){
29
43
  this._onResize = callback;
30
44
  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;
45
+ this._propSize = (OverflowDirection.HORIZONTAL === overFlowDirection) ? "width" : "height";
46
+ this._resizeObserver = new ResizeObserver(JSUtils.debounce((entries: ResizeObserverEntry[]) => this.handleResize(entries), debounce));
47
+ this._resizeObserver.observe(element);
48
+ this._deltaSize = deltaSize;
49
+ this._notOverFlow = notOverFlow;
50
+ }
51
+
52
+ public addNotOverFlowElement(elementId: string){
53
+ if(!this._notOverFlow.includes(elementId)){
54
+ this._notOverFlow.push(elementId);
55
+ }
35
56
  }
36
57
 
37
58
  public destroy(){
38
59
  this._resizeObserver.disconnect();
39
60
  }
40
61
 
62
+ public forceUpdate(){
63
+ if(this._lastContainerSize && this._lastContainerInstance){
64
+ this.updateOverFlowedItems(this._lastContainerInstance, this._lastContainerSize);
65
+ }
66
+ }
67
+
41
68
  private handleResize(entries: ResizeObserverEntry[]){
69
+ if(!entries || entries.length === 0) return;
42
70
 
43
- if(!entries || entries.length === 0){
44
- return;
71
+ const container = entries[0];
72
+ const containerSize:number = (container.contentRect as any)[this._propSize];
73
+ if(!containerSize) return;
74
+
75
+ if(this.hasChangedSize(containerSize)){
76
+ this.updateOverFlowedItems(container.target as HTMLElement, containerSize);
45
77
  }
78
+ }
46
79
 
47
- const resizeItem = entries[0];
48
- const contentRect:any = resizeItem.contentRect;
80
+ private updateOverFlowedItems(container: HTMLElement, containerSize: number){
81
+ const children:Element[] = Array.from(container.children);
82
+ this.registerNotOverflowProps(children);
83
+ this.proccessElements(containerSize, children);
84
+ this._lastContainerSize = containerSize;
85
+ this._lastContainerInstance = container;
86
+ }
49
87
 
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
- }
88
+ private registerNotOverflowProps(children: Element[]) {
89
+ children.forEach(childElement => {
90
+ const id = childElement.id || this.getDataElementId(childElement);
91
+ if (this.canNotRegisterNotOverFlow(id)) return;
92
+ this._notOverFlowPros.set(id, this.getElementSizeProps(childElement));
93
+ });
55
94
  }
56
95
 
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;
96
+ private canNotRegisterNotOverFlow(id: string) {
97
+ return !id || !this._notOverFlow.includes(id) || this._notOverFlowPros.has(id);
62
98
  }
63
99
 
100
+ private hasChangedSize(elementSize: number):boolean{
101
+ if(!this._lastContainerSize) return true;
102
+ const variation = elementSize - this._lastContainerSize;
64
103
 
65
- private getPropSizeByDirection():string{
66
- if(OverflowDirection.HORIZONTAL === this._scrollDirection){
67
- return "width"
104
+ if(variation < 0){
105
+ const absoluteVariation = Math.abs(variation);
106
+ return (absoluteVariation > this._deltaSize);
68
107
  }
69
108
 
70
- return "height";
109
+ return variation > 0;
71
110
  }
72
111
 
73
112
  private proccessElements(elementSize:number, children:Element[]){
74
-
75
- if(children.length === 0){
76
- return;
77
- }
113
+ if(children.length === 0) return;
78
114
 
79
115
  const childrenSize = this.calcChildrenSize(children);
80
-
81
116
  let diff = Number((elementSize - childrenSize).toFixed(4));
82
-
117
+
83
118
  if(diff > 0){
84
- this.proccessElementsWithoutOverFlow(diff);
119
+ this.clearOverFlow();
85
120
  return;
86
121
  }
87
122
 
88
- this.proccessElementsOverFlow(children, diff);
123
+ this.proccessElementsOverFlow(children, elementSize);
124
+ }
125
+
126
+ private clearOverFlow(){
127
+ this._hiddenItemsProps = new Map();
128
+ this._onResize([]);
89
129
  }
90
130
 
91
- private proccessElementsWithoutOverFlow(diff:number){
92
- this._hiddenItems.forEach((item:any) => {
93
-
94
- if(item.getBoundingClientRect().width < diff){
95
- this._hiddenItems.pop();
131
+ private proccessElementsOverFlow(allElements:Element[], avaliableSize:number){
132
+ const elementsThatFit: Element[] = [];
133
+ const avaliableSizeConsideringDelta = (avaliableSize - this._deltaSize);
134
+
135
+ let sumElementsSize = 0;
136
+ for (const element of allElements) {
137
+ sumElementsSize += this.calcElementSize(element);
138
+ if(this.exceedsAvaliableSize(sumElementsSize, elementsThatFit, avaliableSizeConsideringDelta)) break;
139
+ elementsThatFit.push(element);
140
+ }
141
+
142
+ const overFlowedElements = allElements.filter(element => this.isElementOverFlowing(elementsThatFit, element));
143
+
144
+ overFlowedElements.forEach(overFlowed => {
145
+ if(!this._hiddenItemsProps.has(overFlowed)){
146
+ this.registerElementSize(overFlowed);
96
147
  }
97
-
98
148
  });
99
149
 
100
- this._onResize(this._hiddenItems);
150
+ this._onResize(overFlowedElements);
101
151
  }
102
152
 
103
- private proccessElementsOverFlow(children:Element[], diff:number){
104
- const elementsOverflow = [];
105
- let sumRemovedItems = 0;
153
+ private isElementOverFlowing(elementsThatFit: Element[], element: Element) {
154
+ return !elementsThatFit.includes(element) && this.canOverFlowElement(element);
155
+ }
106
156
 
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
- }
157
+ private canOverFlowElement(element: Element) {
158
+ return !this._notOverFlow.includes(element.id)
159
+ && !this._notOverFlow.includes(this.getDataElementId(element));
160
+ }
113
161
 
114
- if(itemToRemove != undefined){
115
- elementsOverflow.push(itemToRemove);
116
- sumRemovedItems += (itemToRemove.getBoundingClientRect() as any)[this._propSize];
117
- }
118
- }
162
+ private getDataElementId(element: Element): string {
163
+ return (element as HTMLElement).getAttribute('data-element-id') ?? "";
164
+ }
119
165
 
120
-
121
- this._hiddenItems = elementsOverflow;
122
- this._onResize(elementsOverflow);
166
+ private exceedsAvaliableSize(sumElementsSize: number, elements: Element[], avaliableSize: number): boolean {
167
+ if(!this._notOverFlow.length) return sumElementsSize > avaliableSize
123
168
 
124
- }
169
+ const elementIdsToCalculate = this.canNotOverFlowNotIncludedIds(elements);
170
+ if(!elementIdsToCalculate.length) return sumElementsSize > avaliableSize
125
171
 
126
- private calcChildrenSize(children:Element[]):number{
127
- let sumChildren = 0;
172
+ const variation = this.calculateVariation(elementIdsToCalculate);
173
+ const occupiedSize = sumElementsSize + variation;
174
+ return occupiedSize > avaliableSize;
175
+ }
128
176
 
129
- Array.from(children).forEach(el => {
130
- sumChildren += (el.getBoundingClientRect() as any)[this._propSize];
131
- sumChildren += this.calcMarginSize(el);
177
+ private calculateVariation(elementIdsToCalculate: string[]) {
178
+ let variation = 0
179
+ elementIdsToCalculate.forEach(id => {
180
+ const sizeProps = this._notOverFlowPros.get(id);
181
+ variation += sizeProps?.size ?? 0;
182
+ variation += sizeProps?.margin ?? 0;
132
183
  });
184
+ return variation;
185
+ }
133
186
 
134
- if(sumChildren > 0){
135
- sumChildren += this._deltaSize;
136
- }
187
+ private canNotOverFlowNotIncludedIds(elements: Element[]): string[]{
188
+ const elementsIdList = elements.map(el => el.id || this.getDataElementId(el)).filter(id => !!id);
189
+ return this._notOverFlow.filter(id => !elementsIdList.includes(id));
190
+ }
137
191
 
138
- return sumChildren;
192
+ private registerElementSize(element: Element) {
193
+ const sizeProps = this.getElementSizeProps(element);
194
+ this._hiddenItemsProps.set(element, sizeProps);
139
195
  }
140
196
 
141
- private calcMarginSize(el:Element){
142
- const computedStyle = getComputedStyle(el);
197
+ private getElementSizeProps(element: Element) {
198
+ const sizeProps: SizeProps = {
199
+ size: (element.getBoundingClientRect() as any)[this._propSize],
200
+ margin: calcMarginSize(element, this._scrollDirection),
201
+ };
202
+ return sizeProps;
203
+ }
143
204
 
144
- if(OverflowDirection.HORIZONTAL === this._scrollDirection){
145
- return (parseInt(computedStyle.marginLeft || '0') + parseInt(computedStyle.marginRight || '0'));
205
+ private calcChildrenSize(children:Element[]):number{
206
+ let sumChildren = 0;
207
+ sumChildren += this._deltaSize;
208
+ Array.from(children).forEach(el => sumChildren += this.calcElementSize(el));
209
+ return sumChildren;
210
+ }
211
+
212
+ private calcElementSize(el: Element) {
213
+ let size = 0
214
+ if (this.isOverFlowed(el)) {
215
+ const sizeProps = this._hiddenItemsProps.get(el);
216
+ size += sizeProps?.size ?? 0;
217
+ size += sizeProps?.margin ?? 0;
218
+ return size;
146
219
  }
147
220
 
148
- return (parseInt(computedStyle.marginTop || '0') + parseInt(computedStyle.marginBottom || '0'));
221
+ size += (el.getBoundingClientRect() as any)[this._propSize];
222
+ size += calcMarginSize(el, this._scrollDirection);
223
+ return size;
149
224
  }
150
225
 
226
+ private isOverFlowed(el: Element) {
227
+ return el.classList.contains(OVERFLOWED_CLASS_NAME);
228
+ }
229
+ }
230
+
231
+ export interface OverFlowWatcherParams {
232
+ element:HTMLElement,
233
+ callback:OnOverflowCallBack,
234
+ overFlowDirection?:OverflowDirection,
235
+ deltaSize?:number,
236
+ debounce?: number,
237
+ notOverFlow?: string[]
238
+ }
239
+
240
+ interface SizeProps {
241
+ size: number,
242
+ margin: number,
151
243
  }
@@ -0,0 +1,36 @@
1
+ import { CacheManager } from './CacheManager/index.js';
2
+ import { StorageType } from './CacheManager/interfaces/index.js';
3
+
4
+
5
+ export class ServiceUtils {
6
+
7
+
8
+ /**
9
+ * Auxilia no uso do CacheManager, gerando automaticamente uma chave de cache com base no identificador.
10
+ *
11
+ * @template T Tipo do dado a ser retornado.
12
+ * @param identifier Identificadores únicos usados para compor a chave de cache.
13
+ * @param fetchFunction Função que retorna uma `Promise` com o valor a ser armazenado no cache caso ele não exista ou tenha expirado.
14
+ * @param storageType Tipo de armazenamento: `'sessionStorage'` ou `'localStorage'`. O padrão é `'sessionStorage'`.
15
+ * @returns Uma `Promise` com o valor armazenado ou obtido via `fetchFunction`.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const actions = await useCacheWithService(
20
+ * `${this.entityName} - ${this.resourceID}`,
21
+ * async () => {
22
+ * return await fetchActionsFromAPI();
23
+ * }
24
+ * );
25
+ * console.log(actions);
26
+ * ```
27
+ */
28
+ public static async useCacheWithService<T>(
29
+ identifier: string,
30
+ fetchFunction: () => Promise<T>,
31
+ storageType: StorageType = StorageType.IN_MEMORY_CACHE
32
+ ): Promise<T> {
33
+ const cacheKey = `${identifier}`;
34
+ return CacheManager.getOrSet(cacheKey, fetchFunction, storageType);
35
+ }
36
+ }
@@ -0,0 +1,30 @@
1
+ import DataUnit from "../dataunit/DataUnit.js";
2
+ import { FieldDescriptor, Sort, SortMode } from "../dataunit/metadata/UnitMetadata.js";
3
+ import { FieldComparator } from "../dataunit/sorting/FieldComparator.js";
4
+ import { Record } from '../dataunit/DataUnit.js';
5
+
6
+ /**
7
+ * `SortingUtils`: Utilizado para auxiliar na ordenacao de registros.
8
+ */
9
+ export default class SortingUtils {
10
+
11
+ public static getSortingFunction(dataUnit: DataUnit, sorting?: Array<Sort>): ((recordA: Record, recordB: Record) => number) | undefined {
12
+
13
+ if (sorting == undefined || sorting.length == 0) {
14
+ return undefined;
15
+ }
16
+
17
+ return (recordA, recordB) => {
18
+ for (const sort of sorting) {
19
+ if (sort.field){
20
+ const result = FieldComparator.compare(dataUnit.getField(sort.field) as FieldDescriptor, recordA, recordB, sort.mode === SortMode.ASC);
21
+ if (result != 0) {
22
+ return result;
23
+ }
24
+ }
25
+ }
26
+ return 0;
27
+ };
28
+ }
29
+
30
+ }
@@ -538,4 +538,17 @@ export class StringUtils {
538
538
 
539
539
  return valueAux;
540
540
  }
541
+
542
+
543
+ /**
544
+ * Escapa caracteres especiais em uma string, usando sequencias de escape Unicode.
545
+ * @param str A string que deve sofrer alteração.
546
+ * @returns String com valores alterados.
547
+ */
548
+ public static escapeString(str: string): string {
549
+ // eslint-disable-next-line no-control-regex
550
+ return str.replace(/[\u0000-\u001F\u007F-\uFFFF<>=&"']/g, (char) => {
551
+ return "\\u" + char.charCodeAt(0).toString(16).padStart(4, "0");
552
+ });
553
+ }
541
554
  }
@@ -15,6 +15,11 @@ export class UserAgentUtils {
15
15
  return !!browser.firefox;
16
16
  }
17
17
 
18
+ public static isElectron() {
19
+ const browser = this.getBrowserInfo();
20
+ return !!browser.electron;
21
+ }
22
+
18
23
  /**
19
24
  * Obtém nome e versão do navegador que está sendo utilizado.
20
25
  * @returns Objeto com o nome e versão do navegador.
@@ -40,6 +45,7 @@ export class UserAgentUtils {
40
45
  }
41
46
  } catch (e) {
42
47
  //ignored
48
+ console.warn(e);
43
49
  }
44
50
 
45
51
  browser = {
@@ -49,7 +55,6 @@ export class UserAgentUtils {
49
55
  simpleVersion,
50
56
  ...(Array.isArray(type) ? type.reduce((acc, val) => ({ ...acc, [val]: true}), {}) : { [type]: true })
51
57
  }
52
-
53
58
  return !hasFound;
54
59
  }
55
60
  })