@libs-ui/utils 0.2.8 → 0.2.10-6.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/cache.d.ts +15 -15
- package/communicate-micro.d.ts +5 -4
- package/constants.d.ts +1 -0
- package/encode-url.define.d.ts +1 -0
- package/esm2022/cache.mjs +69 -89
- package/esm2022/communicate-micro.mjs +22 -19
- package/esm2022/constants.mjs +2 -1
- package/esm2022/encode-url.define.mjs +11 -0
- package/esm2022/file.mjs +10 -0
- package/esm2022/format-date.mjs +79 -0
- package/esm2022/helpers.mjs +156 -26
- package/esm2022/http-params.mjs +3 -3
- package/esm2022/index.mjs +6 -1
- package/esm2022/key-cache.mjs +16 -8
- package/esm2022/pattern.mjs +21 -21
- package/esm2022/two-way-signal-object.mjs +59 -0
- package/esm2022/uuid.mjs +3 -2
- package/esm2022/xss-filter.mjs +10 -0
- package/fesm2022/libs-ui-utils.mjs +478 -194
- package/fesm2022/libs-ui-utils.mjs.map +1 -1
- package/file.d.ts +1 -0
- package/format-date.d.ts +6 -0
- package/helpers.d.ts +12 -4
- package/http-params.d.ts +1 -1
- package/index.d.ts +5 -0
- package/package.json +3 -2
- package/pattern.d.ts +20 -20
- package/two-way-signal-object.d.ts +2 -0
- package/xss-filter.d.ts +3 -0
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import { TemplateRef, ElementRef, signal } from '@angular/core';
|
|
2
1
|
import CryptoES from 'crypto-es';
|
|
3
2
|
import { HttpParams } from '@angular/common/http';
|
|
4
|
-
import {
|
|
3
|
+
import { isSignal, TemplateRef, ElementRef, signal } from '@angular/core';
|
|
4
|
+
import { Observable, Subject, fromEvent, takeUntil, filter } from 'rxjs';
|
|
5
|
+
import dayjs from 'dayjs';
|
|
6
|
+
import 'dayjs/locale/vi';
|
|
7
|
+
import 'dayjs/locale/en';
|
|
8
|
+
import localeData from 'dayjs/plugin/localeData';
|
|
9
|
+
import updateLocale from 'dayjs/plugin/updateLocale';
|
|
5
10
|
|
|
6
11
|
const getPlatFromBrowser = () => {
|
|
7
12
|
const userAgent = navigator.userAgent;
|
|
@@ -185,6 +190,42 @@ class UtilsUrlSearchParams {
|
|
|
185
190
|
}
|
|
186
191
|
}
|
|
187
192
|
|
|
193
|
+
let key$1 = '12~@#loqwsxacva(3rdhaq12';
|
|
194
|
+
const setKeyCrypto = (value) => {
|
|
195
|
+
if (value.length !== 24 && value.length !== 32) {
|
|
196
|
+
throw Error(`key.length = ${value.length}; Key phải là 1 chuỗi dài 24 hoặc 32 ký tự`);
|
|
197
|
+
}
|
|
198
|
+
key$1 = value;
|
|
199
|
+
};
|
|
200
|
+
const keyStore$1 = () => {
|
|
201
|
+
return key$1;
|
|
202
|
+
};
|
|
203
|
+
const encrypt = (plainData) => {
|
|
204
|
+
if (!keyStore$1()) {
|
|
205
|
+
throw Error("lỗi chưa setup key mã hóa");
|
|
206
|
+
}
|
|
207
|
+
const key = CryptoES.enc.Hex.parse(keyStore$1());
|
|
208
|
+
const iv = CryptoES.enc.Hex.parse(keyStore$1());
|
|
209
|
+
const mode = CryptoES.mode.CBC;
|
|
210
|
+
const padding = CryptoES.pad.Pkcs7;
|
|
211
|
+
const options = { iv: iv, mode: mode, padding: padding };
|
|
212
|
+
return CryptoES.AES.encrypt(plainData, key, options).toString();
|
|
213
|
+
};
|
|
214
|
+
const decrypt = (encryptedData) => {
|
|
215
|
+
if (!keyStore$1()) {
|
|
216
|
+
throw Error("lỗi chưa setup key mã hóa");
|
|
217
|
+
}
|
|
218
|
+
const key = CryptoES.enc.Hex.parse(keyStore$1());
|
|
219
|
+
const iv = CryptoES.enc.Hex.parse(keyStore$1());
|
|
220
|
+
const mode = CryptoES.mode.CBC;
|
|
221
|
+
const padding = CryptoES.pad.Pkcs7;
|
|
222
|
+
const options = { iv: iv, mode: mode, padding: padding };
|
|
223
|
+
return CryptoES.AES.decrypt(encryptedData, key, options).toString(CryptoES.enc.Utf8);
|
|
224
|
+
};
|
|
225
|
+
const md5 = (plainData) => {
|
|
226
|
+
return CryptoES.MD5(plainData).toString();
|
|
227
|
+
};
|
|
228
|
+
|
|
188
229
|
const uuid = () => {
|
|
189
230
|
const timestamp = performance.now() * 1000;
|
|
190
231
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+-=[]{}|;:,.<>?/~';
|
|
@@ -199,35 +240,60 @@ const uuid = () => {
|
|
|
199
240
|
[charArray[i], charArray[j]] = [charArray[j], charArray[i]];
|
|
200
241
|
}
|
|
201
242
|
const shuffledString = charArray.join('');
|
|
202
|
-
return shuffledString;
|
|
243
|
+
return md5(shuffledString);
|
|
203
244
|
};
|
|
204
245
|
|
|
205
246
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
247
|
+
/**Các hàm tương tự thư viện lodash */
|
|
206
248
|
const isNil = (value) => {
|
|
207
249
|
return value === null || value === undefined;
|
|
208
250
|
};
|
|
209
251
|
const isEmpty = (value) => {
|
|
210
252
|
return value === null || value === '' || value === undefined || (typeof value === 'object' && (JSON.stringify(value) === '{}' || JSON.stringify(value) === '[]'));
|
|
211
253
|
};
|
|
254
|
+
const omitBy = (objData, predicate) => {
|
|
255
|
+
if (!objData || typeof objData !== 'object' || Array.isArray(objData)) {
|
|
256
|
+
return objData;
|
|
257
|
+
}
|
|
258
|
+
const newObj = {};
|
|
259
|
+
Object.keys(objData).forEach(key => {
|
|
260
|
+
const valueOfKey = get(objData, key);
|
|
261
|
+
if (!predicate(valueOfKey)) {
|
|
262
|
+
set(newObj, key, valueOfKey);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
return newObj;
|
|
266
|
+
};
|
|
212
267
|
const get = (obj, path, defaultValue = undefined) => {
|
|
213
268
|
if (obj == null) {
|
|
214
269
|
return defaultValue;
|
|
215
270
|
}
|
|
216
|
-
|
|
271
|
+
if (isSignal(obj)) {
|
|
272
|
+
obj = obj();
|
|
273
|
+
}
|
|
274
|
+
if (obj instanceof HttpParams) {
|
|
275
|
+
return obj.get(`${path}`);
|
|
276
|
+
}
|
|
277
|
+
const paths = Array.isArray(path) ? path : path.replace(/\[(\d+)]/g, '.$1').split('.').filter(key => key);
|
|
217
278
|
for (let i = 0; i < paths.length; i++) {
|
|
218
279
|
if (obj == null || !Object.prototype.hasOwnProperty.call(obj, paths[i])) {
|
|
219
280
|
return defaultValue;
|
|
220
281
|
}
|
|
221
|
-
|
|
282
|
+
const val = isSignal(obj[paths[i]]) ? obj[paths[i]]() : obj[paths[i]];
|
|
283
|
+
obj = val;
|
|
222
284
|
}
|
|
223
285
|
return obj;
|
|
224
286
|
};
|
|
225
287
|
const set = (obj, path, value) => {
|
|
226
|
-
if (!obj || typeof obj !== "object") {
|
|
288
|
+
if (!obj || (typeof obj !== "object" && !isSignal(obj)) || (isSignal(obj) && typeof obj() !== "object")) {
|
|
227
289
|
throw new Error("The first argument must be an object");
|
|
228
290
|
}
|
|
229
|
-
|
|
230
|
-
|
|
291
|
+
if (obj instanceof HttpParams) {
|
|
292
|
+
return obj.set(`${path}`, value);
|
|
293
|
+
}
|
|
294
|
+
const pathArray = Array.isArray(path) ? path : path.replace(/\[(\d+)]/g, '.[$1]').split('.').filter(key => key);
|
|
295
|
+
let current = isSignal(obj) ? obj() : obj;
|
|
296
|
+
let lastIsSignal = false;
|
|
231
297
|
pathArray.forEach((key, index) => {
|
|
232
298
|
if (index < pathArray.length - 1) {
|
|
233
299
|
if (!(key in current) || typeof current[key] !== "object") {
|
|
@@ -235,53 +301,156 @@ const set = (obj, path, value) => {
|
|
|
235
301
|
key = key.replace(/\[(\d+)]/g, '$1');
|
|
236
302
|
current[key] = /\[(\d+)]/g.test(nextKey) ? [] : {};
|
|
237
303
|
}
|
|
238
|
-
current = current[key];
|
|
304
|
+
current = key ? current[key] : current;
|
|
305
|
+
lastIsSignal = isSignal(current);
|
|
306
|
+
current = lastIsSignal ? current() : current;
|
|
239
307
|
return;
|
|
240
308
|
}
|
|
241
309
|
// Gán giá trị ở cuối đường dẫn
|
|
310
|
+
key = key.replace(/\[(\d+)]/g, '$1');
|
|
311
|
+
if (lastIsSignal) {
|
|
312
|
+
current.update((data) => {
|
|
313
|
+
data[key] = value;
|
|
314
|
+
return { ...data };
|
|
315
|
+
});
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
242
318
|
current[key] = value;
|
|
243
319
|
});
|
|
244
320
|
return obj;
|
|
245
321
|
};
|
|
246
|
-
const cloneDeep = (
|
|
247
|
-
if (
|
|
248
|
-
return
|
|
322
|
+
const cloneDeep = (data) => {
|
|
323
|
+
if (data === null || typeof data !== 'object') {
|
|
324
|
+
return data;
|
|
249
325
|
}
|
|
250
|
-
if (
|
|
251
|
-
return
|
|
326
|
+
if (data instanceof HttpParams) {
|
|
327
|
+
return data;
|
|
328
|
+
}
|
|
329
|
+
if (data instanceof Date) {
|
|
330
|
+
return new Date(data.getTime());
|
|
252
331
|
}
|
|
253
|
-
if (
|
|
254
|
-
return new RegExp(
|
|
332
|
+
if (data instanceof RegExp) {
|
|
333
|
+
return new RegExp(data.source, data.flags);
|
|
255
334
|
}
|
|
256
|
-
if (
|
|
335
|
+
if (data instanceof Map) {
|
|
257
336
|
const mapCopy = new Map();
|
|
258
|
-
|
|
337
|
+
data.forEach((val, key) => {
|
|
259
338
|
mapCopy.set(cloneDeep(key), cloneDeep(val));
|
|
260
339
|
});
|
|
261
340
|
return mapCopy;
|
|
262
341
|
}
|
|
263
|
-
if (
|
|
342
|
+
if (data instanceof Set) {
|
|
264
343
|
const setCopy = new Set();
|
|
265
|
-
|
|
344
|
+
data.forEach(val => {
|
|
266
345
|
setCopy.add(cloneDeep(val));
|
|
267
346
|
});
|
|
268
347
|
return setCopy;
|
|
269
348
|
}
|
|
270
|
-
if (Array.isArray(
|
|
271
|
-
return
|
|
349
|
+
if (Array.isArray(data)) {
|
|
350
|
+
return data.map(item => cloneDeep(item));
|
|
351
|
+
}
|
|
352
|
+
if (data instanceof Promise || data instanceof Observable) {
|
|
353
|
+
return data;
|
|
354
|
+
}
|
|
355
|
+
if (isSignal(data)) {
|
|
356
|
+
return cloneDeep(data());
|
|
272
357
|
}
|
|
273
358
|
const result = {};
|
|
274
|
-
for (const key in
|
|
275
|
-
|
|
276
|
-
|
|
359
|
+
for (const key in data) {
|
|
360
|
+
const value = data[key];
|
|
361
|
+
if (value instanceof TemplateRef || value instanceof ElementRef || value instanceof Element || data instanceof Promise || data instanceof Observable || data instanceof HttpParams) {
|
|
362
|
+
result[key] = value;
|
|
277
363
|
continue;
|
|
278
364
|
}
|
|
279
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
280
|
-
result[key] = cloneDeep(value
|
|
365
|
+
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
366
|
+
result[key] = cloneDeep(value);
|
|
281
367
|
}
|
|
282
368
|
}
|
|
283
369
|
return result;
|
|
284
370
|
};
|
|
371
|
+
const keyBy = (data, key) => {
|
|
372
|
+
if (!data || !data.length || !key) {
|
|
373
|
+
return {};
|
|
374
|
+
}
|
|
375
|
+
return data.reduce((dir, nextItem) => {
|
|
376
|
+
const valueOfKey = nextItem[key];
|
|
377
|
+
if (typeof valueOfKey !== 'string' && typeof valueOfKey !== 'number') {
|
|
378
|
+
return dir;
|
|
379
|
+
}
|
|
380
|
+
dir[valueOfKey] = nextItem;
|
|
381
|
+
return dir;
|
|
382
|
+
}, {});
|
|
383
|
+
};
|
|
384
|
+
const groupBy = (data, key) => {
|
|
385
|
+
if (!data || !Object.keys(data).length || !key) {
|
|
386
|
+
return {};
|
|
387
|
+
}
|
|
388
|
+
return data.reduce((dir, nextItem) => {
|
|
389
|
+
const valueOfKey = nextItem[key];
|
|
390
|
+
if (typeof valueOfKey !== 'string' && typeof valueOfKey !== 'number') {
|
|
391
|
+
return dir;
|
|
392
|
+
}
|
|
393
|
+
if (!dir[valueOfKey]) {
|
|
394
|
+
dir[valueOfKey] = [];
|
|
395
|
+
}
|
|
396
|
+
dir[valueOfKey].push(nextItem);
|
|
397
|
+
return dir;
|
|
398
|
+
}, {});
|
|
399
|
+
};
|
|
400
|
+
const range = (start, end, step) => {
|
|
401
|
+
if (end === undefined || end === null) {
|
|
402
|
+
end = start;
|
|
403
|
+
start = 0;
|
|
404
|
+
}
|
|
405
|
+
if (!step) {
|
|
406
|
+
step = end < 0 ? -1 : 1;
|
|
407
|
+
}
|
|
408
|
+
if (end < start && step > 0) {
|
|
409
|
+
step *= -1;
|
|
410
|
+
}
|
|
411
|
+
const valueStartByStep = step + start;
|
|
412
|
+
const direction = start < end ? 'asc' : 'desc';
|
|
413
|
+
if ((direction === 'asc' && (valueStartByStep < start || valueStartByStep > end)) || (direction === 'desc' && (valueStartByStep > start || valueStartByStep < end))) {
|
|
414
|
+
return [start];
|
|
415
|
+
}
|
|
416
|
+
const arr = new Array();
|
|
417
|
+
for (let index = 0; index < Math.abs(end - start); index++) {
|
|
418
|
+
let value = start + index * step;
|
|
419
|
+
if (index === 0) {
|
|
420
|
+
value = start;
|
|
421
|
+
}
|
|
422
|
+
if ((direction === 'asc' && (value < start || value > end)) || (direction === 'desc' && (value > start || value < end))) {
|
|
423
|
+
return arr;
|
|
424
|
+
}
|
|
425
|
+
arr.push(value);
|
|
426
|
+
}
|
|
427
|
+
return arr;
|
|
428
|
+
};
|
|
429
|
+
const isEqual = (value1, value2) => {
|
|
430
|
+
if (value1 === value2 || (value1 === null && value2 === null) || (value1 === undefined && value2 === undefined)) {
|
|
431
|
+
return true;
|
|
432
|
+
}
|
|
433
|
+
if (typeof value1 !== 'object' || typeof value2 !== 'object' || (Array.isArray(value1) && !Array.isArray(value2))) {
|
|
434
|
+
return false;
|
|
435
|
+
}
|
|
436
|
+
if (Array.isArray(value1)) {
|
|
437
|
+
if (value1.length !== value2.length) {
|
|
438
|
+
return false;
|
|
439
|
+
}
|
|
440
|
+
return !value1.some((item, index) => !isEqual(item, value2[index]));
|
|
441
|
+
}
|
|
442
|
+
if (Object.keys(value1).length !== Object.keys(value2).length) {
|
|
443
|
+
return false;
|
|
444
|
+
}
|
|
445
|
+
return !Object.keys(value1).some((key) => !isEqual(value1[key], value2[key]));
|
|
446
|
+
};
|
|
447
|
+
const uniqBy = (data, key) => {
|
|
448
|
+
if (!key || !data || !data.length || typeof data[0] !== 'object') {
|
|
449
|
+
return Array.from(new Set(data));
|
|
450
|
+
}
|
|
451
|
+
const dataUnique = keyBy(data, key);
|
|
452
|
+
return Object.keys(dataUnique).map(key => dataUnique[key]);
|
|
453
|
+
};
|
|
285
454
|
const generateInterface = (obj, interfaceName) => {
|
|
286
455
|
const generateType = (value) => {
|
|
287
456
|
if (value === null) {
|
|
@@ -410,42 +579,6 @@ const GetColorById = (str) => {
|
|
|
410
579
|
return listColorDefine$1[Math.abs(hashString) % listColorDefine$1.length];
|
|
411
580
|
};
|
|
412
581
|
|
|
413
|
-
let key$1 = '12~@#loqwsxacva(3rdhaq12';
|
|
414
|
-
const setKeyCrypto = (value) => {
|
|
415
|
-
if (value.length !== 24 && value.length !== 32) {
|
|
416
|
-
throw Error(`key.length = ${value.length}; Key phải là 1 chuỗi dài 24 hoặc 32 ký tự`);
|
|
417
|
-
}
|
|
418
|
-
key$1 = value;
|
|
419
|
-
};
|
|
420
|
-
const keyStore$1 = () => {
|
|
421
|
-
return key$1;
|
|
422
|
-
};
|
|
423
|
-
const encrypt = (plainData) => {
|
|
424
|
-
if (!keyStore$1()) {
|
|
425
|
-
throw Error("lỗi chưa setup key mã hóa");
|
|
426
|
-
}
|
|
427
|
-
const key = CryptoES.enc.Hex.parse(keyStore$1());
|
|
428
|
-
const iv = CryptoES.enc.Hex.parse(keyStore$1());
|
|
429
|
-
const mode = CryptoES.mode.CBC;
|
|
430
|
-
const padding = CryptoES.pad.Pkcs7;
|
|
431
|
-
const options = { iv: iv, mode: mode, padding: padding };
|
|
432
|
-
return CryptoES.AES.encrypt(plainData, key, options).toString();
|
|
433
|
-
};
|
|
434
|
-
const decrypt = (encryptedData) => {
|
|
435
|
-
if (!keyStore$1()) {
|
|
436
|
-
throw Error("lỗi chưa setup key mã hóa");
|
|
437
|
-
}
|
|
438
|
-
const key = CryptoES.enc.Hex.parse(keyStore$1());
|
|
439
|
-
const iv = CryptoES.enc.Hex.parse(keyStore$1());
|
|
440
|
-
const mode = CryptoES.mode.CBC;
|
|
441
|
-
const padding = CryptoES.pad.Pkcs7;
|
|
442
|
-
const options = { iv: iv, mode: mode, padding: padding };
|
|
443
|
-
return CryptoES.AES.decrypt(encryptedData, key, options).toString(CryptoES.enc.Utf8);
|
|
444
|
-
};
|
|
445
|
-
const md5 = (plainData) => {
|
|
446
|
-
return CryptoES.MD5(plainData).toString();
|
|
447
|
-
};
|
|
448
|
-
|
|
449
582
|
let key = '12~@#loqwsxacva(3rdhaq12';
|
|
450
583
|
const setKeyCrypto3rd = (value) => {
|
|
451
584
|
if (value.length !== 24 && value.length !== 32) {
|
|
@@ -602,11 +735,11 @@ class UtilsKeyCodeConstant {
|
|
|
602
735
|
}
|
|
603
736
|
|
|
604
737
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
605
|
-
const
|
|
738
|
+
const UtilsHttpParamsRequestInstance = (options, instance) => {
|
|
606
739
|
return new UtilsHttpParamsRequest(options, instance);
|
|
607
740
|
};
|
|
608
741
|
class UtilsHttpParamsRequest extends HttpParams {
|
|
609
|
-
params;
|
|
742
|
+
params = new HttpParams();
|
|
610
743
|
constructor(options, instance) {
|
|
611
744
|
super(options);
|
|
612
745
|
if (!instance) {
|
|
@@ -680,13 +813,20 @@ const getKeyCacheByArrayObject = (keyCache, argumentsValue) => {
|
|
|
680
813
|
return '';
|
|
681
814
|
}
|
|
682
815
|
let keyBuild = `${JSON.stringify(argumentsValue.slice(1))}-key-cache-plus`;
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
816
|
+
argumentsValue.forEach((item) => {
|
|
817
|
+
if (typeof item === 'object') {
|
|
818
|
+
if (Array.isArray(item)) {
|
|
819
|
+
keyBuild = `${keyBuild}${JSON.stringify(item)}`;
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
const keys = (item instanceof HttpParams ? item.keys() : Object.keys(item)).sort(((str1, str2) => str1.localeCompare(str2)));
|
|
823
|
+
keys.forEach(key => {
|
|
824
|
+
keyBuild = `${keyBuild}${JSON.stringify(get(item, key))}`;
|
|
825
|
+
});
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
keyBuild = `${keyBuild}${item}`;
|
|
829
|
+
});
|
|
690
830
|
const keyCachePlus = md5(keyBuild);
|
|
691
831
|
const keyCacheMD5 = md5(keyCache);
|
|
692
832
|
return `${keyCacheMD5}-${md5(`${keyCacheMD5}-${keyCachePlus}`)}`;
|
|
@@ -703,13 +843,16 @@ const isEmbedFrame = () => {
|
|
|
703
843
|
};
|
|
704
844
|
|
|
705
845
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
846
|
+
class UtilsCommunicateMicroKeyGlobal {
|
|
847
|
+
static KEY_MESSAGE_MODAL = 'LIBS_UI_MODEL_EVENT';
|
|
848
|
+
}
|
|
706
849
|
class UtilsCommunicateMicro {
|
|
707
|
-
static KEY_GET_ALL_MESSAGE = 'MICRO_SITES_ALL_MESSAGE';
|
|
708
850
|
static PREFIX_TYPE = '3RD_INTEGRATE_MICRO_SITE_';
|
|
851
|
+
static KEY_GET_ALL_MESSAGE = 'MICRO_SITES_ALL_MESSAGE';
|
|
709
852
|
static initdEvent;
|
|
710
853
|
static subs = new Map();
|
|
711
854
|
static allMessageSub = new Subject();
|
|
712
|
-
static initEvent(currentWindow) {
|
|
855
|
+
static initEvent(currentWindow, onDestroy) {
|
|
713
856
|
if (this.initdEvent) {
|
|
714
857
|
return;
|
|
715
858
|
}
|
|
@@ -717,7 +860,7 @@ class UtilsCommunicateMicro {
|
|
|
717
860
|
if (!this.subs.get(UtilsCommunicateMicro.KEY_GET_ALL_MESSAGE)) {
|
|
718
861
|
this.subs.set(UtilsCommunicateMicro.KEY_GET_ALL_MESSAGE, UtilsCommunicateMicro.allMessageSub);
|
|
719
862
|
}
|
|
720
|
-
fromEvent(currentWindow, 'message').subscribe(e => {
|
|
863
|
+
fromEvent(currentWindow, 'message').pipe(takeUntil(onDestroy)).subscribe(e => {
|
|
721
864
|
const event = { data: { ...e.data } };
|
|
722
865
|
const data = event.data;
|
|
723
866
|
const type = data.type;
|
|
@@ -745,6 +888,10 @@ class UtilsCommunicateMicro {
|
|
|
745
888
|
this.allMessageSub.next(event);
|
|
746
889
|
}
|
|
747
890
|
});
|
|
891
|
+
UtilsCommunicateMicro.GetMessage(UtilsCache.typeKeyClearLocalStorage).pipe(filter(e => e.data.response !== UtilsCache.idService), takeUntil(onDestroy)).subscribe(() => {
|
|
892
|
+
console.log('clear all cache by event');
|
|
893
|
+
UtilsCache.ClearAll();
|
|
894
|
+
});
|
|
748
895
|
}
|
|
749
896
|
static PostMessageToParent(data) {
|
|
750
897
|
data = this.convertData(data);
|
|
@@ -784,9 +931,8 @@ class UtilsCommunicateMicro {
|
|
|
784
931
|
JSON.parse(decrypt3rd(data.response));
|
|
785
932
|
return data;
|
|
786
933
|
}
|
|
787
|
-
catch (
|
|
788
|
-
|
|
789
|
-
data.response = decrypt3rd(JSON.stringify(data.response));
|
|
934
|
+
catch (_) {
|
|
935
|
+
data.response = encrypt3rd(JSON.stringify(data.response));
|
|
790
936
|
return data;
|
|
791
937
|
}
|
|
792
938
|
}
|
|
@@ -794,9 +940,8 @@ class UtilsCommunicateMicro {
|
|
|
794
940
|
JSON.parse(decrypt(data.response));
|
|
795
941
|
return data;
|
|
796
942
|
}
|
|
797
|
-
catch (
|
|
798
|
-
|
|
799
|
-
data.response = decrypt(JSON.stringify(data.response));
|
|
943
|
+
catch (_) {
|
|
944
|
+
data.response = encrypt(JSON.stringify(data.response));
|
|
800
945
|
return data;
|
|
801
946
|
}
|
|
802
947
|
}
|
|
@@ -816,6 +961,9 @@ class UtilsCommunicateMicro {
|
|
|
816
961
|
if (!Array.isArray(messageType) || !messageType.length) {
|
|
817
962
|
throw new Error('message type empty');
|
|
818
963
|
}
|
|
964
|
+
if (messageType.length === 1) {
|
|
965
|
+
return this.GetMessage(messageType[0]);
|
|
966
|
+
}
|
|
819
967
|
const types = messageType.sort().join(';');
|
|
820
968
|
let sub = this.subs.get(types);
|
|
821
969
|
if (sub) {
|
|
@@ -833,25 +981,18 @@ class UtilsCommunicateMicro {
|
|
|
833
981
|
});
|
|
834
982
|
});
|
|
835
983
|
}
|
|
836
|
-
postMessageToParent(data) {
|
|
837
|
-
UtilsCommunicateMicro.PostMessageToParent(data);
|
|
838
|
-
}
|
|
839
|
-
postMessageToChildren(data) {
|
|
840
|
-
UtilsCommunicateMicro.PostMessageToChildren(data);
|
|
841
|
-
}
|
|
842
984
|
}
|
|
843
985
|
|
|
844
986
|
/* eslint-disable no-async-promise-executor */
|
|
845
987
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
846
988
|
class UtilsCache {
|
|
847
|
-
static typeKeyClearLocalStorage = 'LIBS_UI_CLEAR_LOCAL_STORAGE_EVENT';
|
|
848
|
-
static listKeyKeepWhenClearALll = Array();
|
|
849
|
-
static languageKeyCache = 'SR3xQKxHgffiCevPQRralg';
|
|
850
|
-
static initdEvent;
|
|
851
989
|
static CACHE_EXPIRE_TIME_DEFAULT = 5 * 60;
|
|
852
990
|
static CACHE_EXPIRE_NONE = -1;
|
|
853
|
-
static language = signal(UtilsLanguageConstants.defaultLang);
|
|
854
991
|
static idService = uuid();
|
|
992
|
+
static typeKeyClearLocalStorage = 'LIBS_UI_CLEAR_LOCAL_STORAGE_EVENT';
|
|
993
|
+
static languageKeyCache = 'SR3xQKxHgffiCevPQRralg';
|
|
994
|
+
static listKeyKeepWhenClearALll = Array();
|
|
995
|
+
static initdEvent;
|
|
855
996
|
static storage;
|
|
856
997
|
static dbName = 'libs-ui-cache';
|
|
857
998
|
static itemIndexByKey = 'key';
|
|
@@ -868,25 +1009,21 @@ class UtilsCache {
|
|
|
868
1009
|
if (config.typeKeyClearLocalStorage) {
|
|
869
1010
|
UtilsCache.typeKeyClearLocalStorage = config.typeKeyClearLocalStorage;
|
|
870
1011
|
}
|
|
871
|
-
if (config.
|
|
872
|
-
UtilsCache.listKeyKeepWhenClearALll = config.
|
|
1012
|
+
if (config.listKeyKeepWhenClearAll) {
|
|
1013
|
+
UtilsCache.listKeyKeepWhenClearALll = config.listKeyKeepWhenClearAll;
|
|
873
1014
|
}
|
|
874
1015
|
if (config.languageKeyCache) {
|
|
875
1016
|
UtilsCache.languageKeyCache = config.languageKeyCache;
|
|
876
1017
|
}
|
|
877
|
-
UtilsCommunicateMicro.GetMessage(UtilsCache.typeKeyClearLocalStorage).pipe(filter(e => e.data.response !== UtilsCache.idService)).subscribe(() => {
|
|
878
|
-
UtilsCache.ClearAll();
|
|
879
|
-
});
|
|
880
1018
|
}
|
|
881
1019
|
static setLang(lang) {
|
|
882
1020
|
if (lang !== UtilsLanguageConstants.VI && lang !== UtilsLanguageConstants.EN) {
|
|
883
1021
|
throw Error('Language support vi | en');
|
|
884
1022
|
}
|
|
885
|
-
UtilsCache.
|
|
886
|
-
UtilsCache.Set(UtilsCache.languageKeyCache, lang);
|
|
1023
|
+
UtilsCache.Set(UtilsCache.languageKeyCache, lang, UtilsCache.CACHE_EXPIRE_NONE);
|
|
887
1024
|
}
|
|
888
1025
|
static getLang() {
|
|
889
|
-
return UtilsCache.
|
|
1026
|
+
return UtilsCache.Get(UtilsCache.languageKeyCache, UtilsLanguageConstants.defaultLang);
|
|
890
1027
|
}
|
|
891
1028
|
static openDB() {
|
|
892
1029
|
return new Promise(resolve => {
|
|
@@ -894,15 +1031,12 @@ class UtilsCache {
|
|
|
894
1031
|
request.onupgradeneeded = (event) => {
|
|
895
1032
|
const db = event.target.result;
|
|
896
1033
|
if (!db.objectStoreNames.contains(UtilsCache.dbName)) {
|
|
897
|
-
const objectStore = db.createObjectStore(UtilsCache.dbName, { keyPath:
|
|
1034
|
+
const objectStore = db.createObjectStore(UtilsCache.dbName, { keyPath: UtilsCache.itemIndexByKey, autoIncrement: true });
|
|
898
1035
|
objectStore.createIndex(UtilsCache.itemIndexByKey, UtilsCache.itemIndexByKey, { unique: true });
|
|
899
1036
|
}
|
|
900
1037
|
};
|
|
901
1038
|
request.onsuccess = () => {
|
|
902
1039
|
UtilsCache.db = request.result;
|
|
903
|
-
setTimeout(() => {
|
|
904
|
-
UtilsCache.DeleteKeyStartWithAsync('');
|
|
905
|
-
}, 2000);
|
|
906
1040
|
resolve(true);
|
|
907
1041
|
};
|
|
908
1042
|
request.onerror = (event) => {
|
|
@@ -916,7 +1050,10 @@ class UtilsCache {
|
|
|
916
1050
|
await UtilsCache.openDB();
|
|
917
1051
|
}
|
|
918
1052
|
const transaction = UtilsCache.db?.transaction([UtilsCache.dbName], 'readwrite');
|
|
919
|
-
|
|
1053
|
+
if (!transaction) {
|
|
1054
|
+
return null;
|
|
1055
|
+
}
|
|
1056
|
+
return transaction.objectStore(UtilsCache.dbName);
|
|
920
1057
|
}
|
|
921
1058
|
static get LocalStorage() {
|
|
922
1059
|
try {
|
|
@@ -990,8 +1127,7 @@ class UtilsCache {
|
|
|
990
1127
|
if (!objectStore) {
|
|
991
1128
|
return resolve(default_value);
|
|
992
1129
|
}
|
|
993
|
-
const
|
|
994
|
-
const request = index.get(key);
|
|
1130
|
+
const request = objectStore.get(key);
|
|
995
1131
|
request.onsuccess = () => {
|
|
996
1132
|
if (!request.result) {
|
|
997
1133
|
return resolve(default_value);
|
|
@@ -1022,7 +1158,7 @@ class UtilsCache {
|
|
|
1022
1158
|
try {
|
|
1023
1159
|
const data = JSON.parse(decrypt(cachedData));
|
|
1024
1160
|
if (data.expire === UtilsCache.CACHE_EXPIRE_NONE) {
|
|
1025
|
-
return data.value;
|
|
1161
|
+
return data.value ?? default_value;
|
|
1026
1162
|
}
|
|
1027
1163
|
const currentMillisecond = (new Date().valueOf() / 1000);
|
|
1028
1164
|
if (data.expire < currentMillisecond) {
|
|
@@ -1040,52 +1176,31 @@ class UtilsCache {
|
|
|
1040
1176
|
}
|
|
1041
1177
|
static async SetAsync(key, value, expireTimeBySecond = UtilsCache.CACHE_EXPIRE_TIME_DEFAULT, isKeyMD5 = false) {
|
|
1042
1178
|
return new Promise(async (resolve, reject) => {
|
|
1043
|
-
|
|
1179
|
+
const objectStore = await UtilsCache.getObjectStore();
|
|
1044
1180
|
key = isKeyMD5 ? key : md5(key);
|
|
1045
1181
|
try {
|
|
1046
1182
|
const currentMillisecond = expireTimeBySecond === UtilsCache.CACHE_EXPIRE_NONE ? UtilsCache.CACHE_EXPIRE_NONE : (new Date().valueOf() / 1000) + expireTimeBySecond;
|
|
1047
1183
|
const data = {
|
|
1048
|
-
key: key,
|
|
1049
1184
|
value: encrypt(JSON.stringify({ json: value, expire: currentMillisecond })),
|
|
1050
1185
|
};
|
|
1186
|
+
data[UtilsCache.itemIndexByKey] = key;
|
|
1051
1187
|
if (!objectStore) {
|
|
1052
|
-
return
|
|
1188
|
+
return reject(new Error('Can not open object store'));
|
|
1053
1189
|
}
|
|
1054
|
-
const
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
const item = getIndexKeyRequest.result;
|
|
1058
|
-
if (item) {
|
|
1059
|
-
await UtilsCache.ClearAsync(key, true);
|
|
1060
|
-
objectStore = await UtilsCache.getObjectStore();
|
|
1061
|
-
}
|
|
1062
|
-
if (!objectStore) {
|
|
1063
|
-
return resolve(-1);
|
|
1064
|
-
}
|
|
1065
|
-
const request = objectStore.add(data);
|
|
1066
|
-
request.onsuccess = () => {
|
|
1067
|
-
resolve(request.result);
|
|
1068
|
-
};
|
|
1069
|
-
request.onerror = () => {
|
|
1070
|
-
console.log(request.error);
|
|
1071
|
-
return resolve(-1);
|
|
1072
|
-
};
|
|
1190
|
+
const request = objectStore?.put(data);
|
|
1191
|
+
request.onsuccess = () => {
|
|
1192
|
+
resolve(request.result);
|
|
1073
1193
|
};
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
reject(event.target.error);
|
|
1194
|
+
request.onerror = () => {
|
|
1195
|
+
reject(request.error);
|
|
1077
1196
|
};
|
|
1078
1197
|
}
|
|
1079
1198
|
catch (error) {
|
|
1080
|
-
|
|
1081
|
-
resolve({});
|
|
1199
|
+
reject(error);
|
|
1082
1200
|
}
|
|
1083
1201
|
});
|
|
1084
1202
|
}
|
|
1085
1203
|
static Set(key, value, expireTimeBySecond = UtilsCache.CACHE_EXPIRE_TIME_DEFAULT) {
|
|
1086
|
-
if (value === undefined || value === null || value === '') {
|
|
1087
|
-
return;
|
|
1088
|
-
}
|
|
1089
1204
|
const currentMillisecond = expireTimeBySecond === UtilsCache.CACHE_EXPIRE_NONE ? UtilsCache.CACHE_EXPIRE_NONE : (new Date().valueOf() / 1000) + expireTimeBySecond;
|
|
1090
1205
|
const data = {
|
|
1091
1206
|
value: value,
|
|
@@ -1093,35 +1208,25 @@ class UtilsCache {
|
|
|
1093
1208
|
};
|
|
1094
1209
|
try {
|
|
1095
1210
|
this.LocalStorage.setItem(key, encrypt(JSON.stringify(data)));
|
|
1211
|
+
return true;
|
|
1096
1212
|
}
|
|
1097
1213
|
catch (error) {
|
|
1098
1214
|
console.log(error);
|
|
1215
|
+
return false;
|
|
1099
1216
|
}
|
|
1100
1217
|
}
|
|
1101
1218
|
static async ClearAsync(key, isMD5 = false) {
|
|
1102
1219
|
return new Promise(async (resolve) => {
|
|
1103
1220
|
const objectStore = await UtilsCache.getObjectStore();
|
|
1104
1221
|
if (!objectStore) {
|
|
1105
|
-
return resolve(
|
|
1222
|
+
return resolve();
|
|
1106
1223
|
}
|
|
1107
|
-
const
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
const result = getRequest.result;
|
|
1111
|
-
if (result) {
|
|
1112
|
-
const deleteRequest = objectStore.delete(result.id); // Xóa theo id của item tìm được
|
|
1113
|
-
deleteRequest.onsuccess = () => {
|
|
1114
|
-
resolve({});
|
|
1115
|
-
};
|
|
1116
|
-
deleteRequest.onerror = () => {
|
|
1117
|
-
resolve({});
|
|
1118
|
-
};
|
|
1119
|
-
return;
|
|
1120
|
-
}
|
|
1121
|
-
resolve({});
|
|
1224
|
+
const request = objectStore.delete(isMD5 ? key : md5(key));
|
|
1225
|
+
request.onsuccess = () => {
|
|
1226
|
+
resolve();
|
|
1122
1227
|
};
|
|
1123
|
-
|
|
1124
|
-
resolve(
|
|
1228
|
+
request.onerror = () => {
|
|
1229
|
+
resolve();
|
|
1125
1230
|
};
|
|
1126
1231
|
});
|
|
1127
1232
|
}
|
|
@@ -1132,22 +1237,32 @@ class UtilsCache {
|
|
|
1132
1237
|
this.LocalStorage.removeItem(key);
|
|
1133
1238
|
}
|
|
1134
1239
|
static ClearAllAsync() {
|
|
1135
|
-
return new Promise((resolve, reject) => {
|
|
1136
|
-
const
|
|
1240
|
+
return new Promise(async (resolve, reject) => {
|
|
1241
|
+
const objectStore = await UtilsCache.getObjectStore();
|
|
1242
|
+
if (!objectStore) {
|
|
1243
|
+
return resolve();
|
|
1244
|
+
}
|
|
1245
|
+
const request = objectStore.clear();
|
|
1137
1246
|
request.onsuccess = () => {
|
|
1138
1247
|
console.log('Database deleted successfully');
|
|
1139
|
-
resolve(
|
|
1248
|
+
resolve();
|
|
1140
1249
|
};
|
|
1141
1250
|
request.onerror = (event) => {
|
|
1142
1251
|
console.error('Error deleting database:', event.target.error);
|
|
1143
1252
|
reject(event.target.error);
|
|
1144
1253
|
};
|
|
1145
|
-
request.onblocked = () => {
|
|
1146
|
-
console.warn('Delete request is blocked');
|
|
1147
|
-
};
|
|
1148
1254
|
});
|
|
1149
1255
|
}
|
|
1150
1256
|
static ClearAll() {
|
|
1257
|
+
if (isEmbedFrame()) {
|
|
1258
|
+
const data = {
|
|
1259
|
+
type: UtilsCache.typeKeyClearLocalStorage,
|
|
1260
|
+
response: {
|
|
1261
|
+
idEvent: this.idService
|
|
1262
|
+
}
|
|
1263
|
+
};
|
|
1264
|
+
UtilsCommunicateMicro.PostMessageToParent(data);
|
|
1265
|
+
}
|
|
1151
1266
|
const keys = [...UtilsCache.listKeyKeepWhenClearALll];
|
|
1152
1267
|
Object.keys(this.LocalStorage).forEach(key => {
|
|
1153
1268
|
if (key.includes('kc-callback-')) {
|
|
@@ -1157,13 +1272,6 @@ class UtilsCache {
|
|
|
1157
1272
|
const stores = UtilsCache.GetDataByKeys(Array.from(keys));
|
|
1158
1273
|
this.LocalStorage.clear();
|
|
1159
1274
|
UtilsCache.SetDataByKey(stores);
|
|
1160
|
-
const data = {
|
|
1161
|
-
type: UtilsCache.typeKeyClearLocalStorage,
|
|
1162
|
-
response: {
|
|
1163
|
-
idEvent: this.idService
|
|
1164
|
-
}
|
|
1165
|
-
};
|
|
1166
|
-
UtilsCommunicateMicro.PostMessageToParent(data);
|
|
1167
1275
|
}
|
|
1168
1276
|
static GetDataByKeys(keys) {
|
|
1169
1277
|
const stores = new Map();
|
|
@@ -1194,9 +1302,8 @@ class UtilsCache {
|
|
|
1194
1302
|
if (!objectStore) {
|
|
1195
1303
|
return resolve({});
|
|
1196
1304
|
}
|
|
1197
|
-
const index = objectStore.index(UtilsCache.itemIndexByKey);
|
|
1198
1305
|
// Lấy tất cả các keys từ index
|
|
1199
|
-
const request =
|
|
1306
|
+
const request = objectStore.getAll();
|
|
1200
1307
|
keyCacheStartWith = isKeyMD5 ? keyCacheStartWith : md5(keyCacheStartWith);
|
|
1201
1308
|
request.onsuccess = (e) => {
|
|
1202
1309
|
const data = e.target.result;
|
|
@@ -1204,8 +1311,8 @@ class UtilsCache {
|
|
|
1204
1311
|
return resolve({});
|
|
1205
1312
|
}
|
|
1206
1313
|
data.forEach(obj => {
|
|
1207
|
-
if (obj.
|
|
1208
|
-
UtilsCache.ClearAsync(obj.
|
|
1314
|
+
if (obj[UtilsCache.itemIndexByKey].startsWith(keyCacheStartWith)) {
|
|
1315
|
+
UtilsCache.ClearAsync(obj[UtilsCache.itemIndexByKey], true);
|
|
1209
1316
|
}
|
|
1210
1317
|
});
|
|
1211
1318
|
return resolve({});
|
|
@@ -1227,6 +1334,22 @@ class UtilsCache {
|
|
|
1227
1334
|
}
|
|
1228
1335
|
});
|
|
1229
1336
|
}
|
|
1337
|
+
static DeleteDatabaseIndexDB(dbName) {
|
|
1338
|
+
return new Promise((resolve, reject) => {
|
|
1339
|
+
const request = indexedDB.deleteDatabase(dbName);
|
|
1340
|
+
request.onsuccess = () => {
|
|
1341
|
+
console.log('Database deleted successfully');
|
|
1342
|
+
resolve(true);
|
|
1343
|
+
};
|
|
1344
|
+
request.onerror = (event) => {
|
|
1345
|
+
console.error('Error deleting database:', event.target.error);
|
|
1346
|
+
reject(event.target.error);
|
|
1347
|
+
};
|
|
1348
|
+
request.onblocked = () => {
|
|
1349
|
+
console.warn('Delete request is blocked');
|
|
1350
|
+
};
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1230
1353
|
}
|
|
1231
1354
|
|
|
1232
1355
|
const formatNumber = (value) => {
|
|
@@ -1355,72 +1478,233 @@ const ERROR_MESSAGE_MAX_VALID = 'i18n_message_error_input_max_value';
|
|
|
1355
1478
|
const ERROR_MESSAGE_MIN_LENGTH = 'i18n_message_error_input_min_length';
|
|
1356
1479
|
const ERROR_MESSAGE_MAX_LENGTH = 'i18n_message_error_input_max_length';
|
|
1357
1480
|
const CHARACTER_DATA_EMPTY = '__';
|
|
1481
|
+
const DEFAULT_START_PAGE_0 = 'defaultStartPage0';
|
|
1358
1482
|
|
|
1359
1483
|
/* eslint-disable no-useless-escape */
|
|
1360
|
-
const
|
|
1484
|
+
const patternEmail = () => {
|
|
1361
1485
|
return /^[A-z0-9]+[A-z0-9\_\.\+\-]*[A-z0-9]@[A-z0-9]+[A-z0-9\_\.\+\-]*[A-z0-9]\.[A-z0-9]+[A-z0-9\_\.\+\-]*[A-z0-9]$/;
|
|
1362
1486
|
};
|
|
1363
|
-
const
|
|
1487
|
+
const patternUrl = () => {
|
|
1364
1488
|
return /^(http|https|ftp):(\/){2}[^\s]+[.]{1}[^\s]+$/;
|
|
1365
1489
|
};
|
|
1366
|
-
const
|
|
1490
|
+
const patternHostUrl = () => {
|
|
1367
1491
|
return /^((https|http|ftp):[/]{2}[^/\s]+)/;
|
|
1368
1492
|
};
|
|
1369
|
-
const
|
|
1493
|
+
const patternDomain = () => {
|
|
1370
1494
|
return /^([a-zA-Z0-9])(([a-z0-9-]{1,61})?[a-z0-9]{1})?(\.[a-z0-9](([a-z0-9-]{1,61})?[a-z0-9]{1})?)?(\.[a-zA-Z]{2,4})+$/;
|
|
1371
1495
|
};
|
|
1372
|
-
const
|
|
1496
|
+
const patternMobilePhone = () => {
|
|
1373
1497
|
return /^(\+?84|0|84)([0-9]{9})$/;
|
|
1374
1498
|
};
|
|
1375
|
-
const
|
|
1499
|
+
const patternPhone = () => {
|
|
1376
1500
|
return /^(\+?84|[0-9]|84)([0-9]{2,9})$/;
|
|
1377
1501
|
};
|
|
1378
|
-
const
|
|
1502
|
+
const patternPhoneNormal = () => {
|
|
1379
1503
|
return /^(\+?84|[0-9]|84)([0-9]{9,10})$/;
|
|
1380
1504
|
};
|
|
1381
|
-
const
|
|
1505
|
+
const patternNumber = () => {
|
|
1382
1506
|
return /\d+/g;
|
|
1383
1507
|
};
|
|
1384
|
-
const
|
|
1508
|
+
const patternEncodeUri = () => {
|
|
1385
1509
|
return /%([0-9A-F]{2})/g;
|
|
1386
1510
|
};
|
|
1387
|
-
const
|
|
1511
|
+
const patternName = () => {
|
|
1388
1512
|
return /^\w+[A-Za-z\s\d]+$/;
|
|
1389
1513
|
};
|
|
1390
|
-
const
|
|
1514
|
+
const patternNameUtf8 = () => {
|
|
1391
1515
|
return /^[ àáảãạăắằẵặẳâầấậẫẩđèéẻẽẹêềếểễệìíỉĩịòóỏõọôồốổỗộơờớởỡợùúủũụưừứửữựỳýỷỹÀÁẢÃẠĂẮẰẴẶẲÂẦẤẬẪẨĐÈÉẺẼẸÊỀẾỂỄỆÌÍỈĨỊÒÓỎÕỌÔỒỐỔỖỘƠỜỚỞỠỢÙÚỦŨỤƯỪỨỬỮỰỲÝỶỸA-Za-z0-9]+$/;
|
|
1392
1516
|
};
|
|
1393
|
-
const
|
|
1517
|
+
const patternNameSpecial = () => {
|
|
1394
1518
|
return /[~!@#$%^&*()-+=<>,?\/\\:;"']/;
|
|
1395
1519
|
};
|
|
1396
|
-
const
|
|
1520
|
+
const patternNameProfile = () => {
|
|
1397
1521
|
return /([\w\W\d\s]+)+/;
|
|
1398
1522
|
};
|
|
1399
|
-
const
|
|
1523
|
+
const patternEmoji = () => {
|
|
1400
1524
|
return /(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/g;
|
|
1401
1525
|
};
|
|
1402
|
-
const
|
|
1526
|
+
const patternRuleFieldReplace = () => {
|
|
1403
1527
|
return /[{]{2}[a-zA-Z_-]+[}]{2}/g;
|
|
1404
1528
|
};
|
|
1405
|
-
const
|
|
1529
|
+
const patternGetFieldByRuleFieldReplace = () => {
|
|
1406
1530
|
return /[a-zA-Z_-]+/g;
|
|
1407
1531
|
};
|
|
1408
|
-
const
|
|
1532
|
+
const patternPem = () => {
|
|
1409
1533
|
return /^(0|1):([0-9]{1,2}):(\{\{path-api\}\}):([a-zA-Z0-9\/]+)$/g;
|
|
1410
1534
|
};
|
|
1411
|
-
const
|
|
1535
|
+
const patternTax = () => {
|
|
1412
1536
|
return /^([0-9]){10}(-[0-9]{3})?$/;
|
|
1413
1537
|
};
|
|
1414
|
-
const
|
|
1538
|
+
const patternKey = () => {
|
|
1415
1539
|
return /^([0-9]){10}(-[0-9]{3})?$/;
|
|
1416
1540
|
};
|
|
1417
|
-
const
|
|
1541
|
+
const patternAccount = () => {
|
|
1418
1542
|
return /^(?=.*@)[a-z0-9@._-]{2,63}$/;
|
|
1419
1543
|
};
|
|
1420
1544
|
|
|
1545
|
+
let functionXssFilter = async (value) => {
|
|
1546
|
+
return value;
|
|
1547
|
+
};
|
|
1548
|
+
const updateFunctionXssFilter = (functionCustom) => {
|
|
1549
|
+
functionXssFilter = functionCustom;
|
|
1550
|
+
};
|
|
1551
|
+
const xssFilter = async (data) => {
|
|
1552
|
+
return await functionXssFilter(data);
|
|
1553
|
+
};
|
|
1554
|
+
|
|
1555
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1556
|
+
const convertObjectToSignal = (data, isCloneDeep = true) => {
|
|
1557
|
+
if (data === null || typeof data !== 'object' || isSignal(data)) {
|
|
1558
|
+
return data;
|
|
1559
|
+
}
|
|
1560
|
+
if (Array.isArray(data)) {
|
|
1561
|
+
return signal(data.map(item => convertObjectToSignal(item, isCloneDeep)));
|
|
1562
|
+
}
|
|
1563
|
+
if (data instanceof Map) {
|
|
1564
|
+
const mapCopy = new Map();
|
|
1565
|
+
Array.from(data.keys()).forEach(key => {
|
|
1566
|
+
mapCopy.set(key, convertObjectToSignal(data.get(key), isCloneDeep));
|
|
1567
|
+
});
|
|
1568
|
+
return signal(mapCopy);
|
|
1569
|
+
}
|
|
1570
|
+
data = signal(isCloneDeep ? { ...data } : data);
|
|
1571
|
+
for (const key in data()) {
|
|
1572
|
+
const value = data()[key];
|
|
1573
|
+
if (value instanceof TemplateRef || value instanceof ElementRef || value instanceof Element || value instanceof Date || value instanceof RegExp || value instanceof Set || value instanceof Map) {
|
|
1574
|
+
continue;
|
|
1575
|
+
}
|
|
1576
|
+
if (Object.prototype.hasOwnProperty.call(data(), key)) {
|
|
1577
|
+
data()[key] = convertObjectToSignal(value, isCloneDeep);
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
return data;
|
|
1581
|
+
};
|
|
1582
|
+
const convertSignalToObject = (data, isCloneDeep = true) => {
|
|
1583
|
+
if (data === null || (typeof data !== 'function' && typeof data !== 'object')) {
|
|
1584
|
+
return data;
|
|
1585
|
+
}
|
|
1586
|
+
if (isSignal(data)) {
|
|
1587
|
+
data = data();
|
|
1588
|
+
}
|
|
1589
|
+
if (Array.isArray(data)) {
|
|
1590
|
+
if (!isSignal(data[0])) {
|
|
1591
|
+
return data;
|
|
1592
|
+
}
|
|
1593
|
+
return data.map(item => convertSignalToObject(isCloneDeep ? cloneDeep(item) : item, isCloneDeep));
|
|
1594
|
+
}
|
|
1595
|
+
if (data instanceof Map) {
|
|
1596
|
+
const mapCopy = new Map();
|
|
1597
|
+
Array.from(data.keys()).forEach(key => {
|
|
1598
|
+
mapCopy.set(key, convertSignalToObject(isCloneDeep ? cloneDeep(data.get(key)) : data.get(key), isCloneDeep));
|
|
1599
|
+
});
|
|
1600
|
+
return mapCopy;
|
|
1601
|
+
}
|
|
1602
|
+
const result = isCloneDeep ? {} : data;
|
|
1603
|
+
for (const key in data) {
|
|
1604
|
+
const value = data[key];
|
|
1605
|
+
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
1606
|
+
result[key] = convertSignalToObject(isCloneDeep ? cloneDeep(value) : value, isCloneDeep);
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
return result;
|
|
1610
|
+
};
|
|
1611
|
+
|
|
1612
|
+
dayjs.extend(localeData);
|
|
1613
|
+
dayjs.extend(updateLocale);
|
|
1614
|
+
let functionFormatDate = undefined;
|
|
1615
|
+
const updateFunctionFormatDate = (functionCustom) => {
|
|
1616
|
+
functionFormatDate = functionCustom;
|
|
1617
|
+
};
|
|
1618
|
+
const formatDate = (time, format = 'YYYY/MM/DD HH:mm', lang) => {
|
|
1619
|
+
if (!time) {
|
|
1620
|
+
return '';
|
|
1621
|
+
}
|
|
1622
|
+
lang = lang || UtilsCache.getLang();
|
|
1623
|
+
if (functionFormatDate) {
|
|
1624
|
+
return functionFormatDate(time, format, lang);
|
|
1625
|
+
}
|
|
1626
|
+
time = typeof time === 'number' ? dayjs.unix(time).locale(lang) : dayjs(time).locale(lang);
|
|
1627
|
+
if (lang === 'vi') {
|
|
1628
|
+
dayjs.updateLocale('vi', {
|
|
1629
|
+
monthsShort: 'Thg 1_Thg 2_Thg 3_Thg 4_Thg 5_Thg 6_Thg 7_Thg 8_Thg 9_Thg 10_Thg 11_Thg 12'.split('_')
|
|
1630
|
+
});
|
|
1631
|
+
}
|
|
1632
|
+
if (typeof time === 'number') {
|
|
1633
|
+
return dayjs.unix(time).format(getFormatData(getTypeByFormat(format), lang));
|
|
1634
|
+
}
|
|
1635
|
+
return dayjs(time).format(getFormatData(getTypeByFormat(format), lang));
|
|
1636
|
+
};
|
|
1637
|
+
const getTypeByFormat = (format) => {
|
|
1638
|
+
if (format === 'dm' || format === 'dmy' || format === 'dmy hm' || format === 'my') {
|
|
1639
|
+
return format;
|
|
1640
|
+
}
|
|
1641
|
+
if (format === 'DD/MM/YYYY' || format === 'YYYY-MM-DD' || format === 'dd/MM/yyyy' || format === 'dd-MM-yyyy' || format === 'dd/mm/yyyy') {
|
|
1642
|
+
return 'dmy';
|
|
1643
|
+
}
|
|
1644
|
+
if (format === 'MM-DD' || format === 'dd/MM' || format === 'dd/mm') {
|
|
1645
|
+
return 'dm';
|
|
1646
|
+
}
|
|
1647
|
+
if (format === 'M/YYYY' || format === 'YYYY-MM' || format === 'MM/yyyy') {
|
|
1648
|
+
return 'my';
|
|
1649
|
+
}
|
|
1650
|
+
if (format === 'YYYY/MM/DD hh:mm:ss' || format === 'dmy hms' || format === 'dd/mm/yyyy hh:mm:ss') {
|
|
1651
|
+
return 'dmy hms';
|
|
1652
|
+
}
|
|
1653
|
+
return 'dmy hm';
|
|
1654
|
+
};
|
|
1655
|
+
const getFormatData = (type, lang) => {
|
|
1656
|
+
switch (type) {
|
|
1657
|
+
case 'dm':
|
|
1658
|
+
if (lang === 'vi') {
|
|
1659
|
+
return 'D MMM';
|
|
1660
|
+
}
|
|
1661
|
+
return 'MMM D';
|
|
1662
|
+
case 'dmy':
|
|
1663
|
+
if (lang === 'vi') {
|
|
1664
|
+
return 'D MMM, YYYY';
|
|
1665
|
+
}
|
|
1666
|
+
return 'MMM D, YYYY';
|
|
1667
|
+
case 'dmy hm':
|
|
1668
|
+
if (lang === 'vi') {
|
|
1669
|
+
return 'D MMM, YYYY HH:mm';
|
|
1670
|
+
}
|
|
1671
|
+
return 'MMM D, YYYY HH:mm';
|
|
1672
|
+
case 'my':
|
|
1673
|
+
if (lang === 'vi') {
|
|
1674
|
+
return 'MMM, YYYY';
|
|
1675
|
+
}
|
|
1676
|
+
return 'MMM YYYY ';
|
|
1677
|
+
case 'dmy hms':
|
|
1678
|
+
if (lang === 'vi') {
|
|
1679
|
+
return 'D MMM, YYYY HH:mm:ss';
|
|
1680
|
+
}
|
|
1681
|
+
return 'MMM D, YYYY HH:mm:ss';
|
|
1682
|
+
}
|
|
1683
|
+
};
|
|
1684
|
+
|
|
1685
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1686
|
+
const endCodeUrl = (objectData, isBody) => {
|
|
1687
|
+
objectData = omitBy(objectData, param => param === '' || isNil(param));
|
|
1688
|
+
let res = '';
|
|
1689
|
+
for (const p in objectData) {
|
|
1690
|
+
res += `&${p}=${encodeURIComponent(objectData[p])}`;
|
|
1691
|
+
}
|
|
1692
|
+
return res === '' ? '' : `${isBody ? '' : '?'}${res.substring(1)}`;
|
|
1693
|
+
};
|
|
1694
|
+
|
|
1695
|
+
const convertFileToBase64 = (file) => {
|
|
1696
|
+
return new Promise((resolve) => {
|
|
1697
|
+
const reader = new FileReader();
|
|
1698
|
+
reader.readAsDataURL(file);
|
|
1699
|
+
reader.onload = (event) => {
|
|
1700
|
+
resolve(event.target?.result ?? '');
|
|
1701
|
+
};
|
|
1702
|
+
});
|
|
1703
|
+
};
|
|
1704
|
+
|
|
1421
1705
|
/**
|
|
1422
1706
|
* Generated bundle index. Do not edit.
|
|
1423
1707
|
*/
|
|
1424
1708
|
|
|
1425
|
-
export { CHARACTER_DATA_EMPTY, ERROR_MESSAGE_EMPTY_VALID, ERROR_MESSAGE_MAX_LENGTH, ERROR_MESSAGE_MAX_VALID, ERROR_MESSAGE_MIN_LENGTH, ERROR_MESSAGE_MIN_VALID, ERROR_MESSAGE_PATTEN_VALID, GetColorById,
|
|
1709
|
+
export { CHARACTER_DATA_EMPTY, DEFAULT_START_PAGE_0, ERROR_MESSAGE_EMPTY_VALID, ERROR_MESSAGE_MAX_LENGTH, ERROR_MESSAGE_MAX_VALID, ERROR_MESSAGE_MIN_LENGTH, ERROR_MESSAGE_MIN_VALID, ERROR_MESSAGE_PATTEN_VALID, GetColorById, UtilsCache, UtilsCommunicateMicro, UtilsCommunicateMicroKeyGlobal, UtilsHttpParamsRequest, UtilsHttpParamsRequestInstance, UtilsKeyCodeConstant, UtilsLanguageConstants, UtilsUrlSearchParams, checkMouseOverInContainer, checkViewInScreen, cloneDeep, cloneIBoundingClientRect, colorContrastFromOrigin, colorStepContrastFromOrigin, convertFileToBase64, convertObjectToSignal, convertSignalToObject, decrypt, decrypt3rd, deleteUnicode, emojiPattern, encrypt, encrypt3rd, endCodeUrl, escapeHtml, formatDate, formatNumber, generateInterface, get, getColorById, getKeyCacheByArrayObject, getPlatFromBrowser, getViewport, groupBy, isEmbedFrame, isEmpty, isEqual, isNil, keyBy, listColorDefine$1 as listColorDefine, md5, omitBy, patternAccount, patternDomain, patternEmail, patternEmoji, patternEncodeUri, patternGetFieldByRuleFieldReplace, patternHostUrl, patternKey, patternMobilePhone, patternName, patternNameProfile, patternNameSpecial, patternNameUtf8, patternNumber, patternPem, patternPhone, patternPhoneNormal, patternRuleFieldReplace, patternTax, patternUrl, range, removeEmoji, rgbToHex, set, setCaretPosition, setKeyCrypto, setKeyCrypto3rd, setStyles, uniqBy, updateFunctionCheckEmbedFrame, updateFunctionFormatDate, updateFunctionXssFilter, uuid, viewDataNumberByLanguage, xssFilter };
|
|
1426
1710
|
//# sourceMappingURL=libs-ui-utils.mjs.map
|