@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.
- package/.docs/classes/Base64Utils.md +39 -0
- package/.docs/classes/Change.md +11 -11
- package/.docs/classes/ColumnFilterManager.md +145 -0
- package/.docs/classes/DataUnit.md +429 -139
- package/.docs/classes/DataUnitInMemoryLoader.md +303 -0
- package/.docs/classes/DataUnitLoaderUtils.md +151 -0
- package/.docs/classes/DateUtils.md +8 -8
- package/.docs/classes/FieldComparator.md +2 -2
- package/.docs/classes/IDBRepository.md +22 -0
- package/.docs/classes/LockManager.md +249 -0
- package/.docs/classes/MaskFormatter.md +66 -14
- package/.docs/classes/ObjectUtils.md +141 -0
- package/.docs/classes/OverflowWatcher.md +310 -46
- package/.docs/classes/SelectionInfo.md +25 -11
- package/.docs/classes/ServiceCanceledException.md +193 -0
- package/.docs/classes/ServiceUtils.md +67 -0
- package/.docs/classes/SilentException.md +193 -0
- package/.docs/classes/StringUtils.md +24 -0
- package/.docs/classes/UserAgentUtils.md +15 -1
- package/.docs/enumerations/Action.md +41 -21
- package/.docs/enumerations/ChangeOperation.md +4 -4
- package/.docs/enumerations/LockManagerOperation.md +33 -0
- package/.docs/enumerations/RECORD_DATE_FORMAT.md +27 -0
- package/.docs/enumerations/SelectionMode.md +2 -2
- package/.docs/enumerations/StorageType.md +37 -0
- package/.docs/globals.md +19 -0
- package/.docs/interfaces/DUActionInterceptor.md +1 -1
- package/.docs/interfaces/DataUnitInMemoryLoaderConfig.md +37 -0
- package/.docs/interfaces/IRepository.md +18 -0
- package/.docs/interfaces/LoadDataRequest.md +1 -1
- package/.docs/interfaces/OverFlowWatcherParams.md +67 -0
- package/.docs/interfaces/PageRequest.md +3 -3
- package/.docs/interfaces/PaginationInfo.md +25 -0
- package/.docs/interfaces/PaginationInfoBuilderParams.md +37 -0
- package/.docs/interfaces/QuickFilter.md +3 -3
- package/.docs/interfaces/Record.md +4 -4
- package/.docs/interfaces/SavedRecord.md +5 -5
- package/.docs/interfaces/WaitingChange.md +3 -3
- package/.docs/namespaces/MaskFormatter/type-aliases/MaskCharacter.md +1 -1
- package/.docs/namespaces/MaskFormatter/variables/MaskCharacter.md +1 -1
- package/.docs/type-aliases/DataUnitEventOptions.md +17 -0
- package/.docs/variables/OVERFLOWED_CLASS_NAME.md +13 -0
- package/.releaserc +1 -0
- package/bun.lockb +0 -0
- package/dist/dataunit/DataUnit.d.ts +92 -13
- package/dist/dataunit/DataUnit.js +219 -71
- package/dist/dataunit/DataUnit.js.map +1 -1
- package/dist/dataunit/DataUnitHelper.js +6 -5
- package/dist/dataunit/DataUnitHelper.js.map +1 -1
- package/dist/dataunit/formatting/PrettyFormatter.js +14 -6
- package/dist/dataunit/formatting/PrettyFormatter.js.map +1 -1
- package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.d.ts +9 -0
- package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.js +6 -0
- package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.js.map +1 -0
- package/dist/dataunit/loader/dataUnitInMemoryLoader.d.ts +25 -0
- package/dist/dataunit/loader/dataUnitInMemoryLoader.js +131 -0
- package/dist/dataunit/loader/dataUnitInMemoryLoader.js.map +1 -0
- package/dist/dataunit/loader/utils/dataUnitLoaderUtils.d.ts +20 -0
- package/dist/dataunit/loader/utils/dataUnitLoaderUtils.js +62 -0
- package/dist/dataunit/loader/utils/dataUnitLoaderUtils.js.map +1 -0
- package/dist/dataunit/loading/LoadDataRequest.d.ts +1 -1
- package/dist/dataunit/loading/PaginationInfo.d.ts +8 -0
- package/dist/dataunit/metadata/DataType.js +3 -0
- package/dist/dataunit/metadata/DataType.js.map +1 -1
- package/dist/dataunit/sorting/FieldComparator.d.ts +2 -2
- package/dist/dataunit/sorting/FieldComparator.js +4 -9
- package/dist/dataunit/sorting/FieldComparator.js.map +1 -1
- package/dist/dataunit/state/action/DataUnitAction.d.ts +2 -0
- package/dist/dataunit/state/action/DataUnitAction.js +2 -0
- package/dist/dataunit/state/action/DataUnitAction.js.map +1 -1
- package/dist/dataunit/state/slice/LoadingControlSlice.js +16 -0
- package/dist/dataunit/state/slice/LoadingControlSlice.js.map +1 -1
- package/dist/dataunit/state/slice/RecordsSlice.js +1 -1
- package/dist/dataunit/state/slice/RecordsSlice.js.map +1 -1
- package/dist/dataunit/state/slice/SelectionSlice.js +4 -4
- package/dist/dataunit/state/slice/SelectionSlice.js.map +1 -1
- package/dist/exceptions/ServiceCanceledException.d.ts +14 -0
- package/dist/exceptions/ServiceCanceledException.js +13 -0
- package/dist/exceptions/ServiceCanceledException.js.map +1 -0
- package/dist/exceptions/SilentException.d.ts +14 -0
- package/dist/exceptions/SilentException.js +13 -0
- package/dist/exceptions/SilentException.js.map +1 -0
- package/dist/index.d.ts +13 -3
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/repository/IRepository.d.ts +6 -0
- package/dist/repository/indexeddb/IDBRepository.d.ts +1 -0
- package/dist/repository/indexeddb/IDBRepository.js +3 -0
- package/dist/repository/indexeddb/IDBRepository.js.map +1 -1
- package/dist/utils/Base64Utils.d.ts +7 -0
- package/dist/utils/Base64Utils.js +13 -0
- package/dist/utils/Base64Utils.js.map +1 -0
- package/dist/utils/CacheManager/index.d.ts +52 -0
- package/dist/utils/CacheManager/index.js +101 -0
- package/dist/utils/CacheManager/index.js.map +1 -0
- package/dist/utils/CacheManager/interfaces/index.d.ts +5 -0
- package/dist/utils/CacheManager/interfaces/index.js +7 -0
- package/dist/utils/CacheManager/interfaces/index.js.map +1 -0
- package/dist/utils/ColumnFilterManager.d.ts +19 -0
- package/dist/utils/ColumnFilterManager.js +73 -0
- package/dist/utils/ColumnFilterManager.js.map +1 -0
- package/dist/utils/DateUtils.js +3 -0
- package/dist/utils/DateUtils.js.map +1 -1
- package/dist/utils/ElementUtils.d.ts +2 -0
- package/dist/utils/ElementUtils.js +9 -0
- package/dist/utils/ElementUtils.js.map +1 -0
- package/dist/utils/LockManager.d.ts +58 -0
- package/dist/utils/LockManager.js +188 -0
- package/dist/utils/LockManager.js.map +1 -0
- package/dist/utils/MaskFormatter.d.ts +16 -1
- package/dist/utils/MaskFormatter.js +82 -2
- package/dist/utils/MaskFormatter.js.map +1 -1
- package/dist/utils/ObjectUtils.d.ts +38 -0
- package/dist/utils/ObjectUtils.js +51 -0
- package/dist/utils/ObjectUtils.js.map +1 -1
- package/dist/utils/OnboardingUtils.js +1 -1
- package/dist/utils/OnboardingUtils.js.map +1 -1
- package/dist/utils/OverflowWatcher/index.d.ts +35 -7
- package/dist/utils/OverflowWatcher/index.js +140 -59
- package/dist/utils/OverflowWatcher/index.js.map +1 -1
- package/dist/utils/ServiceUtils.d.ts +24 -0
- package/dist/utils/ServiceUtils.js +40 -0
- package/dist/utils/ServiceUtils.js.map +1 -0
- package/dist/utils/SortingUtils.d.ts +9 -0
- package/dist/utils/SortingUtils.js +24 -0
- package/dist/utils/SortingUtils.js.map +1 -0
- package/dist/utils/StringUtils.d.ts +6 -0
- package/dist/utils/StringUtils.js +11 -0
- package/dist/utils/StringUtils.js.map +1 -1
- package/dist/utils/UserAgentUtils/index.d.ts +1 -0
- package/dist/utils/UserAgentUtils/index.js +5 -0
- package/dist/utils/UserAgentUtils/index.js.map +1 -1
- package/jest.config.ts +2 -0
- package/package.json +2 -1
- package/reports/test-report.xml +215 -0
- package/setupTests.js +7 -0
- package/sonar-project.properties +6 -3
- package/src/dataunit/DataUnit.ts +268 -86
- package/src/dataunit/DataUnitHelper.ts +6 -5
- package/src/dataunit/formatting/PrettyFormatter.ts +15 -6
- package/src/dataunit/loader/DataUnitInMemoryLoaderConfig.ts +10 -0
- package/src/dataunit/loader/dataUnitInMemoryLoader.ts +176 -0
- package/src/dataunit/loader/utils/dataUnitLoaderUtils.ts +86 -0
- package/src/dataunit/loading/LoadDataRequest.ts +1 -1
- package/src/dataunit/loading/PaginationInfo.ts +10 -0
- package/src/dataunit/metadata/DataType.ts +3 -0
- package/src/dataunit/sorting/FieldComparator.ts +18 -32
- package/src/dataunit/state/action/DataUnitAction.ts +2 -0
- package/src/dataunit/state/slice/LoadingControlSlice.ts +42 -0
- package/src/dataunit/state/slice/RecordsSlice.ts +1 -1
- package/src/dataunit/state/slice/SelectionSlice.ts +4 -4
- package/src/dataunit/state/slice/test/RecordsSlice.spec.ts +45 -0
- package/src/dataunit/test/DataUnit.spec.ts +44 -0
- package/src/exceptions/ServiceCanceledException.ts +25 -0
- package/src/exceptions/SilentException.ts +25 -0
- package/src/index.ts +30 -3
- package/src/repository/IRepository.ts +7 -0
- package/src/repository/indexeddb/IDBRepository.ts +4 -0
- package/src/utils/Base64Utils.ts +13 -0
- package/src/utils/CacheManager/index.ts +103 -0
- package/src/utils/CacheManager/interfaces/index.ts +5 -0
- package/src/utils/ColumnFilterManager.ts +104 -0
- package/src/utils/DateUtils.ts +3 -0
- package/src/utils/ElementUtils.ts +10 -0
- package/src/utils/LockManager.ts +208 -0
- package/src/utils/MaskFormatter.ts +93 -2
- package/src/utils/ObjectUtils.ts +56 -0
- package/src/utils/OnboardingUtils.ts +1 -1
- package/src/utils/OverflowWatcher/index.ts +170 -78
- package/src/utils/ServiceUtils.ts +36 -0
- package/src/utils/SortingUtils.ts +30 -0
- package/src/utils/StringUtils.ts +13 -0
- package/src/utils/UserAgentUtils/index.ts +6 -1
- package/src/utils/test/objectUtils.spec.ts +109 -0
- package/test/dataunit/formatting/PrettyFormatter.spec.ts +177 -0
- package/test/dataunit/loader/dataUnitInMemoryLoader.spec.ts +221 -0
- package/test/dataunit/loader/utils/dataUnitLoaderUtils.spec.ts +158 -0
- package/test/util/ColumnFilterManager.spec.ts +133 -0
- package/test/util/ElementUtils.spec.ts +34 -0
- 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
|
|
package/src/utils/ObjectUtils.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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.
|
|
32
|
-
this._resizeObserver.
|
|
33
|
-
this.
|
|
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
|
-
|
|
44
|
-
|
|
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
|
-
|
|
48
|
-
const
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
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
|
|
58
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
return
|
|
104
|
+
if(variation < 0){
|
|
105
|
+
const absoluteVariation = Math.abs(variation);
|
|
106
|
+
return (absoluteVariation > this._deltaSize);
|
|
68
107
|
}
|
|
69
108
|
|
|
70
|
-
return
|
|
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.
|
|
119
|
+
this.clearOverFlow();
|
|
85
120
|
return;
|
|
86
121
|
}
|
|
87
122
|
|
|
88
|
-
this.proccessElementsOverFlow(children,
|
|
123
|
+
this.proccessElementsOverFlow(children, elementSize);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private clearOverFlow(){
|
|
127
|
+
this._hiddenItemsProps = new Map();
|
|
128
|
+
this._onResize([]);
|
|
89
129
|
}
|
|
90
130
|
|
|
91
|
-
private
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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(
|
|
150
|
+
this._onResize(overFlowedElements);
|
|
101
151
|
}
|
|
102
152
|
|
|
103
|
-
private
|
|
104
|
-
|
|
105
|
-
|
|
153
|
+
private isElementOverFlowing(elementsThatFit: Element[], element: Element) {
|
|
154
|
+
return !elementsThatFit.includes(element) && this.canOverFlowElement(element);
|
|
155
|
+
}
|
|
106
156
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
}
|
|
162
|
+
private getDataElementId(element: Element): string {
|
|
163
|
+
return (element as HTMLElement).getAttribute('data-element-id') ?? "";
|
|
164
|
+
}
|
|
119
165
|
|
|
120
|
-
|
|
121
|
-
this.
|
|
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
|
-
|
|
127
|
-
|
|
172
|
+
const variation = this.calculateVariation(elementIdsToCalculate);
|
|
173
|
+
const occupiedSize = sumElementsSize + variation;
|
|
174
|
+
return occupiedSize > avaliableSize;
|
|
175
|
+
}
|
|
128
176
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
135
|
-
|
|
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
|
-
|
|
192
|
+
private registerElementSize(element: Element) {
|
|
193
|
+
const sizeProps = this.getElementSizeProps(element);
|
|
194
|
+
this._hiddenItemsProps.set(element, sizeProps);
|
|
139
195
|
}
|
|
140
196
|
|
|
141
|
-
private
|
|
142
|
-
const
|
|
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
|
-
|
|
145
|
-
|
|
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
|
-
|
|
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
|
+
}
|
package/src/utils/StringUtils.ts
CHANGED
|
@@ -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
|
})
|