@shival99/z-ui 1.9.13 → 1.9.14

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 (47) hide show
  1. package/fesm2022/shival99-z-ui-components-z-accordion.mjs +129 -12
  2. package/fesm2022/shival99-z-ui-components-z-accordion.mjs.map +1 -1
  3. package/fesm2022/shival99-z-ui-components-z-autocomplete.mjs +142 -8
  4. package/fesm2022/shival99-z-ui-components-z-autocomplete.mjs.map +1 -1
  5. package/fesm2022/shival99-z-ui-components-z-breadcrumb.mjs +65 -16
  6. package/fesm2022/shival99-z-ui-components-z-breadcrumb.mjs.map +1 -1
  7. package/fesm2022/shival99-z-ui-components-z-chat.mjs +18 -7
  8. package/fesm2022/shival99-z-ui-components-z-chat.mjs.map +1 -1
  9. package/fesm2022/shival99-z-ui-components-z-filter.mjs +1 -1
  10. package/fesm2022/shival99-z-ui-components-z-filter.mjs.map +1 -1
  11. package/fesm2022/shival99-z-ui-components-z-skeleton-auto.mjs +61 -0
  12. package/fesm2022/shival99-z-ui-components-z-skeleton-auto.mjs.map +1 -0
  13. package/fesm2022/shival99-z-ui-components-z-skeleton.mjs +13 -33
  14. package/fesm2022/shival99-z-ui-components-z-skeleton.mjs.map +1 -1
  15. package/fesm2022/shival99-z-ui-components-z-switch.mjs +16 -6
  16. package/fesm2022/shival99-z-ui-components-z-switch.mjs.map +1 -1
  17. package/fesm2022/shival99-z-ui-components-z-table.mjs +291 -24
  18. package/fesm2022/shival99-z-ui-components-z-table.mjs.map +1 -1
  19. package/fesm2022/shival99-z-ui-components-z-tabs.mjs +27 -2
  20. package/fesm2022/shival99-z-ui-components-z-tabs.mjs.map +1 -1
  21. package/fesm2022/shival99-z-ui-components-z-timeline.mjs +5 -3
  22. package/fesm2022/shival99-z-ui-components-z-timeline.mjs.map +1 -1
  23. package/fesm2022/shival99-z-ui-providers.mjs +1 -0
  24. package/fesm2022/shival99-z-ui-providers.mjs.map +1 -1
  25. package/fesm2022/shival99-z-ui-services.mjs +371 -179
  26. package/fesm2022/shival99-z-ui-services.mjs.map +1 -1
  27. package/fesm2022/shival99-z-ui-utils.mjs +6 -1
  28. package/fesm2022/shival99-z-ui-utils.mjs.map +1 -1
  29. package/package.json +5 -1
  30. package/types/shival99-z-ui-components-z-accordion.d.ts +22 -4
  31. package/types/shival99-z-ui-components-z-autocomplete.d.ts +34 -8
  32. package/types/shival99-z-ui-components-z-breadcrumb.d.ts +13 -3
  33. package/types/shival99-z-ui-components-z-calendar.d.ts +4 -4
  34. package/types/shival99-z-ui-components-z-chat.d.ts +1 -0
  35. package/types/shival99-z-ui-components-z-editor.d.ts +1 -1
  36. package/types/shival99-z-ui-components-z-modal.d.ts +1 -1
  37. package/types/shival99-z-ui-components-z-popover.d.ts +1 -1
  38. package/types/shival99-z-ui-components-z-select.d.ts +1 -1
  39. package/types/shival99-z-ui-components-z-skeleton-auto.d.ts +35 -0
  40. package/types/shival99-z-ui-components-z-skeleton.d.ts +3 -7
  41. package/types/shival99-z-ui-components-z-switch.d.ts +7 -1
  42. package/types/shival99-z-ui-components-z-table.d.ts +65 -7
  43. package/types/shival99-z-ui-components-z-tabs.d.ts +3 -3
  44. package/types/shival99-z-ui-components-z-timeline.d.ts +7 -1
  45. package/types/shival99-z-ui-components-z-upload.d.ts +3 -3
  46. package/types/shival99-z-ui-services.d.ts +18 -1
  47. package/types/shival99-z-ui-utils.d.ts +2 -1
@@ -1,6 +1,6 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { Injectable, InjectionToken, inject, DestroyRef, signal, computed, PLATFORM_ID, effect } from '@angular/core';
3
- import { zFormatNumExcel, zConvertColorToArgb } from '@shival99/z-ui/utils';
3
+ import { zNormalize, zFormatNumExcel, zConvertColorToArgb } from '@shival99/z-ui/utils';
4
4
  import * as ExcelJS from 'exceljs';
