@stemy/ngx-utils 17.4.4 → 17.5.1

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.
@@ -2237,6 +2237,11 @@ class SetUtils {
2237
2237
  return;
2238
2238
  items.forEach(i => set.add(i));
2239
2239
  }
2240
+ static merge(set, other) {
2241
+ if (!ObjectUtils.isSet(set) || !ObjectUtils.isSet(other))
2242
+ return;
2243
+ other.forEach(i => set.add(i));
2244
+ }
2240
2245
  }
2241
2246
 
2242
2247
  class UniqueUtils {
@@ -3264,19 +3269,28 @@ class EventsService {
3264
3269
  get isSticky() {
3265
3270
  return this.sticky;
3266
3271
  }
3272
+ get isAuthenticated() {
3273
+ return !!this.user;
3274
+ }
3267
3275
  constructor() {
3268
- this.eventForwarded = new EventEmitter();
3269
- this.stickyUpdated = new EventEmitter();
3270
- this.languageChanged = new EventEmitter();
3271
- this.editLanguageChanged = new EventEmitter();
3276
+ this.eventForwarded = new Subject();
3277
+ this.stickyUpdated = new Subject();
3278
+ this.languageChanged = new Subject();
3279
+ this.editLanguageChanged = new Subject();
3280
+ this.translationsEnabled = new Subject();
3281
+ this.userChanged = new Subject();
3272
3282
  this.sticky = false;
3283
+ this.user = null;
3284
+ this.userChanged.subscribe(user => {
3285
+ this.user = user;
3286
+ });
3273
3287
  }
3274
3288
  event(e) {
3275
- this.eventForwarded.emit(e);
3289
+ this.eventForwarded.next(e);
3276
3290
  }
3277
3291
  updateSticky(sticky) {
3278
3292
  this.sticky = sticky;
3279
- this.stickyUpdated.emit(sticky);
3293
+ this.stickyUpdated.next(sticky);
3280
3294
  }
3281
3295
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: EventsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
3282
3296
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: EventsService }); }
@@ -3387,16 +3401,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImpo
3387
3401
  type: Injectable
3388
3402
  }], ctorParameters: () => [] });
3389
3403
 
