@eui/core 19.0.2 → 19.0.3-snapshot-1737728205029

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.
@@ -2,13 +2,12 @@ import * as i1 from '@eui/base';
2
2
  import { LogLevel, ConsoleAppender, initialAppState, initialUserState, initialNotificationsState, initialI18nState, initialLocaleState, Logger, LoggerMock, initialCoreState, xhr, mergeAll, getI18nLoaderConfig, EuiLazyService, getI18nServiceConfigFromBase, getBrowserDefaultLanguage, EuiEuLanguages, EuiService, getUserState, getLocaleServiceConfigFromBase, transformToUxHttpResponse } from '@eui/base';
3
3
  export * from '@eui/base';
4
4
  import * as i0 from '@angular/core';
5
- import { InjectionToken, inject, PLATFORM_ID, Injectable, Inject, Injector, NgModule, signal, computed, runInInjectionContext, Optional, SkipSelf, provideAppInitializer, ErrorHandler, LOCALE_ID } from '@angular/core';
5
+ import { InjectionToken, inject, PLATFORM_ID, Injectable, Inject, Injector, NgModule, Optional, SkipSelf, provideAppInitializer, ErrorHandler, LOCALE_ID } from '@angular/core';
6
6
  import * as extendProxy from 'extend';
7
7
  import { isPlatformBrowser, LOCATION_INITIALIZED, DOCUMENT, isPlatformServer, getLocaleId, registerLocaleData } from '@angular/common';
8
- import { filter, debounceTime, distinctUntilChanged, tap, take, map, switchMap, catchError, concatMap, takeUntil } from 'rxjs/operators';
9
- import { toObservable } from '@angular/core/rxjs-interop';
8
+ import { BehaviorSubject, of, forkJoin, from, Subject, defer, firstValueFrom } from 'rxjs';
9
+ import { filter, debounceTime, distinctUntilChanged, map, tap, take, switchMap, catchError, concatMap, takeUntil } from 'rxjs/operators';
10
10
  import { isEqual, get } from 'lodash-es';
11
- import { of, forkJoin, from, Subject, BehaviorSubject, defer, firstValueFrom } from 'rxjs';
12
11
  import { DateAdapter, MAT_DATE_LOCALE } from '@angular/material/core';
13
12
  import { MomentDateAdapter } from '@angular/material-moment-adapter';
14
13
  import * as i1$2 from '@angular/common/http';
@@ -18,6 +17,7 @@ import { NavigationEnd } from '@angular/router';
18
17
  import { createSelector } from 'reselect';
19
18
  import * as i1$3 from '@ngx-translate/core';
20
19
  import { TranslateLoader } from '@ngx-translate/core';
20
+ import { toSignal } from '@angular/core/rxjs-interop';
21
21
  import { By } from '@angular/platform-browser';
22
22
  import { FormGroup, FormArray } from '@angular/forms';
23
23
  import { DomPortalOutlet, ComponentPortal, PortalInjector } from '@angular/cdk/portal';
@@ -795,13 +795,14 @@ class StoreService {
795
795
  */
796
796
  this._autoSaveHandlers = {};
797
797
  this.isHandlingAutoSave = false;
798
- this.injector = inject(Injector);
799
798
  if (isPlatformBrowser(this.platformId)) {
800
799
  this._storage = localStorage;
801
800
  }
802
- this.state = signal({}, { equal: isEqual });
803
- toObservable(this.state)
804
- .pipe(filter(() => this.isHandlingAutoSave), debounceTime(1000), distinctUntilChanged())
801
+ const initialState = {};
802
+ this.state = new BehaviorSubject(initialState);
803
+ // Subscribe to signal changes for auto-save
804
+ this.state.asObservable()
805
+ .pipe(filter(() => this.isHandlingAutoSave), debounceTime(1000), distinctUntilChanged((prev, curr) => isEqual(prev, curr)))
805
806
  .subscribe((state) => {
806
807
  this.saveState(state);
807
808
  });
@@ -816,7 +817,8 @@ class StoreService {
816
817
  // load the state from the localStorage
817
818
  let localState = loadState(this._storage);
818
819
  localState = { ...localState, app: { ...localState?.app, version } };
819
- this.updateState(this.deepMerge(localState, { ...initialCoreState }));
820
+ const mergedState = this.deepMerge(localState, { ...initialCoreState });
821
+ this.updateState(mergedState);
820
822
  }
821
823
  }