5
5
  import { saveAs } from 'file-saver';
6
6
  import * as XLSX from 'xlsx';
@@ -11,137 +11,51 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
11
11
  import { TranslateService } from '@ngx-translate/core';
12
12
  import { isPlatformBrowser, DOCUMENT } from '@angular/common';
13
13
 
14
- class ZCacheService {
15
- static _prefix = 'z_';
16
- static _encrypt = true;
17
- static configure(config) {
18
- if (config.prefix) {
19
- ZCacheService._prefix = config.prefix;
20
- }
21
- if (config.encrypt !== undefined) {
22
- ZCacheService._encrypt = config.encrypt;
23
- }
24
- }
25
- static _encode(data) {
26
- const payload = { __z: true, __d: data };
27
- return btoa(encodeURIComponent(JSON.stringify(payload)));
28
- }
29
- static _decode(data) {
30
- try {
31
- const decoded = JSON.parse(decodeURIComponent(atob(data)));
32
- if (!decoded.__z) {
33
- return null;
34
- }
35
- return decoded.__d;
36
- }
37
- catch {
38
- return null;
39
- }
40
- }
41
- static _normalizeKey(key) {
42
- return key.toLowerCase();
43
- }
44
- static _getFullKey(key, encrypt) {
45
- const normalizedKey = ZCacheService._normalizeKey(key);
46
- const prefixedKey = `${ZCacheService._prefix}${normalizedKey}`;
47
- return encrypt ? ZCacheService._encode(prefixedKey) : prefixedKey;
48
- }
49
- static _decodeStorageKey(storageKey) {
50
- const decoded = ZCacheService._decode(storageKey);
51
- if (typeof decoded !== 'string') {
52
- return null;
53
- }
54
- return decoded;
55
- }
56
- static _isManagedStorageKey(storageKey) {
57
- if (storageKey.startsWith(ZCacheService._prefix)) {
58
- return true;
59
- }
60
- const decoded = ZCacheService._decodeStorageKey(storageKey);
61
- if (!decoded) {
62
- return false;
63
- }
64
- return decoded.startsWith(ZCacheService._prefix);
65
- }
66
- static _safeOperation(operation, fallback) {
67
- try {
68
- return operation();
69
- }
70
- catch (error) {
71
- console.error('[ZCache] Operation error:', error);
72
- return fallback;
73
- }
74
- }
75
- static get(key, defaultValue, encrypt = ZCacheService._encrypt) {
76
- return ZCacheService._safeOperation(() => {
77
- const _key = ZCacheService._getFullKey(key, encrypt);
78
- const result = localStorage.getItem(_key);
79
- if (!result) {
80
- return defaultValue;
81
- }
82
- const data = encrypt ? ZCacheService._decode(result) : JSON.parse(result);
83
- return data ?? defaultValue;
84
- }, defaultValue);
85
- }
86
- static set(key, data, encrypt = ZCacheService._encrypt) {
87
- return ZCacheService._safeOperation(() => {
88
- const _key = ZCacheService._getFullKey(key, encrypt);
89
- const _value = encrypt ? ZCacheService._encode(data) : JSON.stringify(data);
90
- localStorage.setItem(_key, _value);
91
- return true;
92
- }, false);
93
- }
94
- static delete(key) {
95
- return ZCacheService._safeOperation(() => {
96
- const encryptedKey = ZCacheService._getFullKey(key, true);
97
- const plainKey = ZCacheService._getFullKey(key, false);
98
- localStorage.removeItem(encryptedKey);
99
- localStorage.removeItem(plainKey);
100
- return true;
101
- }, false);
102
- }
103
- static deleteMultiple(keys) {
104
- return ZCacheService._safeOperation(() => {
105
- keys.forEach(key => {
106
- const encryptedKey = ZCacheService._getFullKey(key, true);
107
- const plainKey = ZCacheService._getFullKey(key, false);
108
- localStorage.removeItem(encryptedKey);
109
- localStorage.removeItem(plainKey);
110
- });
111
- return true;
112
- }, false);
113
- }
114
- static clear() {
115
- return ZCacheService._safeOperation(() => {
116
- const keysToRemove = [];
117
- for (let i = 0; i < localStorage.length; i++) {
118
- const key = localStorage.key(i);
119
- if (!key) {
120
- continue;
121
- }
122
- if (ZCacheService._isManagedStorageKey(key)) {
123
- keysToRemove.push(key);
124
- }
125
- }
126
- keysToRemove.forEach(key => localStorage.removeItem(key));
127
- return true;
128
- }, false);
14
+ const Z_CACHE_SCOPE_SEPARATOR = '::';
15
+ const Z_DB_SCOPE_SEPARATOR = '__';
16
+ const Z_SCOPE_FALLBACK = 'global';
17
+ const Z_RUNTIME_SCOPE = (() => {
18
+ if (typeof window === 'undefined') {
19
+ return Z_SCOPE_FALLBACK;
20
+ }
21
+ const origin = zNormalize(window.location.origin);
22
+ const baseHref = typeof document !== 'undefined' ? zNormalize(document.querySelector('base')?.getAttribute('href') ?? '') : '';
23
+ if (!origin && !baseHref) {
24
+ return Z_SCOPE_FALLBACK;
25
+ }
26
+ if (!origin) {
27
+ return baseHref || Z_SCOPE_FALLBACK;
28
+ }
29
+ if (!baseHref) {
30
+ return origin;
31
+ }
32
+ return `${origin}__${baseHref}`;
33
+ })();
34
+ const Z_CACHE_SCOPE_SUFFIX = `${Z_CACHE_SCOPE_SEPARATOR}${Z_RUNTIME_SCOPE}`;
35
+ const Z_DB_SCOPE_SUFFIX = `${Z_DB_SCOPE_SEPARATOR}${Z_RUNTIME_SCOPE}`;
36
+ function zAppendScope(value, scopeSuffix) {
37
+ const trimmed = value.trim();
38
+ if (!trimmed || trimmed.endsWith(scopeSuffix)) {
39
+ return value;
40
+ }
41
+ return `${trimmed}${scopeSuffix}`;
42
+ }
43
+ function zBuildScopedCacheKey(baseKey) {
44
+ return zAppendScope(baseKey, Z_CACHE_SCOPE_SUFFIX);
45
+ }
46
+ function zBuildScopedDbName(baseDbName) {
47
+ return zAppendScope(baseDbName, Z_DB_SCOPE_SUFFIX);
48
+ }
49
+ function zStripScopedCacheKey(key) {
50
+ const normalizedKey = key.trim();
51
+ if (!normalizedKey) {
52
+ return key;
129
53
  }
130
- static has(key, encrypt = ZCacheService._encrypt) {
131
- return ZCacheService._safeOperation(() => {
132
- const _key = ZCacheService._getFullKey(key, encrypt);
133
- return localStorage.getItem(_key) !== null;
134
- }, false);
54
+ if (!normalizedKey.endsWith(Z_CACHE_SCOPE_SUFFIX)) {
55
+ return normalizedKey;
135
56
  }
136
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: ZCacheService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
137
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: ZCacheService, providedIn: 'root' });
57
+ return normalizedKey.slice(0, normalizedKey.length - Z_CACHE_SCOPE_SUFFIX.length);
138
58
  }
139
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: ZCacheService, decorators: [{
140
- type: Injectable,
141
- args: [{
142
- providedIn: 'root',
143
- }]
144
- }] });
145
59
 
