zek 19.0.21 → 19.0.23

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/fesm2022/zek.mjs CHANGED
@@ -1281,8 +1281,14 @@ class JwtHelper {
1281
1281
  }
1282
1282
 
1283
1283
  class MathHelper {
1284
+ // static round(value: number, decimals: number = 0): number {
1285
+ // return Math.round(Number(value) * Math.pow(10, decimals)) / (Math.pow(10, decimals));
1286
+ // }
1284
1287
  static round(value, decimals = 0) {
1285
- return Math.round(Number(value) * Math.pow(10, decimals)) / (Math.pow(10, decimals));
1288
+ if (!Number.isFinite(value))
1289
+ return NaN;
1290
+ const factor = 10 ** decimals;
1291
+ return Math.round((value + Number.EPSILON) * factor) / factor;
1286
1292
  }
1287
1293
  static clamp(v, min, max) {
1288
1294
  return Math.max(min, Math.min(max, v));
@@ -1297,6 +1303,22 @@ class MathHelper {
1297
1303
  }
1298
1304
  return sum;
1299
1305
  }
1306
+ static format(num, digits = 2) {
1307
+ if (num === null || num === undefined || isNaN(num))
1308
+ return '0';
1309
+ // If less than 1000, display normally
1310
+ if (Math.abs(num) < 1000) {
1311
+ return num.toString();
1312
+ }
1313
+ const suffixes = ['k', 'M', 'G', 'T', 'P', 'E'];
1314
+ // Calculate the index of the suffix
1315
+ // e.g. 1,000 -> index 0 ('k'), 1,000,000 -> index 1 ('M')
1316
+ const exp = Math.floor(Math.log(Math.abs(num)) / Math.log(1000));
1317
+ const value = num / Math.pow(1000, exp);
1318
+ const rounded = this.round(value, digits);
1319
+ // Return with suffix (subtract 1 because index 0 is 'k', not '1')
1320
+ return rounded + suffixes[exp - 1];
1321
+ }
1300
1322
  }
1301
1323
 