822
824
  /**
@@ -841,45 +843,33 @@ class StoreService {
841
843
  console.warn('eUI does not PROXY to NGRX store.dispatch() anymore');
842
844
  }
843
845
  updateState(state, reducer) {
846
+ const currentState = this.state.getValue();
847
+ let newState;
844
848
  if (reducer) {
845
- this.state.update(currentState => {
846
- const newState = reducer(currentState, state);
847
- return {
848
- ...newState,
849
- };
850
- });
849
+ newState = reducer(currentState, { ...state });
851
850
  }
852
851
  else {
853
- this.state.update(currentState => this.deepMerge(currentState, { ...state }));
852
+ newState = this.deepMerge(currentState, { ...state });
854
853
  }
854
+ this.state.next(newState);
855
855
  }
856
856
  select(keyOrMapFn) {
857
- let computedState = computed(() => this.state());
858
- if (keyOrMapFn) {
859
- switch (typeof keyOrMapFn) {
860
- case 'function':
861
- computedState = computed(() => {
862
- const state = this.state();
863
- return keyOrMapFn(state);
864
- });
865
- break;
866
- case 'string':
867
- computedState = computed(() => {
868
- const state = this.state();
869
- if (!keyOrMapFn) {
870
- return state;
871
- }
872
- const keys = keyOrMapFn.split('.');
873
- // Traverse the object based on the dot notation
874
- return keys.reduce((acc, currKey) => {
875
- return acc && acc[currKey] !== undefined ? acc[currKey] : undefined;
876
- }, state);
877
- });
878
- break;
879
- }
857
+ const baseObservable = this.state.asObservable();
858
+ if (!keyOrMapFn) {
859
+ return baseObservable;
880
860
  }
881
- // Use `runInInjectionContext` to ensure `toObservable` is within Angular injection context
882
- return runInInjectionContext(this.injector, () => toObservable(computedState).pipe(distinctUntilChanged((x, y) => isEqual(x, y))));
861
+ if (typeof keyOrMapFn === 'function') {
862
+ return baseObservable.pipe(map(state => keyOrMapFn(state)), distinctUntilChanged((x, y) => isEqual(x, y)));
863
+ }
864
+ return baseObservable.pipe(map(state => {
865
+ if (!keyOrMapFn) {
866
+ return state;
867
+ }
868
+ const keys = keyOrMapFn.split('.');
869
+ return keys.reduce((acc, currKey) => {
870
+ return acc && acc[currKey] !== undefined ? acc[currKey] : undefined;
871
+ }, state);
872
+ }), distinctUntilChanged((x, y) => isEqual(x, y)));
883
873
  }
884
874
  /**
885
875
  * filters and save the state with the Browser storage
@@ -2002,18 +1992,22 @@ const getLastAddedModule = (state) => state.app.loadedConfigModules.lastAddedMod
2002
1992
  class I18nService extends EuiLazyService {
2003
1993
  static { this.DEFAULT_STATE = { activeLang: 'en' }; }
2004
1994
  constructor(baseGlobalConfig, translateService, logService, store, document) {
2005
- super({ activeLang: 'en' });
1995
+ super(I18nService.DEFAULT_STATE);
2006
1996
  this.baseGlobalConfig = baseGlobalConfig;
2007
1997
  this.translateService = translateService;
2008
1998
  this.logService = logService;
2009
1999
  this.store = store;
2010
2000
  this.document = document;
2011
- /**
2012
- * a single signal holding the state - initial state is null
2013
- */
2014
- this.state = signal(I18nService.DEFAULT_STATE, { equal: isEqual });
2015
- this.injector = inject(Injector);
2016
2001
  this.subNotifier = new Subject();