146
60
  const Z_EXCEL_COLORS = {
147
61
  'green-50': 'FFF0FDF4',
@@ -256,6 +170,185 @@ const Z_EXCEL_WIDTH_LIMITS = {
256
170
  default: 20,
257
171
  };
258
172
 
173
+ const Z_INDEXDB_DEFAULT_CONFIG = {
174
+ dbName: 'ZDatabase',
175
+ version: 1,
176
+ mode: 'readwrite',
177
+ defaultStore: 'ZStore',
178
+ };
179
+ const Z_INDEXDB_BATCH_SIZE = 100;
180
+ const Z_INDEXDB_MAX_VERSION = 1000;
181
+
182
+ const Z_LANG_TO_LOCALE = {
183
+ vi: 'vi-VN',
184
+ en: 'en-US',
185
+ };
186
+
187
+ class ZCacheService {
188
+ static _prefix = 'z_';
189
+ static _encrypt = true;
190
+ static configure(config) {
191
+ if (config.prefix) {
192
+ ZCacheService._prefix = config.prefix;
193
+ }
194
+ if (config.encrypt !== undefined) {
195
+ ZCacheService._encrypt = config.encrypt;
196
+ }
197
+ }
198
+ static _encode(data) {
199
+ const payload = { __z: true, __d: data };
200
+ return btoa(encodeURIComponent(JSON.stringify(payload)));
201
+ }
202
+ static _decode(data) {
203
+ try {
204
+ const decoded = JSON.parse(decodeURIComponent(atob(data)));
205
+ if (!decoded.__z) {
206
+ return null;
207
+ }
208
+ return decoded.__d;
209
+ }
210
+ catch {
211
+ return null;
212
+ }
213
+ }
214
+ static _normalizeLegacyKey(key) {
215
+ return key.trim().toLowerCase();
216
+ }
217
+ static _normalizeKey(key) {
218
+ return zBuildScopedCacheKey(ZCacheService._normalizeLegacyKey(key));
219
+ }
220
+ static _toStorageKey(normalizedKey, encrypt) {
221
+ const prefixedKey = `${ZCacheService._prefix}${normalizedKey}`;
222
+ return encrypt ? ZCacheService._encode(prefixedKey) : prefixedKey;
223
+ }
224
+ static _getFullKey(key, encrypt) {
225
+ return ZCacheService._toStorageKey(ZCacheService._normalizeKey(key), encrypt);
226
+ }
227
+ static _getLegacyFullKey(key, encrypt) {
228
+ const legacyNormalized = ZCacheService._normalizeLegacyKey(key);
229
+ const scopedNormalized = ZCacheService._normalizeKey(key);
230
+ if (legacyNormalized === scopedNormalized) {
231
+ return null;
232
+ }
233
+ return ZCacheService._toStorageKey(legacyNormalized, encrypt);
234
+ }
235
+ static _getCandidateStorageKeys(key, encrypt) {
236
+ const scopedKey = ZCacheService._getFullKey(key, encrypt);
237
+ const legacyKey = ZCacheService._getLegacyFullKey(key, encrypt);
238
+ return legacyKey ? [scopedKey, legacyKey] : [scopedKey];
239
+ }
240
+ static _decodeStorageKey(storageKey) {
241
+ const decoded = ZCacheService._decode(storageKey);
242
+ if (typeof decoded !== 'string') {
243
+ return null;
244
+ }
245
+ return decoded;
246
+ }
247
+ static _isManagedStorageKey(storageKey) {
248
+ if (storageKey.startsWith(ZCacheService._prefix)) {
249
+ return true;
250
+ }
251
+ const decoded = ZCacheService._decodeStorageKey(storageKey);
252
+ if (!decoded) {
253
+ return false;
254
+ }
255
+ return decoded.startsWith(ZCacheService._prefix);
256
+ }
257
+ static _safeOperation(operation, fallback) {
258
+ try {
259
+ return operation();
260
+ }
261
+ catch (error) {
262
+ console.error('[ZCache] Operation error:', error);
263
+ return fallback;
264
+ }
265
+ }
266
+ static get(key, defaultValue, encrypt = ZCacheService._encrypt) {
267
+ return ZCacheService._safeOperation(() => {
268
+ const candidateKeys = ZCacheService._getCandidateStorageKeys(key, encrypt);
269
+ for (let i = 0; i < candidateKeys.length; i++) {
270
+ const result = localStorage.getItem(candidateKeys[i]);
271
+ if (!result) {
272
+ continue;
273
+ }
274
+ const data = encrypt ? ZCacheService._decode(result) : JSON.parse(result);
275
+ if (data === null || data === undefined) {
276
+ continue;
277
+ }
278
+ if (i > 0) {
279
+ const scopedKey = candidateKeys[0];
280
+ localStorage.setItem(scopedKey, result);
281
+ localStorage.removeItem(candidateKeys[i]);
282
+ }
283
+ return data;
284
+ }
285
+ return defaultValue;
286
+ }, defaultValue);
287
+ }
288
+ static set(key, data, encrypt = ZCacheService._encrypt) {
289
+ return ZCacheService._safeOperation(() => {
290
+ const _key = ZCacheService._getFullKey(key, encrypt);
291
+ const legacyKey = ZCacheService._getLegacyFullKey(key, encrypt);
292
+ const _value = encrypt ? ZCacheService._encode(data) : JSON.stringify(data);
293
+ localStorage.setItem(_key, _value);
294
+ if (legacyKey) {
295
+ localStorage.removeItem(legacyKey);
296
+ }
297
+ return true;
298
+ }, false);
299
+ }
300
+ static delete(key) {
301
+ return ZCacheService._safeOperation(() => {
302
+ const encryptedKeys = ZCacheService._getCandidateStorageKeys(key, true);
303
+ const plainKeys = ZCacheService._getCandidateStorageKeys(key, false);
304
+ encryptedKeys.forEach(item => localStorage.removeItem(item));
305
+ plainKeys.forEach(item => localStorage.removeItem(item));
306
+ return true;
307
+ }, false);
308
+ }
309
+ static deleteMultiple(keys) {
310
+ return ZCacheService._safeOperation(() => {
311
+ keys.forEach(key => {
312
+ const encryptedKeys = ZCacheService._getCandidateStorageKeys(key, true);
313
+ const plainKeys = ZCacheService._getCandidateStorageKeys(key, false);
314
+ encryptedKeys.forEach(item => localStorage.removeItem(item));
315
+ plainKeys.forEach(item => localStorage.removeItem(item));
316
+ });
317
+ return true;
318
+ }, false);
319
+ }
320
+ static clear() {
321
+ return ZCacheService._safeOperation(() => {
322
+ const keysToRemove = [];
323
+ for (let i = 0; i < localStorage.length; i++) {
324
+ const key = localStorage.key(i);
325
+ if (!key) {
326
+ continue;
327
+ }
328
+ if (ZCacheService._isManagedStorageKey(key)) {
329
+ keysToRemove.push(key);
330
+ }
331
+ }
332
+ keysToRemove.forEach(key => localStorage.removeItem(key));
333
+ return true;
334
+ }, false);
335
+ }
336
+ static has(key, encrypt = ZCacheService._encrypt) {
337
+ return ZCacheService._safeOperation(() => {
338
+ const candidateKeys = ZCacheService._getCandidateStorageKeys(key, encrypt);
339
+ return candidateKeys.some(storageKey => localStorage.getItem(storageKey) !== null);
340
+ }, false);
341
+ }
342
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: ZCacheService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
343
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: ZCacheService, providedIn: 'root' });
344
+ }
345
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: ZCacheService, decorators: [{
346
+ type: Injectable,
347
+ args: [{
348
+ providedIn: 'root',
349
+ }]
350
+ }] });
351
+
259
352
  class ZExcelService {
260
353
  static _isHeaderConfig(config) {
261
354
  if (!config || typeof config !== 'object') {
@@ -900,18 +993,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImpor
900
993
  }]
901
994
  }] });