3390
- const emptyDict = {};
3404
+ const EMPTY_DICT = {};
3391
3405
  class StaticLanguageService {
3392
3406
  get defaultLanguage() {
3393
3407
  return this.configs.getQueryParameter("lang") || this.storage.get("language", this.getDefaultLanguage());
3394
3408
  }
3395
3409
  get dictionary() {
3396
- return this.mergedTranslations[this.currentLanguage] || emptyDict;
3410
+ return this.mergedTranslations[this.currentLanguage] || EMPTY_DICT;
3397
3411
  }
3398
3412
  set dictionary(value) {
3399
- this.translations[this.currentLanguage] = value;
3413
+ this.setDictionary(this.currentLang, value);
3400
3414
  this.mergeTranslations();
3401
3415
  }
3402
3416
  get languages() {
@@ -3407,21 +3421,27 @@ class StaticLanguageService {
3407
3421
  }
3408
3422
  set currentLanguage(lang) {
3409
3423
  this.currentLang = lang;
3410
- this.events.languageChanged.emit(lang);
3424
+ this.events.languageChanged.next(lang);
3411
3425
  }
3412
3426
  get editLanguage() {
3413
3427
  return this.editLang || this.currentLanguage;
3414
3428
  }
3415
3429
  set editLanguage(lang) {
3416
3430
  this.editLang = lang || this.currentLanguage;
3417
- this.events.editLanguageChanged.emit(this.editLang);
3431
+ this.events.editLanguageChanged.next(this.editLang);
3432
+ }
3433
+ get enableTranslations() {
3434
+ return this.enableTrans;
3435
+ }
3436
+ set enableTranslations(value) {
3437
+ this.enableTrans = value;
3438
+ this.events.translationsEnabled.next(value);
3418
3439
  }
3419
3440
  get disableTranslations() {
3420
- return this.disableTrans;
3441
+ return !this.enableTranslations;
3421
3442
  }
3422
3443
  set disableTranslations(value) {
3423
- this.disableTrans = value;
3424
- this.events.languageChanged.emit(this.currentLang);
3444
+ this.enableTranslations = !value;
3425
3445
  }
3426
3446
  get httpClient() {
3427
3447
  return this.client;
@@ -3440,7 +3460,7 @@ class StaticLanguageService {
3440
3460
  this.client = client;
3441
3461
  this.editLang = null;
3442
3462
  this.currentLang = null;
3443
- this.disableTrans = false;
3463
+ this.enableTrans = true;
3444
3464
  this.languageList = [];
3445
3465
  this.translations = {
3446
3466
  none: {}
@@ -3457,7 +3477,7 @@ class StaticLanguageService {
3457
3477
  languages = Array.isArray(languages) && languages.length > 0 ? languages : this.languageList;
3458
3478
  this.languageList = Array.from(new Set(languages));
3459
3479
  this.languageList.forEach(lang => {
3460
- this.translations[lang] = this.translations[lang] || emptyDict;
3480
+ this.translations[lang] = this.translations[lang] || EMPTY_DICT;
3461
3481
  });
3462
3482
  }
3463
3483
  addLanguages(languages) {
@@ -3475,12 +3495,24 @@ class StaticLanguageService {
3475
3495
  this.mergedTranslations = this.translations;
3476
3496
  }
3477
3497
  getTranslationSync(key, params = null) {
3478
- key = String(key || "");
3479
- const lowerKey = key.toLocaleLowerCase();
3480
- const translation = !key ? "" : this.dictionary[lowerKey] || key;
3481
- return this.interpolate(translation, params);
3498
+ key = String(key ?? "");
3499
+ if (!key)
3500
+ return "";
3501
+ try {
3502
+ const lowerKey = key.toLocaleLowerCase();
3503
+ const dict = this.dictionary;
3504
+ if (lowerKey in dict && this.enableTranslations) {
3505
+ return this.interpolate(dict[lowerKey], params);
3506
+ }
3507
+ return this.interpolate(key, params);
3508
+ }
3509
+ catch (reason) {
3510
+ console.warn("ERROR IN TRANSLATIONS", reason);
3511
+ return key;
3512
+ }
3482
3513
  }
3483
- async getTranslation(key, params) {
3514
+ async getTranslation(key, params = null) {
3515
+ await this.loadDictionary();
3484
3516
  return this.getTranslationSync(key, params);
3485
3517
  }
3486
3518
  getTranslations(...keys) {
@@ -3502,9 +3534,20 @@ class StaticLanguageService {
3502
3534
  const translation = translations ? translations.find(t => t.lang == lang) : null;
3503
3535
  return this.interpolate(translation ? translation.translation : "", params);
3504
3536
  }
3537
+ async loadDictionary() {
3538
+ return this.dictionary;
3539
+ }
3540
+ setDictionary(lang, dictionary) {
3541
+ this.translations[lang] = Object.keys(dictionary || {}).reduce((res, key) => {
3542
+ res[key.toLocaleLowerCase()] = dictionary[key];
3543
+ return res;
3544
+ }, {});
3545
+ return this.translations[lang];
3546
+ }
3505
3547
  interpolate(expr, params) {
3506
3548
  if (typeof expr === "string") {
3507
- return this.interpolateString(expr, params);
3549
+ // Force single spaces to be empty strings, for labeling in forms.
3550
+ return expr === " " ? "" : this.interpolateString(expr, params);
3508
3551
  }
3509
3552
  if (typeof expr === "function") {
3510
3553
  return expr(params);
@@ -3515,7 +3558,7 @@ class StaticLanguageService {
3515
3558
  if (!expr || !params)
3516
3559
  return expr;
3517
3560
  return expr.replace(/{{\s?([^{}\s]*)\s?}}/g, (substring, b) => {
3518
- const r = ObjectUtils.getValue(params, b);
3561
+ const r = ObjectUtils.getValue(params, b, "");
3519
3562
  return ObjectUtils.isDefined(r) ? r : substring;
3520
3563
  });
3521
3564
  }
@@ -3541,8 +3584,8 @@ class StaticLanguageService {
3541
3584
  ]);
3542
3585
  this.mergedTranslations = Array.from(languages).reduce((merged, language) => {
3543
3586
  merged[language] = {
3544
- ...(this.translations[language] || emptyDict),
3545
- ...(this.overrideTranslations[language] || emptyDict),
3587
+ ...(this.translations[language] || EMPTY_DICT),
3588
+ ...(this.overrideTranslations[language] || EMPTY_DICT),
3546
3589
  };
3547
3590
  return merged;
3548
3591
  }, {});
@@ -3575,7 +3618,7 @@ class LanguageService extends StaticLanguageService {
3575
3618
  }
3576
3619
  set currentLanguage(lang) {
3577
3620
  this.useLanguage(lang).then(() => {
3578
- this.events.languageChanged.emit(lang);
3621
+ this.events.languageChanged.next(lang);
3579
3622
  });
3580
3623
  }
3581
3624
  get settings() {
@@ -3589,7 +3632,8 @@ class LanguageService extends StaticLanguageService {
3589
3632
  }));
3590
3633
  }
3591
3634
  initService() {
3592
- this.client.setExtraRequestParam("language", "de");
3635
+ super.initService();
3636
+ this.client.setExtraRequestParam("language", "en");
3593
3637
  this.translationRequests = {};
3594
3638
  this.languageSettings = new BehaviorSubject(null);
3595
3639
  if (this.universal.isServer)
@@ -3617,32 +3661,32 @@ class LanguageService extends StaticLanguageService {
3617
3661
  if (this.languageList.length === 0) {
3618
3662
  this.languageList = [defaultLanguage];
3619
3663
  }
3620
- const lang = this.languages.indexOf(defaultLanguage) < 0 ? settings.defaultLanguage || this.languageList[0] : defaultLanguage;
3664
+ const lang = this.selectLanguage(this.currentLang)
3665
+ ?? this.selectLanguage(defaultLanguage)
3666
+ ?? this.selectLanguage(settings.defaultLanguage || this.languageList[0]);
3621
3667
  await this.useLanguage(lang);
3622
- this.events.languageChanged.emit(lang);
3668
+ this.events.languageChanged.next(lang);
3623
3669
  }
3624
- async getTranslation(key, params = null) {
3625
- try {
3626
- await this.getDictionary();
3627
- return super.getTranslationSync(key, params);
3628
- }
3629
- catch (reason) {
3630
- console.log("ERROR IN TRANSLATIONS", reason);
3631
- return key;
3632
- }
3670
+ selectLanguage(lang) {
3671
+ if (!lang)
3672
+ return null;
3673
+ return this.languageList.length === 0 || this.languageList.includes(lang)
3674
+ ? lang : null;
3633
3675
  }
3634
3676
  async useLanguage(lang) {
3635
- lang = this.languages.indexOf(lang) < 0 ? this.languages[0] : lang;
3677
+ lang = this.selectLanguage(lang);
3636
3678
  this.client.setExtraRequestParam("language", lang);
3637
- if (lang == this.currentLang)
3679
+ if (lang === this.currentLang)
3638
3680
  return this.dictionary;
3639
3681
  this.storage.set("language", lang);
3640
3682
  this.currentLang = lang;
3641
- return this.getDictionary();
3683
+ return this.loadDictionary();
3642
3684
  }
3643
- getDictionary(lang) {
3644
- lang = this.languages.includes(lang) ? lang : this.currentLanguage;
3645
- this.translationRequests[lang] = this.translationRequests[lang] || firstValueFrom(this.client.get(`${this.config.translationUrl}${lang}`))
3685
+ async getDictionary(lang) {
3686
+ if (!lang)
3687
+ return EMPTY_DICT;
3688
+ const ext = this.config.translationExt || ``;
3689
+ this.translationRequests[lang] = this.translationRequests[lang] || firstValueFrom(this.client.get(`${this.config.translationUrl}${lang}${ext}`))
3646
3690
  .then(response => {
3647
3691
  response = response || {};
3648
3692
  const dictionary = Object.keys(response).reduce((result, key) => {
@@ -3654,12 +3698,16 @@ class LanguageService extends StaticLanguageService {
3654
3698
  return dictionary;
3655
3699
  }).catch(error => {
3656
3700
  console.warn("Translation dictionary problem:", error);
3657
- return {};
3701
+ return EMPTY_DICT;
3658
3702
  });
3659
3703
  return this.translationRequests[lang];
3660
3704
  }
3705
+ async loadDictionary() {
3706
+ return this.getDictionary(this.currentLang);
3707
+ }
3661
3708
  loadSettings() {
3662
- this.settingsPromise = this.settingsPromise || firstValueFrom(this.client.get(`${this.config.translationUrl}languageSettings`))
3709
+ const ext = this.config.translationExt || ``;
3710
+ this.settingsPromise = this.settingsPromise || firstValueFrom(this.client.get(`${this.config.translationUrl}languageSettings${ext}`))
3663
3711
  .catch(error => {
3664
3712
  console.warn("Translation settings problem:", error);
3665
3713
  return {
@@ -6317,12 +6365,12 @@ class Wasi {
6317
6365
  wasi_snapshot_preview1: this.wasi,
6318
6366
  env: this.wasi
6319
6367
  }).then(module => {
6320
- const exports = module.instance.exports;
6368
+ const exports$1 = module.instance.exports;
6321
6369
  this.wasm = {
6322
- ...exports,
6370
+ ...exports$1,
6323
6371
  writeArrayToMemory: (array) => {
6324
6372
  const bytes = array.length * array.BYTES_PER_ELEMENT;
6325
- const pointer = exports.malloc(bytes);
6373
+ const pointer = exports$1.malloc(bytes);
6326
6374
  const ctr = array.constructor;
6327
6375
  const heapArray = new ctr(this.wasm.memory.buffer, pointer, array.length);
6328
6376
  heapArray.set(array);