@sankhyalabs/core 5.20.0-dev.7 → 5.20.0-dev.71
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/Change.md +11 -11
- package/.docs/classes/ColumnFilterManager.md +145 -0
- package/.docs/classes/DataUnit.md +405 -137
- 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 +533 -0
- 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/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/OverflowDirection.md +29 -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 +24 -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/type-aliases/OnOverflowCallBack.md +25 -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 +82 -12
- package/dist/dataunit/DataUnit.js +209 -67
- 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/InvalidFieldsSlice.js +2 -0
- package/dist/dataunit/state/slice/InvalidFieldsSlice.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 +12 -2
- package/dist/index.js +11 -1
- 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/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 +191 -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 +59 -0
- package/dist/utils/OverflowWatcher/index.js +188 -0
- package/dist/utils/OverflowWatcher/index.js.map +1 -0
- package/dist/utils/OverflowWatcher/types/overflow-callback.d.ts +6 -0
- package/dist/utils/OverflowWatcher/types/overflow-callback.js +2 -0
- package/dist/utils/OverflowWatcher/types/overflow-callback.js.map +1 -0
- package/dist/utils/OverflowWatcher/types/overflow-direction.d.ts +7 -0
- package/dist/utils/OverflowWatcher/types/overflow-direction.js +9 -0
- package/dist/utils/OverflowWatcher/types/overflow-direction.js.map +1 -0
- 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/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 +250 -82
- 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/InvalidFieldsSlice.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 +29 -1
- package/src/repository/IRepository.ts +7 -0
- package/src/repository/indexeddb/IDBRepository.ts +4 -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 +213 -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 +243 -0
- package/src/utils/OverflowWatcher/types/overflow-callback.ts +6 -0
- package/src/utils/OverflowWatcher/types/overflow-direction.ts +7 -0
- package/src/utils/ServiceUtils.ts +36 -0
- package/src/utils/SortingUtils.ts +30 -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 -0
|
@@ -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
|
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { JSUtils } from "../JSUtils.js";
|
|
2
|
+
import { OverflowDirection } from "./types/overflow-direction.js"
|
|
3
|
+
import { OnOverflowCallBack } from "./types/overflow-callback.js"
|
|
4
|
+
import { calcMarginSize } from '../ElementUtils.js';
|
|
5
|
+
|
|
6
|
+
export * from "./types/overflow-direction.js";
|
|
7
|
+
export * from "./types/overflow-callback.js";
|
|
8
|
+
|
|
9
|
+
export const OVERFLOWED_CLASS_NAME = 'overflowed';
|
|
10
|
+
|
|
11
|
+
export default class OverflowWatcher {
|
|
12
|
+
private _onResize:OnOverflowCallBack;
|
|
13
|
+
private _resizeObserver:ResizeObserver;
|
|
14
|
+
private _lastContainerSize:number|undefined = undefined;
|
|
15
|
+
private _lastContainerInstance: HTMLElement | undefined = undefined;
|
|
16
|
+
private _scrollDirection = OverflowDirection.HORIZONTAL;
|
|
17
|
+
private _propSize:string;
|
|
18
|
+
private _hiddenItemsProps:Map<Element, SizeProps> = new Map();
|
|
19
|
+
private _notOverFlowPros:Map<string, SizeProps> = new Map();
|
|
20
|
+
private _deltaSize:number;
|
|
21
|
+
private _notOverFlow: string[] = [];
|
|
22
|
+
|
|
23
|
+
readonly DATA_ELEMENT_ID = 'data-element-id';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Cria uma instancia do OverflowWatcher
|
|
27
|
+
*
|
|
28
|
+
* @param element - Elemento HTML que o overflow será observado.
|
|
29
|
+
* @param callback - Função que sera chamada quando ocorrer overflow no elemento.
|
|
30
|
+
* @param overFlowDirection - Indica direção que o overflow será monitorado.
|
|
31
|
+
* @param deltaSize - Variação de tamanho que será considerada como overflow.
|
|
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){
|
|
43
|
+
this._onResize = callback;
|
|
44
|
+
this._scrollDirection = overFlowDirection;
|
|
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
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public destroy(){
|
|
59
|
+
this._resizeObserver.disconnect();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public forceUpdate(){
|
|
63
|
+
if(this._lastContainerSize && this._lastContainerInstance){
|
|
64
|
+
this.updateOverFlowedItems(this._lastContainerInstance, this._lastContainerSize);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private handleResize(entries: ResizeObserverEntry[]){
|
|
69
|
+
if(!entries || entries.length === 0) return;
|
|
70
|
+
|
|
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);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
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
|
+
}
|
|
87
|
+
|
|
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
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private canNotRegisterNotOverFlow(id: string) {
|
|
97
|
+
return !id || !this._notOverFlow.includes(id) || this._notOverFlowPros.has(id);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private hasChangedSize(elementSize: number):boolean{
|
|
101
|
+
if(!this._lastContainerSize) return true;
|
|
102
|
+
const variation = elementSize - this._lastContainerSize;
|
|
103
|
+
|
|
104
|
+
if(variation < 0){
|
|
105
|
+
const absoluteVariation = Math.abs(variation);
|
|
106
|
+
return (absoluteVariation > this._deltaSize);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return variation > 0;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private proccessElements(elementSize:number, children:Element[]){
|
|
113
|
+
if(children.length === 0) return;
|
|
114
|
+
|
|
115
|
+
const childrenSize = this.calcChildrenSize(children);
|
|
116
|
+
let diff = Number((elementSize - childrenSize).toFixed(4));
|
|
117
|
+
|
|
118
|
+
if(diff > 0){
|
|
119
|
+
this.clearOverFlow();
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
this.proccessElementsOverFlow(children, elementSize);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private clearOverFlow(){
|
|
127
|
+
this._hiddenItemsProps = new Map();
|
|
128
|
+
this._onResize([]);
|
|
129
|
+
}
|
|
130
|
+
|
|
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);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
this._onResize(overFlowedElements);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private isElementOverFlowing(elementsThatFit: Element[], element: Element) {
|
|
154
|
+
return !elementsThatFit.includes(element) && this.canOverFlowElement(element);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private canOverFlowElement(element: Element) {
|
|
158
|
+
return !this._notOverFlow.includes(element.id)
|
|
159
|
+
&& !this._notOverFlow.includes(this.getDataElementId(element));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private getDataElementId(element: Element): string {
|
|
163
|
+
return (element as HTMLElement).getAttribute('data-element-id') ?? "";
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
private exceedsAvaliableSize(sumElementsSize: number, elements: Element[], avaliableSize: number): boolean {
|
|
167
|
+
if(!this._notOverFlow.length) return sumElementsSize > avaliableSize
|
|
168
|
+
|
|
169
|
+
const elementIdsToCalculate = this.canNotOverFlowNotIncludedIds(elements);
|
|
170
|
+
if(!elementIdsToCalculate.length) return sumElementsSize > avaliableSize
|
|
171
|
+
|
|
172
|
+
const variation = this.calculateVariation(elementIdsToCalculate);
|
|
173
|
+
const occupiedSize = sumElementsSize + variation;
|
|
174
|
+
return occupiedSize > avaliableSize;
|
|
175
|
+
}
|
|
176
|
+
|
|
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;
|
|
183
|
+
});
|
|
184
|
+
return variation;
|
|
185
|
+
}
|
|
186
|
+
|
|
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
|
+
}
|
|
191
|
+
|
|
192
|
+
private registerElementSize(element: Element) {
|
|
193
|
+
const sizeProps = this.getElementSizeProps(element);
|
|
194
|
+
this._hiddenItemsProps.set(element, sizeProps);
|
|
195
|
+
}
|
|
196
|
+
|
|
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
|
+
}
|
|
204
|
+
|
|
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;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
size += (el.getBoundingClientRect() as any)[this._propSize];
|
|
222
|
+
size += calcMarginSize(el, this._scrollDirection);
|
|
223
|
+
return size;
|
|
224
|
+
}
|
|
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,
|
|
243
|
+
}
|
|
@@ -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,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
|
+
}
|
|
@@ -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
|
})
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import ObjectUtils from '../ObjectUtils'
|
|
2
|
+
|
|
3
|
+
describe("ObjectUtils", () => {
|
|
4
|
+
describe('hasEquivalentValues', () => {
|
|
5
|
+
it('should return true if both objects have the same property value', () => {
|
|
6
|
+
const obj1 = { value: 10 };
|
|
7
|
+
const obj2 = { value: 10 };
|
|
8
|
+
expect(ObjectUtils.hasEquivalentProps(obj1, obj2)).toBe(true);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should return false if both objects have different property values', () => {
|
|
12
|
+
const obj1 = { value: 10 };
|
|
13
|
+
const obj2 = { value: 20 };
|
|
14
|
+
expect(ObjectUtils.hasEquivalentProps(obj1, obj2)).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should return true if both objects are equivalent with custom property to compare', () => {
|
|
18
|
+
const obj1 = { customProp: 'hello' };
|
|
19
|
+
const obj2 = { customProp: 'hello' };
|
|
20
|
+
expect(ObjectUtils.hasEquivalentProps(obj1, obj2, 'customProp')).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should return false if both objects are not equivalent with custom property to compare', () => {
|
|
24
|
+
const obj1 = { customProp: 'hello' };
|
|
25
|
+
const obj2 = { customProp: 'world' };
|
|
26
|
+
expect(ObjectUtils.hasEquivalentProps(obj1, obj2, 'customProp')).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should return false if one object does not have the property', () => {
|
|
30
|
+
const obj1 = { value: 10 };
|
|
31
|
+
const obj2 = { anotherProp: 10 };
|
|
32
|
+
expect(ObjectUtils.hasEquivalentProps(obj1, obj2)).toBe(false);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should return true if comparing primitive values directly', () => {
|
|
36
|
+
const obj1 = 5;
|
|
37
|
+
const obj2 = 5;
|
|
38
|
+
expect(ObjectUtils.hasEquivalentProps(obj1, obj2)).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should return false if comparing different primitive values', () => {
|
|
42
|
+
const obj1 = 5;
|
|
43
|
+
const obj2 = 10;
|
|
44
|
+
expect(ObjectUtils.hasEquivalentProps(obj1, obj2)).toBe(false);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should return true when comparing object with a null value', () => {
|
|
48
|
+
const obj1 = null;
|
|
49
|
+
const obj2 = null;
|
|
50
|
+
expect(ObjectUtils.hasEquivalentProps(obj1, obj2)).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('should return false when comparing object with null and non-null value', () => {
|
|
54
|
+
const obj1 = null;
|
|
55
|
+
const obj2 = { value: 5 };
|
|
56
|
+
expect(ObjectUtils.hasEquivalentProps(obj1, obj2)).toBe(false);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('should return true when comparing non-object values that are equal', () => {
|
|
60
|
+
const obj1 = 'same';
|
|
61
|
+
const obj2 = 'same';
|
|
62
|
+
expect(ObjectUtils.hasEquivalentProps(obj1, obj2)).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
it("should get an object value based on its path", async () => {
|
|
69
|
+
const obj = {
|
|
70
|
+
food: {
|
|
71
|
+
fruits: {
|
|
72
|
+
apple: 1,
|
|
73
|
+
banana: 2
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const value = ObjectUtils.getProp(obj, "food.fruits.banana");
|
|
79
|
+
expect(value).toBe(2);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("should get an object value based on its path", async () => {
|
|
83
|
+
const food = {
|
|
84
|
+
fruits: {
|
|
85
|
+
apple: 1,
|
|
86
|
+
banana: 2
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const obj = { food };
|
|
91
|
+
|
|
92
|
+
const value = ObjectUtils.getProp(obj, "food");
|
|
93
|
+
expect(JSON.stringify(value)).toBe(JSON.stringify(food));
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("should return undefined if the path doesn't exist in the object", async () => {
|
|
97
|
+
const obj = {
|
|
98
|
+
food: {
|
|
99
|
+
fruits: {
|
|
100
|
+
apple: 1,
|
|
101
|
+
banana: 2
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const value = ObjectUtils.getProp(obj, "vegetables");
|
|
107
|
+
expect(value).toBe(undefined);
|
|
108
|
+
});
|
|
109
|
+
});
|