2002
+ // Create a BehaviorSubject with the initial state
2003
+ this.stateSubject = new BehaviorSubject(this.stateInstance);
2004
+ // Initialize signal with base state
2005
+ this.state = toSignal(this.stateSubject, { equal: isEqual });
2006
+ // Subscribe to base class state changes
2007
+ this.onStateChange.subscribe((newState) => {
2008
+ // const clonedState = structuredClone(newState as T);
2009
+ this.stateSubject.next(newState);
2010
+ });
2017
2011
  this.config = getI18nServiceConfigFromBase(this.baseGlobalConfig);
2018
2012
  this.onModuleLoad = new BehaviorSubject({ ready: false, name: null });
2019
2013
  }
@@ -2022,44 +2016,33 @@ class I18nService extends EuiLazyService {
2022
2016
  this.subNotifier.complete();
2023
2017
  }
2024
2018
  getState(keyOrMapFn) {
2025
- let computedState = computed(() => this.state());
2026
- if (keyOrMapFn) {
2027
- switch (typeof keyOrMapFn) {
2028
- case 'function':
2029
- computedState = computed(() => {
2030
- const state = this.state();
2031
- return keyOrMapFn(state);
2032
- });
2033
- break;
2034
- case 'string':
2035
- computedState = computed(() => {
2036
- const state = this.state();
2037
- if (!keyOrMapFn) {
2038
- return state;
2039
- }
2040
- const keys = keyOrMapFn.split('.');
2041
- // Traverse the object based on the dot notation
2042
- return keys.reduce((acc, currKey) => {
2043
- return acc && acc[currKey] !== undefined ? acc[currKey] : undefined;
2044
- }, state);
2045
- });
2046
- break;
2047
- }
2019
+ if (!keyOrMapFn) {
2020
+ return this.stateSubject.asObservable().pipe(takeUntil(this.subNotifier), distinctUntilChanged((x, y) => isEqual(x, y)));
2021
+ }
2022
+ if (typeof keyOrMapFn === 'function') {
2023
+ return this.stateSubject.asObservable().pipe(takeUntil(this.subNotifier), map(state => keyOrMapFn(state)), distinctUntilChanged((x, y) => isEqual(x, y)));
2048
2024
  }
2049
- // Use `runInInjectionContext` to ensure `toObservable` is within Angular injection context
2050
- return runInInjectionContext(this.injector, () => toObservable(computedState).pipe(takeUntil(this.subNotifier), distinctUntilChanged((x, y) => isEqual(x, y))));
2025
+ return this.stateSubject.asObservable().pipe(takeUntil(this.subNotifier), map(state => {
2026
+ const keys = keyOrMapFn.split('.');
2027
+ // Traverse the object based on the dot notation
2028
+ return keys.reduce((acc, currKey) => {
2029
+ return acc && acc[currKey] !== undefined ? acc[currKey] : undefined;
2030
+ }, state);
2031
+ }), distinctUntilChanged((x, y) => isEqual(x, y)));
2051
2032
  }
2052
2033
  updateState(state, reducer) {
2053
2034
  if (state.activeLang) {
2054
2035
  this.updateHTMLDOMLang(state.activeLang);
2055
2036
  }
2056
- this.state.update(currentState => super.deepMerge(currentState, { ...state }));
2037
+ this.stateInstance = super.deepMerge(this.stateInstance, { ...state });
2038
+ // Emit state change
2039
+ this.onStateChange.next(this.stateInstance);
2057
2040
  }
2058
2041
  /**
2059
2042
  * This method is used to get the state as readonly signal.
2060
2043
  */
2061
2044
  getSignal() {
2062
- return this.state.asReadonly();
2045
+ return this.state;
2063
2046
  }
2064
2047
  init(langState) {
2065
2048
  const initLang = langState && langState.activeLang ? langState.activeLang : this.preparedDefaultLanguage();
@@ -4652,7 +4635,7 @@ const LOCALE_ID_MAPPER = new InjectionToken('localeIdMapper');
4652
4635
  class LocaleService extends EuiService {
4653
4636
  static { this.DEFAULT_STATE = { id: 'en-US' }; }
4654
4637
  constructor(store, baseGlobalConfig, locale_id, localeMapper, i18n, log) {
4655
- super({ id: locale_id || Intl.DateTimeFormat().resolvedOptions().locale });
4638
+ super({ id: locale_id || Intl.DateTimeFormat().resolvedOptions().locale || LocaleService.DEFAULT_STATE.id });
4656
4639
  this.store = store;
4657
4640
  this.baseGlobalConfig = baseGlobalConfig;
4658
4641
  this.locale_id = locale_id;
@@ -4660,18 +4643,24 @@ class LocaleService extends EuiService {
4660
4643
  this.i18n = i18n;
4661
4644
  this.log = log;
4662
4645
  this.subNotifier = new Subject();
4663
- /**
4664
- * a single signal holding the state - initial state is null
4665
- */
4666
- this.state = signal(LocaleService.DEFAULT_STATE, { equal: isEqual });
4667
- this.injector = inject(Injector);
4668
4646
  if (log) {
4669
4647
  this.logger = log.getLogger('core.LocaleService');
4670
4648
  }
4649
+ // Create a BehaviorSubject with the initial state
4650
+ this.stateSubject = new BehaviorSubject(this.stateInstance);
4651
+ // Initialize signal with base state
4652
+ this.state = toSignal(this.stateSubject, { equal: isEqual });
4653
+ // Subscribe to base class state changes
4654
+ this.onStateChange.subscribe((newState) => {
4655
+ // const clonedState = structuredClone(newState as T);
4656
+ this.stateSubject.next(newState);
4657
+ });
4671
4658
  this.config = getLocaleServiceConfigFromBase(this.baseGlobalConfig);
4672
4659
  // in case no localeMapper provided, set the angular getLocaleId as default
4673
4660
  if (!this.localeMapper) {
4674
4661
  this.localeMapper = getLocaleId;
4662
+ // TODO: replace deprecated method with new one
4663
+ // this.localeMapper = (locale: string) => new Intl.Locale(locale).baseName;
4675
4664
  }
4676
4665
  }
4677
4666
  ngOnDestroy() {
@@ -4687,32 +4676,19 @@ class LocaleService extends EuiService {
4687
4676
  * @param keyOrMapFn
4688
4677
  */
4689
4678
  getState(keyOrMapFn) {
4690
- let computedState = computed(() => this.state());
4691
- if (keyOrMapFn) {
4692
- switch (typeof keyOrMapFn) {
4693
- case 'function':
4694
- computedState = computed(() => {
4695
- const state = this.state();
4696
- return keyOrMapFn(state);
4697
- });
4698
- break;
4699
- case 'string':
4700
- computedState = computed(() => {
4701
- const state = this.state();
4702
- if (!keyOrMapFn) {
4703
- return state;
4704
- }
4705
- const keys = keyOrMapFn.split('.');
4706
- // Traverse the object based on the dot notation
4707
- return keys.reduce((acc, currKey) => {
4708
- return acc && acc[currKey] !== undefined ? acc[currKey] : undefined;
4709
- }, state);
4710
- });
4711
- break;
4712
- }
4679
+ if (!keyOrMapFn) {
4680
+ return this.stateSubject.asObservable().pipe(distinctUntilChanged((x, y) => isEqual(x, y)));
4681
+ }
4682
+ if (typeof keyOrMapFn === 'function') {
4683
+ return this.stateSubject.asObservable().pipe(map(state => keyOrMapFn(state)), distinctUntilChanged((x, y) => isEqual(x, y)));
4713
4684
  }
4714
- // Use `runInInjectionContext` to ensure `toObservable` is within Angular injection context
4715
- return runInInjectionContext(this.injector, () => toObservable(computedState).pipe(distinctUntilChanged((x, y) => isEqual(x, y))));
4685
+ return this.stateSubject.asObservable().pipe(map(state => {
4686
+ const keys = keyOrMapFn.split('.');
4687
+ // Traverse the object based on the dot notation
4688
+ return keys.reduce((acc, currKey) => {
4689
+ return acc && acc[currKey] !== undefined ? acc[currKey] : undefined;
4690
+ }, state);
4691
+ }), distinctUntilChanged((x, y) => isEqual(x, y)));
4716
4692
  }
4717
4693
  /**
4718
4694
  * Initializes the LocaleService with necessary configurations and state.
@@ -4739,11 +4715,12 @@ class LocaleService extends EuiService {
4739
4715
  * @throws Will throw an error if the locale for the given state id is not available.
4740
4716
  */
4741
4717
  updateState(state) {
4718
+ const prevState = structuredClone(this.stateInstance);
4742
4719
  if (state?.id) {
4743
4720
  // check if locale is available otherwise throw error
4744
4721
  try {
4745
4722
  const id = this.localeMapper(state.id);
4746
- this.state.update(currentState => super.deepMerge(currentState, { ...state, id }));
4723
+ this.stateInstance = super.deepMerge(this.stateInstance, { ...state, id });
4747
4724
  }
4748
4725
  catch (e) {
4749
4726
  const message = `Locale for '${state.id}' is not available.\n` +
@@ -4755,14 +4732,18 @@ class LocaleService extends EuiService {
4755
4732
  }
4756
4733
  }
4757
4734
  else {
4758
- this.state.update(currentState => this.deepMerge(currentState, { ...state }));
4735
+ this.stateInstance = super.deepMerge(this.stateInstance, { ...state });
4759
4736
  }
4737
+ // Emit state change
4738
+ this.onStateChange.next(this.stateInstance);
4739
+ // set previous state of service
4740
+ this.prevStateInstance = prevState;
4760
4741
  }
4761
4742
  /**
4762
4743
  * This method is used to get the state as readonly signal.
4763
4744
  */
4764
4745
  getSignal() {
4765
- return this.state.asReadonly();
4746
+ return this.state;
4766
4747
  }
4767
4748
  /**
4768
4749
  * Retrieves the previous locale used in the application.
@@ -4838,10 +4819,10 @@ class LocaleServiceMock extends LocaleService {
4838
4819
  super(null, { locale: {} }, locale_id, null, null, null);
4839
4820
  this.locale_id = locale_id;
4840
4821
  this.DEFAULT_LOCALE = 'en';
4841
- this.stateSubject = new BehaviorSubject({ id: this.DEFAULT_LOCALE });
4822
+ this.stateSub = new BehaviorSubject({ id: this.DEFAULT_LOCALE });
4842
4823
  }
4843
4824
  getState() {
4844
- return this.stateSubject.asObservable();
4825
+ return this.stateSub.asObservable();
4845
4826
  }
4846
4827
  updateState(state) {
4847
4828
  this.DEFAULT_LOCALE = state.id || 'en';
@@ -4851,7 +4832,7 @@ class LocaleServiceMock extends LocaleService {
4851
4832
  else if (state.id === 'el') {
4852
4833
  registerLocaleData(localeEl, 'fr');
4853
4834
  }
4854
- this.stateSubject.next(state);
4835
+ this.stateSub.next(state);
4855
4836
  }
4856
4837
  init(state) {
4857
4838
  this.DEFAULT_LOCALE = state.id || 'en';
@@ -5169,63 +5150,55 @@ class UserService extends EuiService {
5169
5150
  constructor(store) {
5170
5151
  super(UserService.DEFAULT_STATE);
5171
5152
  this.store = store;
5172
- /**
5173
- * a single signal holding the state - initial state is null
5174
- */
5175
- this.state = signal(UserService.DEFAULT_STATE, { equal: isEqual });
5176
- this.injector = inject(Injector);
5153
+ // Create a BehaviorSubject with the initial state
5154
+ this.stateSubject = new BehaviorSubject(this.stateInstance);
5155
+ // Initialize signal with base state
5156
+ this.state = toSignal(this.stateSubject, { equal: isEqual });
5157
+ // Subscribe to base class state changes
5158
+ this.onStateChange.subscribe((newState) => {
5159
+ const clonedState = structuredClone(newState);
5160
+ this.stateSubject.next(clonedState);
5161
+ });
5177
5162
  }
5178
5163
  init(state) {
5179
5164
  super.initEuiService();
5180
5165
  if (Object.prototype.hasOwnProperty.call(state, 'userId')) {
5166
+ // Let base class handle state update
5181
5167
  this.updateState(state);
5182
5168
  return of$1({ success: true });
5183
5169
  }
5184
5170
  return of$1({ success: false, error: 'Init object should be instance of BaseUserState' });
5185
5171
  }
5186
5172
  getState(keyOrMapFn) {
5187
- let computedState = computed(() => this.state());
5188
- if (keyOrMapFn) {
5189
- switch (typeof keyOrMapFn) {
5190
- case 'function':
5191
- computedState = computed(() => {
5192
- const state = this.state();
5193
- return keyOrMapFn(state);
5194
- });
5195
- break;
5196
- case 'string':
5197
- computedState = computed(() => {
5198
- const state = this.state();
5199
- const keys = keyOrMapFn.split('.');
5200
- // Traverse the object based on the dot notation
5201
- return keys.reduce((acc, currKey) => {
5202
- return acc && acc[currKey] !== undefined ? acc[currKey] : undefined;
5203
- }, state);
5204
- });
5205
- break;
5206
- }
5173
+ if (!keyOrMapFn) {
5174
+ return this.stateSubject.asObservable().pipe(distinctUntilChanged((x, y) => isEqual(x, y)));
5175
+ }
5176
+ if (typeof keyOrMapFn === 'function') {
5177
+ return this.stateSubject.asObservable().pipe(map(state => keyOrMapFn(state)), distinctUntilChanged((x, y) => isEqual(x, y)));
5207
5178
  }
5208
- // Use `runInInjectionContext` to ensure `toObservable` is within Angular injection context
5209
- return runInInjectionContext(this.injector, () => toObservable(computedState).pipe(distinctUntilChanged((x, y) => isEqual(x, y))));
5179
+ return this.stateSubject.asObservable().pipe(map(state => {
5180
+ const keys = keyOrMapFn.split('.');
5181
+ // Traverse the object based on the dot notation
5182
+ return keys.reduce((acc, currKey) => {
5183
+ return acc && acc[currKey] !== undefined ? acc[currKey] : undefined;
5184
+ }, state);
5185
+ }), distinctUntilChanged((x, y) => isEqual(x, y)));
5210
5186
  }
5211
5187
  updateState(state, reducer) {
5212
5188
  if (reducer) {
5213
- this.state.update(currentState => {
5214
- const newState = reducer(currentState, state);
5215
- return {
5216
- ...newState,
5217
- };
5218
- });
5189
+ this.stateInstance = reducer(this.stateInstance, state);
5219
5190
  }
5220
5191
  else {
5221
- this.state.update(currentState => this.deepMerge(currentState, { ...state }));
5192
+ this.stateInstance = super.deepMerge(this.stateInstance, state);
5222
5193
  }
5194
+ // Emit state change
5195
+ this.onStateChange.next(this.stateInstance);
5223
5196
  }
5224
5197
  /**
5225
5198
  * This method is used to get the signal of the service.
5226
5199
  */
5227
5200
  getSignal() {
5228
- return this.state.asReadonly();
5201
+ return this.state;
5229
5202
  }
5230
5203
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: UserService, deps: [{ token: StoreService }], target: i0.ɵɵFactoryTarget.Injectable }); }
5231
5204
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: UserService, providedIn: 'root' }); }