@sankhyalabs/core 5.20.0-dev.61 → 5.20.0-dev.63
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/DataUnit.md +0 -10
- package/.docs/classes/LockManager.md +73 -15
- package/.docs/classes/UserAgentUtils.md +15 -1
- package/.docs/enumerations/LockManagerOperation.md +12 -0
- package/.docs/globals.md +1 -0
- package/.docs/variables/CHANGING_PAGE_LOADING_SOURCE.md +13 -0
- package/dist/dataunit/DataUnit.d.ts +1 -1
- package/dist/dataunit/DataUnit.js +2 -2
- package/dist/dataunit/DataUnit.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/utils/LockManager.d.ts +15 -3
- package/dist/utils/LockManager.js +52 -2
- package/dist/utils/LockManager.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/package.json +1 -1
- package/reports/test-report.xml +116 -116
- package/src/dataunit/DataUnit.ts +3 -3
- package/src/index.ts +2 -1
- package/src/utils/LockManager.ts +63 -7
- package/src/utils/UserAgentUtils/index.ts +6 -1
package/src/utils/LockManager.ts
CHANGED
|
@@ -6,7 +6,11 @@ export enum LockManagerOperation {
|
|
|
6
6
|
/**
|
|
7
7
|
Operação de lock utilizada para controlar cliques nos botoes da taskbar.
|
|
8
8
|
*/
|
|
9
|
-
TASKBAR_CLICK = "taskbar_click"
|
|
9
|
+
TASKBAR_CLICK = "taskbar_click",
|
|
10
|
+
/**
|
|
11
|
+
Operação de lock utilizada para controlar carregamento da aplicação.
|
|
12
|
+
*/
|
|
13
|
+
APP_LOADING = "app_loading"
|
|
10
14
|
}
|
|
11
15
|
|
|
12
16
|
type Lock = {
|
|
@@ -72,7 +76,7 @@ export class LockManager{
|
|
|
72
76
|
}
|
|
73
77
|
});
|
|
74
78
|
};
|
|
75
|
-
|
|
79
|
+
|
|
76
80
|
/**
|
|
77
81
|
* Cria um contexto de locker, caso nao exista, para todos elementos pais iniciados com ez- ou snk-.
|
|
78
82
|
*
|
|
@@ -103,6 +107,30 @@ export class LockManager{
|
|
|
103
107
|
}
|
|
104
108
|
}
|
|
105
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Reseta todos os locks existentes para um determinado contexto e operação de forma assíncrona
|
|
112
|
+
* @param id - ID do contexto ou elemento HTML contendo contexto
|
|
113
|
+
* @param operation - Operação específica para resetar os locks
|
|
114
|
+
* @returns Promise que será resolvida quando todos os locks forem resetados
|
|
115
|
+
*/
|
|
116
|
+
public static async resetLocks(id: string | HTMLElement, operation: LockManagerOperation): Promise<void> {
|
|
117
|
+
const lockerId = this.buildLockerID(id, operation);
|
|
118
|
+
if (!lockerId) return;
|
|
119
|
+
|
|
120
|
+
const currentLocks = this._locks.get(lockerId);
|
|
121
|
+
|
|
122
|
+
if (currentLocks?.length) {
|
|
123
|
+
await Promise.all(currentLocks.map(lock => {
|
|
124
|
+
lock.done = true;
|
|
125
|
+
lock.resolve?.();
|
|
126
|
+
return lock.promise;
|
|
127
|
+
}));
|
|
128
|
+
|
|
129
|
+
this._locks.delete(lockerId);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
106
134
|
/**
|
|
107
135
|
* Inicia um locker baseado em um contexto e uma operação.
|
|
108
136
|
*
|
|
@@ -111,7 +139,7 @@ export class LockManager{
|
|
|
111
139
|
*
|
|
112
140
|
* @returns - Uma função que fara a liberação do lock.
|
|
113
141
|
*/
|
|
114
|
-
public static lock(id:string|HTMLElement, operation:LockManagerOperation):
|
|
142
|
+
public static lock(id:string|HTMLElement, operation:LockManagerOperation): () => void {
|
|
115
143
|
const lockerId = LockManager.buildLockerID(id, operation);
|
|
116
144
|
|
|
117
145
|
if(!lockerId) return () => {};
|
|
@@ -122,7 +150,6 @@ export class LockManager{
|
|
|
122
150
|
|
|
123
151
|
const currentLocks = LockManager._locks.get(lockerId) ?? [];
|
|
124
152
|
currentLocks.push(lock);
|
|
125
|
-
|
|
126
153
|
LockManager._locks.set(lockerId, currentLocks);
|
|
127
154
|
|
|
128
155
|
return () => {
|
|
@@ -139,19 +166,48 @@ export class LockManager{
|
|
|
139
166
|
*
|
|
140
167
|
* @returns - Promise que será resolvida quando todos lockers forem finalizados.
|
|
141
168
|
*/
|
|
142
|
-
public static async whenResolve(id:string|HTMLElement, operation:LockManagerOperation): Promise<void> {
|
|
169
|
+
public static async whenResolve(id:string|HTMLElement, operation:LockManagerOperation, debounce?: number, timeOut?: number): Promise<void> {
|
|
143
170
|
const lockerId = LockManager.buildLockerID(id, operation);
|
|
144
171
|
|
|
145
172
|
if(!lockerId) return;
|
|
146
173
|
|
|
174
|
+
if(debounce) await new Promise(resolve => setTimeout(resolve, debounce));
|
|
175
|
+
|
|
176
|
+
const startTime = Date.now();
|
|
177
|
+
|
|
147
178
|
while (LockManager._locks.get(lockerId)?.length) {
|
|
179
|
+
|
|
180
|
+
if (timeOut && Date.now() - startTime >= timeOut) {
|
|
181
|
+
await this.resetLocks(id, operation);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
|
|
148
185
|
const locks:Array<Lock> = LockManager._locks.get(lockerId) ?? [];
|
|
149
186
|
await Promise.all(locks.map(lock => lock.promise));
|
|
150
187
|
|
|
151
188
|
//Aguarda listeners da tela reagirem as mudancas de estado do dataunit
|
|
152
|
-
await new Promise(resolve => setTimeout(resolve, 200));
|
|
153
|
-
|
|
189
|
+
await new Promise(resolve => setTimeout(resolve, debounce || 200));
|
|
190
|
+
|
|
154
191
|
LockManager._locks.set(lockerId, locks.filter(lock => !lock.done));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
public static async whenHasLock(id:string|HTMLElement, operation:LockManagerOperation, timeOut?: number): Promise<void> {
|
|
197
|
+
const lockerId = LockManager.buildLockerID(id, operation);
|
|
198
|
+
|
|
199
|
+
if(!lockerId) return;
|
|
200
|
+
|
|
201
|
+
const startTime = Date.now();
|
|
202
|
+
|
|
203
|
+
while (!LockManager._locks.get(lockerId)?.length) {
|
|
204
|
+
|
|
205
|
+
if (timeOut && Date.now() - startTime >= timeOut) {
|
|
206
|
+
await this.resetLocks(id, operation);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
await new Promise(resolve => setTimeout(resolve, 200));
|
|
155
211
|
}
|
|
156
212
|
}
|
|
157
213
|
}
|
|
@@ -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
|
})
|