902
995
 
903
- const Z_INDEXDB_DEFAULT_CONFIG = {
904
- dbName: 'ZDatabase',
905
- version: 1,
906
- mode: 'readwrite',
907
- defaultStore: 'ZStore',
908
- };
909
- const Z_INDEXDB_BATCH_SIZE = 100;
910
- const Z_INDEXDB_MAX_VERSION = 1000;
911
-
912
996
  class ZIndexDbService {
913
997
  _db = null;
914
998
  _dbName;
999
+ _legacyDbName = null;
915
1000
  _version;
916
1001
  _mode;
917
1002
  _dbReady;
@@ -920,7 +1005,10 @@ class ZIndexDbService {
920
1005
  _globalProtectedKeys;
921
1006
  _encrypt = true;
922
1007
  constructor(config = {}) {
923
- this._dbName = config.dbName ?? Z_INDEXDB_DEFAULT_CONFIG.dbName;
1008
+ const baseDbName = config.dbName ?? Z_INDEXDB_DEFAULT_CONFIG.dbName;
1009
+ const scopedDbName = zBuildScopedDbName(baseDbName);
1010
+ this._dbName = scopedDbName;
1011
+ this._legacyDbName = scopedDbName === baseDbName ? null : baseDbName;
924
1012
  this._version = config.version ?? Z_INDEXDB_DEFAULT_CONFIG.version;
925
1013
  this._mode = config.mode ?? Z_INDEXDB_DEFAULT_CONFIG.mode;
926
1014
  this._defaultStoreName = config.defaultStore ?? Z_INDEXDB_DEFAULT_CONFIG.defaultStore;
@@ -950,8 +1038,25 @@ class ZIndexDbService {
950
1038
  }
951
1039
  return storeConfig.encrypt ?? this._encrypt;
952
1040
  }
1041
+ _normalizeLegacyKey(key) {
1042
+ return key.trim().toLowerCase();
1043
+ }
953
1044
  _normalizeKey(key) {
954
- return key.toLowerCase();
1045
+ return zBuildScopedCacheKey(this._normalizeLegacyKey(key));
1046
+ }
1047
+ _resolveLegacyNormalizedKey(key) {
1048
+ const legacyKey = this._normalizeLegacyKey(key);
1049
+ const scopedKey = this._normalizeKey(key);
1050
+ return legacyKey === scopedKey ? null : legacyKey;
1051
+ }
1052
+ _buildStorageKeys(key, encrypt) {
1053
+ const scopedKey = this._normalizeKey(key);
1054
+ const legacyKey = this._resolveLegacyNormalizedKey(key);
1055
+ const logicalKeys = legacyKey ? [scopedKey, legacyKey] : [scopedKey];
1056
+ if (!encrypt) {
1057
+ return logicalKeys;
1058
+ }
1059
+ return logicalKeys.map(item => this._encryptData(item));
955
1060
  }
956
1061
  _encryptData(data) {
957
1062
  const payload = {
@@ -1004,6 +1109,7 @@ class ZIndexDbService {
1004
1109
  if (this._db) {
1005
1110
  return;
1006
1111
  }
1112
+ await this._adoptLegacyDbNameIfNeeded();
1007
1113
  const currentVersion = await this._getCurrentDbVersion();
1008
1114
  if (currentVersion >= Z_INDEXDB_MAX_VERSION) {
1009
1115
  await this._resetDatabase();
@@ -1053,18 +1159,86 @@ class ZIndexDbService {
1053
1159
  }
1054
1160
  });
1055
1161
  }
1056
- _getCurrentDbVersion() {
1162
+ async _adoptLegacyDbNameIfNeeded() {
1163
+ if (!this._legacyDbName) {
1164
+ return;
1165
+ }
1166
+ const supportsDatabasesApi = typeof indexedDB.databases === 'function';
1167
+ if (!supportsDatabasesApi) {
1168
+ const scopedMeta = await this._probeDbMetadataByOpen(this._dbName);
1169
+ if (scopedMeta.hasStores) {
1170
+ return;
1171
+ }
1172
+ const legacyMeta = await this._probeDbMetadataByOpen(this._legacyDbName);
1173
+ if (!legacyMeta.hasStores) {
1174
+ return;
1175
+ }
1176
+ this._dbName = this._legacyDbName;
1177
+ this._version = Math.max(this._version, legacyMeta.version);
1178
+ this._legacyDbName = null;
1179
+ return;
1180
+ }
1181
+ const scopedVersion = await this._getExistingDbVersion(this._dbName);
1182
+ if (scopedVersion > 0) {
1183
+ return;
1184
+ }
1185
+ const legacyVersion = await this._getExistingDbVersion(this._legacyDbName);
1186
+ if (legacyVersion <= 0) {
1187
+ return;
1188
+ }
1189
+ this._dbName = this._legacyDbName;
1190
+ this._version = Math.max(this._version, legacyVersion);
1191
+ this._legacyDbName = null;
1192
+ }
1193
+ _getExistingDbVersion(dbName) {
1194
+ const databasesApi = indexedDB.databases;
1195
+ if (!databasesApi) {
1196
+ return Promise.resolve(0);
1197
+ }
1198
+ return databasesApi
1199
+ .call(indexedDB)
1200
+ .then(databases => {
1201
+ const matchedDb = databases.find(database => database.name === dbName);
1202
+ return typeof matchedDb?.version === 'number' ? matchedDb.version : 0;
1203
+ })
1204
+ .catch(() => 0);
1205
+ }
1206
+ _probeDbMetadataByOpen(dbName) {
1057
1207
  return new Promise(resolve => {
1058
- const request = indexedDB.open(this._dbName);
1059
- request.onsuccess = event => {
1060
- const db = event.target.result;
1061
- const { version } = db;
1062
- db.close();
1063
- resolve(version);
1064
- };
1065
- request.onerror = () => {
1066
- resolve(1);
1067
- };
1208
+ try {
1209
+ const request = indexedDB.open(dbName);
1210
+ request.onsuccess = event => {
1211
+ const db = event.target.result;
1212
+ const { version } = db;
1213
+ const hasStores = db.objectStoreNames.length > 0;
1214
+ db.close();
1215
+ if (hasStores || version > 1) {
1216
+ resolve({ version, hasStores });
1217
+ return;
1218
+ }
1219
+ try {
1220
+ const deleteRequest = indexedDB.deleteDatabase(dbName);
1221
+ deleteRequest.onsuccess = () => resolve({ version: 0, hasStores: false });
1222
+ deleteRequest.onerror = () => resolve({ version: 0, hasStores: false });
1223
+ deleteRequest.onblocked = () => resolve({ version: 0, hasStores: false });
1224
+ }
1225
+ catch {
1226
+ resolve({ version: 0, hasStores: false });
1227
+ }
1228
+ };
1229
+ request.onerror = () => resolve({ version: 0, hasStores: false });
1230
+ }
1231
+ catch {
1232
+ resolve({ version: 0, hasStores: false });
1233
+ }
1234
+ });
1235
+ }
1236
+ _getCurrentDbVersion() {
1237
+ return this._getExistingDbVersion(this._dbName).then(version => {
1238
+ if (version > 0) {
1239
+ return version;
1240
+ }
1241
+ return this._probeDbMetadataByOpen(this._dbName).then(metadata => (metadata.version > 0 ? metadata.version : 1));
1068
1242
  });
1069
1243
  }
1070
1244
  async _triggerUpgrade() {
@@ -1120,26 +1294,37 @@ class ZIndexDbService {
1120
1294
  return defaultValue;
1121
1295
  }
1122
1296
  }
1123
- const normalizedKey = this._normalizeKey(key);
1124
- const _key = shouldEncrypt ? this._encryptData(normalizedKey) : normalizedKey;
1297
+ const storageKeys = this._buildStorageKeys(key, shouldEncrypt);
1125
1298
  return new Promise(resolve => {
1126
1299
  try {
1127
1300
  const transaction = this._db.transaction([storeConfig.name], this._mode);
1128
1301
  const store = transaction.objectStore(storeConfig.name);
1129
- const request = store.get(_key);
1302
+ const request = store.get(storageKeys[0]);
1130
1303
  request.onsuccess = () => {
1131
- try {
1132
- const { result } = request;
1133
- if (!result) {
1304
+ const resolveData = (rawValue) => {
1305
+ try {
1306
+ if (!rawValue) {
1307
+ resolve(defaultValue);
1308
+ return;
1309
+ }
1310
+ const decrypted = shouldEncrypt ? this._decryptData(rawValue) : rawValue;
1311
+ resolve(decrypted ?? defaultValue);
1312
+ }
1313
+ catch {
1134
1314
  resolve(defaultValue);
1135
- return;
1136
1315
  }
1137
- const decrypted = shouldEncrypt ? this._decryptData(result) : result;
1138
- resolve(decrypted ?? defaultValue);
1316
+ };
1317
+ if (request.result) {
1318
+ resolveData(request.result);
1319
+ return;
1139
1320
  }
1140
- catch {
1321
+ if (storageKeys.length < 2) {
1141
1322
  resolve(defaultValue);
1323
+ return;
1142
1324
  }
1325
+ const legacyRequest = store.get(storageKeys[1]);
1326
+ legacyRequest.onsuccess = () => resolveData(legacyRequest.result);
1327
+ legacyRequest.onerror = () => resolve(defaultValue);
1143
1328
  };
1144
1329
  request.onerror = () => resolve(defaultValue);
1145
1330
  transaction.onerror = () => resolve(defaultValue);
@@ -1167,14 +1352,17 @@ class ZIndexDbService {
1167
1352
  throw new Error(`Failed to create store "${storeConfig.name}"`);
1168
1353
  }
1169
1354
  }
1170
- const normalizedKey = this._normalizeKey(key);
1171
- const _key = shouldEncrypt ? this._encryptData(normalizedKey) : normalizedKey;
1355
+ const storageKeys = this._buildStorageKeys(key, shouldEncrypt);
1356
+ const _key = storageKeys[0];
1172
1357
  const _value = shouldEncrypt ? this._encryptData(value) : value;
1173
1358
  return new Promise((resolve, reject) => {
1174
1359
  try {
1175
1360
  const transaction = this._db.transaction([storeConfig.name], 'readwrite');
1176
1361
  const store = transaction.objectStore(storeConfig.name);
1177
1362
  const request = store.put(_value, _key);
1363
+ if (storageKeys.length > 1) {
1364
+ store.delete(storageKeys[1]);
1365
+ }
1178
1366
  request.onerror = () => reject(request.error);
1179
1367
  transaction.oncomplete = () => resolve();
1180
1368
  transaction.onerror = () => reject(transaction.error);
@@ -1215,9 +1403,10 @@ class ZIndexDbService {
1215
1403
  const transaction = this._db.transaction([storeConfig.name], 'readwrite');
1216
1404
  const store = transaction.objectStore(storeConfig.name);
1217
1405
  keys.forEach(k => {
1218
- const normalizedKey = this._normalizeKey(k);
1219
- store.delete(normalizedKey);
1220
- store.delete(this._encryptData(normalizedKey));
1406
+ const plainKeys = this._buildStorageKeys(k, false);
1407
+ const encryptedKeys = this._buildStorageKeys(k, true);
1408
+ plainKeys.forEach(item => store.delete(item));
1409
+ encryptedKeys.forEach(item => store.delete(item));
1221
1410
  });
1222
1411
  transaction.oncomplete = () => resolve();
1223
1412
  transaction.onerror = () => reject(transaction.error);
@@ -1257,17 +1446,22 @@ class ZIndexDbService {
1257
1446
  const store = transaction.objectStore(storeConfig.name);
1258
1447
  const keyRequest = store.getAllKeys();
1259
1448
  const protectedSet = new Set();
1449
+ const protectedLogicalKeys = new Set();
1260
1450
  protectedKeys.forEach(k => {
1261
- const normalizedKey = this._normalizeKey(k);
1262
- protectedSet.add(normalizedKey);
1263
- protectedSet.add(this._encryptData(normalizedKey));
1451
+ const plainKeys = this._buildStorageKeys(k, false);
1452
+ const encryptedKeys = this._buildStorageKeys(k, true);
1453
+ plainKeys.forEach(item => {
1454
+ protectedSet.add(item);
1455
+ protectedLogicalKeys.add(item);
1456
+ });
1457
+ encryptedKeys.forEach(item => protectedSet.add(item));
1264
1458
  });
1265
1459
  keyRequest.onsuccess = () => {
1266
1460
  const allKeys = keyRequest.result;
1267
1461
  allKeys.forEach(k => {
1268
1462
  if (!protectedSet.has(k)) {
1269
1463
  const decrypted = this._decryptData(k);
1270
- if (!decrypted || !protectedKeys.includes(decrypted)) {
1464
+ if (!decrypted || !protectedLogicalKeys.has(decrypted)) {
1271
1465
  store.delete(k);
1272
1466
  }
1273
1467
  }
@@ -1312,7 +1506,7 @@ class ZIndexDbService {
1312
1506
  const _key = this._shouldEncrypt(storeConfig) ? this._decryptData(key) : key;
1313
1507
  const _value = this._shouldEncrypt(storeConfig) ? this._decryptData(values[index]) : values[index];
1314
1508
  if (_key && _value !== null) {
1315
- results[_key] = _value;
1509
+ results[zStripScopedCacheKey(_key)] = _value;
1316
1510
  }
1317
1511
  }
1318
1512
  catch {
@@ -1356,10 +1550,13 @@ class ZIndexDbService {
1356
1550
  const transaction = this._db.transaction([storeConfig.name], 'readwrite');
1357
1551
  const store = transaction.objectStore(storeConfig.name);
1358
1552
  batch.forEach(([key, value]) => {
1359
- const normalizedKey = this._normalizeKey(key);
1360
- const _key = shouldEncrypt ? this._encryptData(normalizedKey) : normalizedKey;
1553
+ const storageKeys = this._buildStorageKeys(key, shouldEncrypt);
1554
+ const _key = storageKeys[0];
1361
1555
  const _value = shouldEncrypt ? this._encryptData(value) : value;
1362
1556
  store.put(_value, _key);
1557
+ if (storageKeys.length > 1) {
1558
+ store.delete(storageKeys[1]);
1559
+ }
1363
1560
  });
1364
1561
  transaction.oncomplete = () => resolve();
1365
1562
  transaction.onerror = () => reject(transaction.error);
@@ -1386,11 +1583,6 @@ class ZIndexDbService {
1386
1583
  }
1387
1584
  }
1388
1585
 
1389
- const Z_LANG_TO_LOCALE = {
1390
- vi: 'vi-VN',
1391
- en: 'en-US',
1392
- };
1393
-
1394
1586
  const Z_THEME_CONFIG = new InjectionToken('Z_THEME_CONFIG');
1395
1587
  const Z_DEFAULT_THEME = 'neutral';
1396
1588
  /** Single cache key for all theme preferences */
@@ -2237,5 +2429,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImpor
2237
2429
  * Generated bundle index. Do not edit.
2238
2430
  */
2239
2431
 
2240
- export { ZCacheService, ZExcelService, ZHttpAbstractService, ZIndexDbService, ZOverlayContainerService, ZOverlayZIndexService, ZSubjectService, ZThemeService, ZTranslateService, Z_DEFAULT_THEME, Z_EXCEL_BORDER_THIN, Z_EXCEL_CHAR_WIDTH_MAP, Z_EXCEL_COLORS, Z_EXCEL_DEFAULT_CONFIG, Z_EXCEL_FONT_MULTIPLIERS, Z_EXCEL_WIDTH_LIMITS, Z_HTTP_DEFAULT_CONFIG, Z_INDEXDB_BATCH_SIZE, Z_INDEXDB_DEFAULT_CONFIG, Z_INDEXDB_MAX_VERSION, Z_LANG_CACHE_KEY, Z_THEME_CONFIG, Z_THEME_CSS_MAP, Z_THEME_PREFERENCES_CACHE_KEY };
2432
+ export { ZCacheService, ZExcelService, ZHttpAbstractService, ZIndexDbService, ZOverlayContainerService, ZOverlayZIndexService, ZSubjectService, ZThemeService, ZTranslateService, Z_DEFAULT_THEME, Z_EXCEL_BORDER_THIN, Z_EXCEL_CHAR_WIDTH_MAP, Z_EXCEL_COLORS, Z_EXCEL_DEFAULT_CONFIG, Z_EXCEL_FONT_MULTIPLIERS, Z_EXCEL_WIDTH_LIMITS, Z_HTTP_DEFAULT_CONFIG, Z_INDEXDB_BATCH_SIZE, Z_INDEXDB_DEFAULT_CONFIG, Z_INDEXDB_MAX_VERSION, Z_LANG_CACHE_KEY, Z_LANG_TO_LOCALE, Z_THEME_CONFIG, Z_THEME_CSS_MAP, Z_THEME_PREFERENCES_CACHE_KEY, zBuildScopedCacheKey, zBuildScopedDbName, zStripScopedCacheKey };
2241
2433
  //# sourceMappingURL=shival99-z-ui-services.mjs.map