1302
1324
  class PagerHelper {
@@ -1379,30 +1401,131 @@ class RandomHelper {
1379
1401
  }
1380
1402
 
1381
1403
  class StorageHelper {
1404
+ // Check if logic is running in a browser environment
1405
+ static isBrowser() {
1406
+ return typeof window !== 'undefined' && typeof window.localStorage !== 'undefined';
1407
+ }
1408
+ /**
1409
+ * Saves data to localStorage.
1410
+ * Automatically stringifies objects, arrays, booleans, and numbers.
1411
+ */
1382
1412
  static set(key, value) {
1383
- if (!key) {
1413
+ if (!this.isBrowser() || !key)
1414
+ return;
1415
+ // Fix: Only remove if strictly null or undefined.
1416
+ // Prevents accidental deletion of 0, false, or ""
1417
+ if (value === null || value === undefined) {
1418
+ this.remove(key);
1384
1419
  return;
1385
1420
  }
1386
- if (!value) {
1387
- localStorage.removeItem(key);
1421
+ try {
1422
+ // If it's a string, store as is. Otherwise, stringify it.
1423
+ const data = typeof value === 'string' ? value : JSON.stringify(value);
1424
+ localStorage.setItem(key, data);
1425
+ }
1426
+ catch (error) {
1427
+ console.error(`Error saving ${key} to localStorage`, error);
1428
+ }
1429
+ }
1430
+ /**
1431
+ * Retrieves data from localStorage.
1432
+ * Tries to parse JSON; returns string (or original type) if parsing fails.
1433
+ */
1434
+ static get(key) {
1435
+ if (!this.isBrowser() || !key)
1436
+ return null;
1437
+ const item = localStorage.getItem(key);
1438
+ if (item === null)
1439
+ return null;
1440
+ try {
1441
+ // Fix: robust parsing handles objects, arrays, and stringified primitives
1442
+ return JSON.parse(item);
1443
+ }
1444
+ catch (e) {
1445
+ // If parsing fails, return the raw string
1446
+ return item;
1447
+ }
1448
+ }
1449
+ /**
1450
+ * Removes a specific item.
1451
+ */
1452
+ static remove(key) {
1453
+ if (!this.isBrowser() || !key)
1454
+ return;
1455
+ localStorage.removeItem(key);
1456
+ }
1457
+ /**
1458
+ * Clears all local storage.
1459
+ */
1460
+ static clear() {
1461
+ if (!this.isBrowser())
1462
+ return;
1463
+ localStorage.clear();
1464
+ }
1465
+ }
1466
+ class SessionStorageHelper {
1467
+ // Check if logic is running in a browser environment
1468
+ static isBrowser() {
1469
+ return typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined';
1470
+ }
1471
+ /**
1472
+ * Saves data to sessionStorage.
1473
+ * automatically stringifies objects/arrays.
1474
+ */
1475
+ static set(key, value) {
1476
+ if (!this.isBrowser() || !key)
1477
+ return;
1478
+ // Fix: Only remove if strictly null or undefined.
1479
+ // Allowing false, 0, or "" to be stored.
1480
+ if (value === null || value === undefined) {
1481
+ this.remove(key);
1388
1482
  return;
1389
1483
  }
1390
- if (typeof value === "object") {
1391
- value = JSON.stringify(value);
1484
+ try {
1485
+ // Store strings as is, stringify everything else (objects, arrays, numbers, booleans)
1486
+ const data = typeof value === 'string' ? value : JSON.stringify(value);
1487
+ sessionStorage.setItem(key, data);
1488
+ }
1489
+ catch (error) {
1490
+ console.error(`Error saving ${key} to sessionStorage`, error);
1392
1491
  }
1393
- localStorage.setItem(key, value);
1394
1492
  }
1493
+ /**
1494
+ * Retrieves data from sessionStorage.
1495
+ * Tries to parse JSON; returns string if parsing fails.
1496
+ */
1395
1497
  static get(key) {
1396
- const str = localStorage.getItem(key);
1397
- if (!str) {
1498
+ if (!this.isBrowser() || !key)
1398
1499
  return null;
1500
+ const item = sessionStorage.getItem(key);
1501
+ if (item === null)
1502
+ return null;
1503
+ try {
1504
+ // Attempt to parse. This handles objects "{}", arrays "[]",
1505
+ // and stringified primitives like "true" or "123".
1506
+ return JSON.parse(item);
1399
1507
  }
1400
- // assume it is an object that has been stringified
1401
- if (str[0] === '{') {
1402
- const v = JSON.parse(str);
1403
- return v;
1508
+ catch (e) {
1509
+ // If parsing fails, it was likely a simple string to begin with.
1510
+ // Return as-is.
1511
+ return item;
1404
1512
  }
1405
- return str;
1513
+ }
1514
+ /**
1515
+ * Removes a specific item.
1516
+ */
1517
+ static remove(key) {
1518
+ if (!this.isBrowser() || !key)
1519
+ return;
1520
+ sessionStorage.removeItem(key);
1521
+ }
1522
+ /**
1523
+ * Clears all session storage.
1524
+ */
1525
+ static clear() {
1526
+ if (!this.isBrowser())
1527
+ return;
1528
+ sessionStorage.clear();
1406
1529
  }
1407
1530
  }
1408
1531
 
@@ -3076,18 +3199,18 @@ class ListBaseComponent extends BaseComponent {
3076
3199
  initStoredFilter() {
3077
3200
  const filterParam = this.getQueryParam('filter') || this.getParam('filter');
3078
3201
  if (filterParam) {
3079
- const tmp = StorageHelper.get('filter');
3202
+ const tmp = SessionStorageHelper.get('filter');
3080
3203
  if (tmp && tmp.url && tmp.url === this.url && tmp.filter) {
3081
3204
  this.filter = Object.assign({}, tmp.filter);
3082
3205
  //this.filter = { ...tmp.filter };
3083
3206
  //we dont need this.assignFilter(); because after initStoredFilter(); will be assigned.
3084
3207
  }
3085
3208
  else {
3086
- localStorage.removeItem('filter');
3209
+ SessionStorageHelper.remove('filter');
3087
3210
  }
3088
3211
  }
3089
3212
  else {
3090
- localStorage.removeItem('filter');
3213
+ SessionStorageHelper.remove('filter');
3091
3214
  }
3092
3215
  }
3093
3216
  async changePage(page) {
@@ -3123,7 +3246,7 @@ class ListBaseComponent extends BaseComponent {
3123
3246
  this.internalSaveFilter();
3124
3247
  }
3125
3248
  internalSaveFilter() {
3126
- StorageHelper.set('filter', {
3249
+ SessionStorageHelper.set('filter', {
3127
3250
  url: this.url,
3128
3251
  filter: this.internalFilter
3129
3252
  });
@@ -7952,5 +8075,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.6", ngImpor
7952
8075
  * Generated bundle index. Do not edit.
7953
8076
  */
7954
8077
 
7955
- export { API_BASE_URL, AgePipe, Alert, AlertService, ArrayHelper, AuthService, Base64Helper, BaseAlert, BaseComponent, BaseService, BitwiseHelper, BootstrapHelper, CacheHelper, Color, ComponentType, Convert, CoreComponent, CoreUiComponent, CrudService, CssHelper, CustomHttpParamEncoder, DATE_FORMAT, DateHelper, DateValueAccessor, DatepickerModule, EditBase, EditBaseComponent, EditComponent, EditFormComponent, ErrorHelper, ExcelHelper, FileHelper, FileService, FilterBase, FilterHelper, GOOGLE_CLIENT_ID, Gender, Guid, HtmlHelper, HttpErrorHandler, IdName, IdNameChecked, IntervalHelper, JwtHelper, KeyPair, KeyPairChecked, KeyPairEx, KeyPairRequired, LANGUAGE, ListBase, ListBaseComponent, MATCH_VALIDATOR, MatchValidator, MathHelper, Month, ObjectHelper, OverlapHelper, PagedList, Pager, PagerHelper, PeriodRelation, PrintType, RANGE_VALIDATOR, RECAPTCHA_SITE_KEY, RandomHelper, RangeValidator, ReCaptchaService, RecaptchaModule, StorageHelper, StringHelper, TimeHelper, TimeModule, TimePipe, TimerService, TmpHelper, Toast, Tree, UrlHelper, ValidEventArgs, ValidationHelper, Validators, ValidatorsModule, WebApiClient, WebApiModule, ZekAlert, ZekApproveModal, ZekAutoComplete, ZekButtonBrowse, ZekButtonBrowseModalBase, ZekButtonBrowseModalToolbar, ZekButtonBrowseModule, ZekCallbackPipe, ZekCard, ZekCountdown, ZekDateAgoPipe, ZekDelayedInputDirective, ZekDeleteModal, ZekDisapproveModal, ZekDropdown, ZekEditToolbar, ZekFieldValidator, ZekFileInput, ZekFileSizePipe, ZekFileViewer, ZekFilterModal, ZekGoogleLoginButton, ZekGoogleLoginModule, ZekGridToolbar, ZekGridToolbarBar, ZekListToolbar, ZekLoading, ZekLoadingModule, ZekLocalToUtcModule, ZekLocalToUtcPipe, ZekModal, ZekModalModule, ZekNumericDirective, ZekPageTitle, ZekPager, ZekPassword, ZekProgress, ZekRadio, ZekReadOnlyDirective, ZekRestoreModal, ZekSafePipe, ZekSelect2, ZekSelect2Multiple, ZekSelectMultiple, ZekSort, ZekSortButtonGroup, ZekSubmitModal, ZekSumModal, ZekTag, ZekToast, ZekTooltip, ZekUtcToLocalModule, ZekUtcToLocalPipe, ZekValidation, ZekWizard, ZekWizard2, firstBy, handler, matchValidator, nullValidator, rangeValidator, zekAuthGuard };
8078
+ export { API_BASE_URL, AgePipe, Alert, AlertService, ArrayHelper, AuthService, Base64Helper, BaseAlert, BaseComponent, BaseService, BitwiseHelper, BootstrapHelper, CacheHelper, Color, ComponentType, Convert, CoreComponent, CoreUiComponent, CrudService, CssHelper, CustomHttpParamEncoder, DATE_FORMAT, DateHelper, DateValueAccessor, DatepickerModule, EditBase, EditBaseComponent, EditComponent, EditFormComponent, ErrorHelper, ExcelHelper, FileHelper, FileService, FilterBase, FilterHelper, GOOGLE_CLIENT_ID, Gender, Guid, HtmlHelper, HttpErrorHandler, IdName, IdNameChecked, IntervalHelper, JwtHelper, KeyPair, KeyPairChecked, KeyPairEx, KeyPairRequired, LANGUAGE, ListBase, ListBaseComponent, MATCH_VALIDATOR, MatchValidator, MathHelper, Month, ObjectHelper, OverlapHelper, PagedList, Pager, PagerHelper, PeriodRelation, PrintType, RANGE_VALIDATOR, RECAPTCHA_SITE_KEY, RandomHelper, RangeValidator, ReCaptchaService, RecaptchaModule, SessionStorageHelper, StorageHelper, StringHelper, TimeHelper, TimeModule, TimePipe, TimerService, TmpHelper, Toast, Tree, UrlHelper, ValidEventArgs, ValidationHelper, Validators, ValidatorsModule, WebApiClient, WebApiModule, ZekAlert, ZekApproveModal, ZekAutoComplete, ZekButtonBrowse, ZekButtonBrowseModalBase, ZekButtonBrowseModalToolbar, ZekButtonBrowseModule, ZekCallbackPipe, ZekCard, ZekCountdown, ZekDateAgoPipe, ZekDelayedInputDirective, ZekDeleteModal, ZekDisapproveModal, ZekDropdown, ZekEditToolbar, ZekFieldValidator, ZekFileInput, ZekFileSizePipe, ZekFileViewer, ZekFilterModal, ZekGoogleLoginButton, ZekGoogleLoginModule, ZekGridToolbar, ZekGridToolbarBar, ZekListToolbar, ZekLoading, ZekLoadingModule, ZekLocalToUtcModule, ZekLocalToUtcPipe, ZekModal, ZekModalModule, ZekNumericDirective, ZekPageTitle, ZekPager, ZekPassword, ZekProgress, ZekRadio, ZekReadOnlyDirective, ZekRestoreModal, ZekSafePipe, ZekSelect2, ZekSelect2Multiple, ZekSelectMultiple, ZekSort, ZekSortButtonGroup, ZekSubmitModal, ZekSumModal, ZekTag, ZekToast, ZekTooltip, ZekUtcToLocalModule, ZekUtcToLocalPipe, ZekValidation, ZekWizard, ZekWizard2, firstBy, handler, matchValidator, nullValidator, rangeValidator, zekAuthGuard };
7956
8079
  //# sourceMappingURL=zek.mjs.map