@stemy/ngx-utils 19.5.1 → 19.5.3

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.
@@ -1,3 +1,4 @@
1
+ import 'zone.js';
1
2
  import * as i0 from '@angular/core';
2
3
  import { InjectionToken, PLATFORM_ID, Inject, Injectable, Optional, Injector, EventEmitter, isDevMode, ErrorHandler, createComponent, NgZone, Pipe, HostListener, HostBinding, Output, Input, Directive, ElementRef, forwardRef, ViewChild, Component, ContentChild, ViewEncapsulation, ContentChildren, APP_INITIALIZER, makeEnvironmentProviders, NgModule } from '@angular/core';
3
4
  import 'reflect-metadata';
@@ -1657,6 +1658,18 @@ class FileUtils {
1657
1658
  }
1658
1659
  }
1659
1660
 
1661
+ class ForbiddenZone {
1662
+ static isForbidden(name) {
1663
+ return Zone.current.name === `forbidden-${name}`;
1664
+ }
1665
+ static run(name, cb) {
1666
+ const forbiddenZone = Zone.current.fork({
1667
+ name: `forbidden-${name}`
1668
+ });
1669
+ return forbiddenZone.run(cb);
1670
+ }
1671
+ }
1672
+
1660
1673
  class GenericValue extends Subject {
1661
1674
  get value() {
1662
1675
  return this._value;
@@ -3459,6 +3472,7 @@ class EventsService {
3459
3472
  this.eventForwarded = new EventEmitter();
3460
3473
  this.stickyUpdated = new EventEmitter();
3461
3474
  this.languageChanged = new EventEmitter();
3475
+ this.translationsEnabled = new EventEmitter();
3462
3476
  this.sticky = false;
3463
3477
  }
3464
3478
  event(e) {
@@ -3585,7 +3599,7 @@ class StaticLanguageService {
3585
3599
  return this.translations[this.currentLanguage] || {};
3586
3600
  }
3587
3601
  set dictionary(value) {
3588
- this.translations[this.currentLanguage] = value;
3602
+ this.setDictionary(this.currentLang, value);
3589
3603
  }
3590
3604
  get languages() {
3591
3605
  return this.languageList;
@@ -3603,12 +3617,18 @@ class StaticLanguageService {
3603
3617
  set editLanguage(lang) {
3604
3618
  this.editLang = lang || this.currentLanguage;
3605
3619
  }
3620
+ get enableTranslations() {
3621
+ return this.enableTrans;
3622
+ }
3623
+ set enableTranslations(value) {
3624
+ this.enableTrans = value;
3625
+ this.events.translationsEnabled.emit(value);
3626
+ }
3606
3627
  get disableTranslations() {
3607
- return this.disableTrans;
3628
+ return !this.enableTranslations;
3608
3629
  }
3609
3630
  set disableTranslations(value) {
3610
- this.disableTrans = value;
3611
- this.events.languageChanged.emit(this.currentLang);
3631
+ this.enableTranslations = !value;
3612
3632
  }
3613
3633
  get httpClient() {
3614
3634
  return this.client;
@@ -3627,7 +3647,7 @@ class StaticLanguageService {
3627
3647
  this.client = client;
3628
3648
  this.editLang = null;
3629
3649
  this.currentLang = null;
3630
- this.disableTrans = false;
3650
+ this.enableTrans = true;
3631
3651
  this.languageList = [];
3632
3652
  this.translations = {
3633
3653
  none: {}
@@ -3649,16 +3669,24 @@ class StaticLanguageService {
3649
3669
  this.replaceLanguages(this.languageList.concat(languages));
3650
3670
  }
3651
3671
  getTranslationSync(key, params = null) {
3652
- const lowerKey = (key || "").toLocaleLowerCase();
3653
- const translation = this.dictionary[lowerKey] || lowerKey;
3654
- return this.interpolate(translation == lowerKey ? key : translation, params);
3655
- }
3656
- getTranslation(key, params) {
3657
- if (!ObjectUtils.isString(key) || !key.length) {
3658
- throw new Error(`Parameter "key" required`);
3672
+ if (!key)
3673
+ return "";
3674
+ try {
3675
+ const lowerKey = key.toLocaleLowerCase();
3676
+ const dict = this.dictionary;
3677
+ if (lowerKey in dict && this.enableTranslations) {
3678
+ return this.interpolate(dict[lowerKey], params);
3679
+ }
3680
+ return this.interpolate(key, params);
3659
3681
  }
3660
- const translation = ObjectUtils.getValue(this.dictionary, key, key) || key;
3661
- return this.promises.resolve(this.interpolate(translation, params));
3682
+ catch (reason) {
3683
+ console.warn("ERROR IN TRANSLATIONS", reason);
3684
+ return key;
3685
+ }
3686
+ }
3687
+ async getTranslation(key, params = null) {
3688
+ await this.loadDictionary();
3689
+ return this.getTranslationSync(key, params);
3662
3690
  }
3663
3691
  getTranslations(...keys) {
3664
3692
  return this.promises.create(resolve => {
@@ -3679,6 +3707,16 @@ class StaticLanguageService {
3679
3707
  const translation = translations ? translations.find(t => t.lang == lang) : null;
3680
3708
  return this.interpolate(translation ? translation.translation : "", params);
3681
3709
  }
3710
+ async loadDictionary() {
3711
+ return this.dictionary;
3712
+ }
3713
+ setDictionary(lang, dictionary) {
3714
+ this.translations[lang] = Object.keys(dictionary || {}).reduce((res, key) => {
3715
+ res[key.toLocaleLowerCase()] = dictionary[key];
3716
+ return res;
3717
+ }, {});
3718
+ return this.translations[lang];
3719
+ }
3682
3720
  interpolate(expr, params) {
3683
3721
  if (typeof expr === "string") {
3684
3722
  return this.interpolateString(expr, params);
@@ -3753,6 +3791,7 @@ class LanguageService extends StaticLanguageService {
3753
3791
  }));
3754
3792
  }
3755
3793
  initService() {
3794
+ super.initService();
3756
3795
  this.client.setExtraRequestParam("language", "de");
3757
3796
  this.translationRequests = {};
3758
3797
  this.languageSettings = new BehaviorSubject(null);
@@ -3785,22 +3824,6 @@ class LanguageService extends StaticLanguageService {
3785
3824
  await this.useLanguage(lang);
3786
3825
  this.events.languageChanged.emit(lang);
3787
3826
  }
3788
- async getTranslation(key, params = null) {
3789
- if (!key)
3790
- return "";
3791
- try {
3792
- const lowerKey = key.toLocaleLowerCase();
3793
- const dict = await this.loadDictionary();
3794
- if (lowerKey in dict) {
3795
- return this.interpolate(dict[lowerKey], params);
3796
- }
3797
- return this.interpolate(key, params);
3798
- }
3799
- catch (reason) {
3800
- console.log("ERROR IN TRANSLATIONS", reason);
3801
- return key;
3802
- }
3803
- }
3804
3827
  async useLanguage(lang) {
3805
3828
  lang = this.languages.indexOf(lang) < 0 ? this.languages[0] : lang;
3806
3829
  this.client.setExtraRequestParam("language", lang);
@@ -3808,22 +3831,18 @@ class LanguageService extends StaticLanguageService {
3808
3831
  return this.dictionary;
3809
3832
  this.storage.set("language", lang);
3810
3833
  this.currentLang = lang;
3811
- const dict = await this.loadDictionary();
3812
- this.translations[lang] = dict;
3813
- return dict;
3834
+ return this.loadDictionary();
3814
3835
  }
3815
3836
  loadDictionary() {
3816
3837
  const lang = this.currentLanguage;
3817
3838
  this.translationRequests[lang] = this.translationRequests[lang] || new Promise(resolve => {
3818
3839
  const ext = this.config.translationExt || ``;
3819
- this.httpClient.get(`${this.config.translationUrl}${lang}${ext}`).toPromise().then(response => {
3820
- response = response || {};
3821
- resolve(Object.keys(response).reduce((result, key) => {
3822
- result[key.toLocaleLowerCase()] = response[key];
3823
- return result;
3824
- }, {}));
3825
- }, () => {
3826
- resolve({});
3840
+ const request = this.httpClient.get(`${this.config.translationUrl}${lang}${ext}`);
3841
+ firstValueFrom(request).then(response => {
3842
+ resolve(this.setDictionary(lang, response));
3843
+ }, reason => {
3844
+ console.warn("ERROR IN TRANSLATIONS", reason);
3845
+ resolve(this.setDictionary(lang, {}));
3827
3846
  });
3828
3847
  });
3829
3848
  return this.translationRequests[lang];
@@ -3876,10 +3895,7 @@ class OpenApiService {
3876
3895
  }
3877
3896
  async getSchema(name) {
3878
3897
  const schemas = await this.getSchemas();
3879
- const schema = schemas[name];
3880
- if (!schema)
3881
- return null;
3882
- return schemas[name];
3898
+ return schemas[name] || null;
3883
3899
  }
3884
3900
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: OpenApiService, deps: [{ token: API_SERVICE }], target: i0.ɵɵFactoryTarget.Injectable }); }
3885
3901
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: OpenApiService }); }
@@ -5162,9 +5178,9 @@ class TranslatePipe {
5162
5178
  this.lang = lang;
5163
5179
  dirty = true;
5164
5180
  }
5165
- const disabled = this.language.disableTranslations;
5166
- if (this.disabled !== disabled) {
5167
- this.disabled = disabled;
5181
+ const enabled = this.language.enableTranslations;
5182
+ if (this.enabled !== enabled) {
5183
+ this.enabled = enabled;
5168
5184
  dirty = true;
5169
5185
  }
5170
5186
  if (!ObjectUtils.equals(this.query, query)) {
@@ -5197,10 +5213,6 @@ class TranslatePipe {
5197
5213
  this.lastValue = Array.isArray(query) ? this.language.getTranslationFromArray(query, this.params, lang) : this.language.getTranslationFromObject(query, this.params, lang);
5198
5214
  return this.lastValue;
5199
5215
  }
5200
- if (this.disabled) {
5201
- this.lastValue = query;
5202
- return this.lastValue;
5203
- }
5204
5216
  this.lastValue = this.language.getTranslationSync(query, this.params);
5205
5217
  this.language.getTranslation(query, this.params).then(value => {
5206
5218
  this.lastValue = value;
@@ -8427,5 +8439,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImpo
8427
8439
  * Generated bundle index. Do not edit.
8428
8440
  */
8429
8441
 
8430
- export { API_SERVICE, APP_BASE_URL, AUTH_SERVICE, AclService, AjaxRequestHandler, ApiService, ArrayUtils, AsyncMethodBase, AsyncMethodDirective, AuthGuard, BASE_CONFIG, BackgroundDirective, BaseDialogService, BaseHttpClient, BaseHttpService, BaseToasterService, CONFIG_SERVICE, CanvasColor, CanvasUtils, ChipsComponent, ChunkPipe, Circle, ComponentLoaderDirective, ComponentLoaderService, ConfigService, DIALOG_SERVICE, DateUtils, DragDropEventPlugin, DropListComponent, DropdownBoxComponent, DropdownContentDirective, DropdownDirective, DropdownToggleDirective, DynamicTableComponent, DynamicTableTemplateDirective, ERROR_HANDLER, EXPRESS_REQUEST, EntriesPipe, ErrorHandlerService, EventsService, ExtraItemPropertiesPipe, FactoryDependencies, FakeModuleComponent, FileSystemEntry, FileUtils, FilterPipe, FindPipe, FormatNumberPipe, FormatterService, GenericValue, GetOffsetPipe, GetTypePipe, GetValuePipe, GlobalTemplateDirective, GlobalTemplatePipe, GlobalTemplateService, GroupByPipe, HttpPromise, ICON_SERVICE, IConfiguration, IconDirective, IconService, IncludesPipe, Initializer, InteractiveCanvasComponent, InteractiveCircleComponent, InteractiveItemComponent, InteractiveRectComponent, IsTypePipe, JSONfn, JoinPipe, KeysPipe, LANGUAGE_SERVICE, LanguageService, LoaderUtils, LocalHttpService, MapPipe, MathUtils, MaxPipe, MinPipe, NgxTemplateOutletDirective, NgxUtilsModule, OPTIONS_TOKEN, ObjectType, ObjectUtils, ObservableUtils, OpenApiService, PROMISE_SERVICE, PaginationDirective, PaginationItemContext, PaginationItemDirective, PaginationMenuComponent, Point, PopPipe, PromiseService, RESIZE_DELAY, RESIZE_STRATEGY, ROOT_ELEMENT, Rect, ReducePipe, ReflectUtils, RemapPipe, ReplacePipe, ResizeEventPlugin, ResourceIfContext, ResourceIfDirective, ReversePipe, RoundPipe, SCRIPT_PARAMS, SafeHtmlPipe, ScrollEventPlugin, SetUtils, ShiftPipe, SocketClient, SocketService, SplitPipe, StateService, StaticAuthService, StaticLanguageService, StickyClassDirective, StickyDirective, StorageMode, StorageService, StringUtils, TOASTER_SERVICE, TimerUtils, TranslatePipe, TranslatedUrlSerializer, UniqueUtils, UniversalService, UnorderedListComponent, UnorderedListItemDirective, UnorderedListTemplateDirective, UploadComponent, ValuedPromise, ValuesPipe, Vector, WASI_IMPLEMENTATION, WasmService, cachedFactory, cancelablePromise, checkTransitions, getComponentDef, impatientPromise, parseSelector, provideEntryComponents, provideWithOptions, selectorMatchesList };
8442
+ export { API_SERVICE, APP_BASE_URL, AUTH_SERVICE, AclService, AjaxRequestHandler, ApiService, ArrayUtils, AsyncMethodBase, AsyncMethodDirective, AuthGuard, BASE_CONFIG, BackgroundDirective, BaseDialogService, BaseHttpClient, BaseHttpService, BaseToasterService, CONFIG_SERVICE, CanvasColor, CanvasUtils, ChipsComponent, ChunkPipe, Circle, ComponentLoaderDirective, ComponentLoaderService, ConfigService, DIALOG_SERVICE, DateUtils, DragDropEventPlugin, DropListComponent, DropdownBoxComponent, DropdownContentDirective, DropdownDirective, DropdownToggleDirective, DynamicTableComponent, DynamicTableTemplateDirective, ERROR_HANDLER, EXPRESS_REQUEST, EntriesPipe, ErrorHandlerService, EventsService, ExtraItemPropertiesPipe, FactoryDependencies, FakeModuleComponent, FileSystemEntry, FileUtils, FilterPipe, FindPipe, ForbiddenZone, FormatNumberPipe, FormatterService, GenericValue, GetOffsetPipe, GetTypePipe, GetValuePipe, GlobalTemplateDirective, GlobalTemplatePipe, GlobalTemplateService, GroupByPipe, HttpPromise, ICON_SERVICE, IConfiguration, IconDirective, IconService, IncludesPipe, Initializer, InteractiveCanvasComponent, InteractiveCircleComponent, InteractiveItemComponent, InteractiveRectComponent, IsTypePipe, JSONfn, JoinPipe, KeysPipe, LANGUAGE_SERVICE, LanguageService, LoaderUtils, LocalHttpService, MapPipe, MathUtils, MaxPipe, MinPipe, NgxTemplateOutletDirective, NgxUtilsModule, OPTIONS_TOKEN, ObjectType, ObjectUtils, ObservableUtils, OpenApiService, PROMISE_SERVICE, PaginationDirective, PaginationItemContext, PaginationItemDirective, PaginationMenuComponent, Point, PopPipe, PromiseService, RESIZE_DELAY, RESIZE_STRATEGY, ROOT_ELEMENT, Rect, ReducePipe, ReflectUtils, RemapPipe, ReplacePipe, ResizeEventPlugin, ResourceIfContext, ResourceIfDirective, ReversePipe, RoundPipe, SCRIPT_PARAMS, SafeHtmlPipe, ScrollEventPlugin, SetUtils, ShiftPipe, SocketClient, SocketService, SplitPipe, StateService, StaticAuthService, StaticLanguageService, StickyClassDirective, StickyDirective, StorageMode, StorageService, StringUtils, TOASTER_SERVICE, TimerUtils, TranslatePipe, TranslatedUrlSerializer, UniqueUtils, UniversalService, UnorderedListComponent, UnorderedListItemDirective, UnorderedListTemplateDirective, UploadComponent, ValuedPromise, ValuesPipe, Vector, WASI_IMPLEMENTATION, WasmService, cachedFactory, cancelablePromise, checkTransitions, getComponentDef, impatientPromise, parseSelector, provideEntryComponents, provideWithOptions, selectorMatchesList };
8431
8443
  //# sourceMappingURL=stemy-ngx-utils.mjs.map