fix: actualiza chart.js/ngx-translate a sus APIs actuales y separa export type en el barrel
This commit is contained in:
@@ -13,7 +13,8 @@ export * from './lib/util/form-control';
|
||||
export * from './lib/util/icon-registry';
|
||||
export * from './lib/util/infinite-scroll';
|
||||
// ./lib/util/list-configs: omitido(s) por colisión con otro módulo -> featureKey, getFeatureState, initialState
|
||||
export { ListConfigsFacade, ListConfigsState, ListMode, ListModeActionsType, getListMode, listConfigsReducer, resetListMode, setListMode } from './lib/util/list-configs';
|
||||
export { getListMode, ListConfigsFacade, listConfigsReducer, ListModeActionsType, resetListMode, setListMode } from './lib/util/list-configs';
|
||||
export type { ListConfigsState, ListMode } from './lib/util/list-configs';
|
||||
export * from './lib/util/loaders';
|
||||
export * from './lib/util/local-storage';
|
||||
export * from './lib/util/menu';
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import { DatasetColor } from '../../util/models';
|
||||
import {
|
||||
ChartTypeRegistry,
|
||||
ScaleOptionsByType,
|
||||
TooltipOptions
|
||||
} from 'chart.js';
|
||||
import { ChartOptions } from 'chart.js';
|
||||
|
||||
type DeepPartial<T> = T extends object ? { [P in keyof T]?: DeepPartial<T[P]> } : T;
|
||||
/**
|
||||
* chart.js 4 ya no expone `_DeepPartialObject` en un subpath importable
|
||||
* (`chart.js/dist/types/utils` no está en su mapa de `exports`), así que
|
||||
* derivamos los tipos de las propias opciones del gráfico.
|
||||
*/
|
||||
type TooltipConfig = NonNullable<NonNullable<ChartOptions<'line'>['plugins']>['tooltip']>;
|
||||
type ScalesConfig = NonNullable<ChartOptions<'line'>['scales']>;
|
||||
|
||||
export const tooltipConfig: DeepPartial<TooltipOptions<'line'>> = {
|
||||
export const tooltipConfig: TooltipConfig = {
|
||||
backgroundColor: DatasetColor.white,
|
||||
bodyFont: {
|
||||
family: 'Soehne',
|
||||
@@ -34,9 +36,7 @@ export const tooltipConfig: DeepPartial<TooltipOptions<'line'>> = {
|
||||
titleMarginBottom: 0,
|
||||
};
|
||||
|
||||
export const scalesConfig: DeepPartial<{
|
||||
[key: string]: ScaleOptionsByType<ChartTypeRegistry['line']['scales']>;
|
||||
}> = {
|
||||
export const scalesConfig: ScalesConfig = {
|
||||
x: {
|
||||
display: true,
|
||||
grid: {
|
||||
|
||||
@@ -12,7 +12,7 @@ export class I18nService {
|
||||
return new Observable((observer) => {
|
||||
this.translateService.use(lang).subscribe({
|
||||
next: () => {
|
||||
observer.next();
|
||||
observer.next(undefined);
|
||||
observer.complete();
|
||||
},
|
||||
|
||||
|
||||
@@ -1,35 +1,25 @@
|
||||
import { Observable } from 'rxjs';
|
||||
import { TranslateLoader } from '@ngx-translate/core';
|
||||
|
||||
import { makeStateKey, StateKey, TransferState } from '@angular/core';
|
||||
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
|
||||
export class TranslateBrowserLoader implements TranslateLoader {
|
||||
constructor(private http: HttpClient, private transferState: TransferState) {}
|
||||
|
||||
public getTranslation(lang: string): Observable<any> {
|
||||
const key: StateKey<number> = makeStateKey<number>(
|
||||
'transfer-translate-' + lang
|
||||
);
|
||||
const data = this.transferState.get(key, null);
|
||||
|
||||
// First we are looking for the translations in transfer-state,
|
||||
// if none found, http load as fallback
|
||||
if (data) {
|
||||
return new Observable((observer) => {
|
||||
observer.next(data);
|
||||
observer.complete();
|
||||
});
|
||||
} else {
|
||||
return new TranslateHttpLoader(this.http).getTranslation(lang);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function translateBrowserLoaderFactory(
|
||||
httpClient: HttpClient,
|
||||
transferState: TransferState
|
||||
) {
|
||||
return new TranslateBrowserLoader(httpClient, transferState);
|
||||
}
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { TranslateLoader } from '@ngx-translate/core';
|
||||
|
||||
import { Injectable, makeStateKey, StateKey, TransferState, inject } from '@angular/core';
|
||||
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
|
||||
|
||||
/**
|
||||
* En ngx-translate 18 `TranslateHttpLoader` tiene constructor sin argumentos y
|
||||
* se resuelve por inyección (antes recibía el HttpClient), así que este loader
|
||||
* pasa a ser inyectable en vez de construirse a mano con una factoría.
|
||||
*/
|
||||
@Injectable()
|
||||
export class TranslateBrowserLoader implements TranslateLoader {
|
||||
private readonly transferState = inject(TransferState);
|
||||
private readonly httpLoader = inject(TranslateHttpLoader);
|
||||
|
||||
public getTranslation(lang: string): Observable<any> {
|
||||
const key: StateKey<number> = makeStateKey<number>('transfer-translate-' + lang);
|
||||
const data = this.transferState.get(key, null);
|
||||
|
||||
// First we are looking for the translations in transfer-state,
|
||||
// if none found, http load as fallback
|
||||
return data ? of(data) : this.httpLoader.getTranslation(lang);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,18 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { EnvironmentProviders, makeEnvironmentProviders, provideAppInitializer, inject } from '@angular/core';
|
||||
|
||||
import { TranslateLoader, TranslateService, provideTranslateService } from '@ngx-translate/core';
|
||||
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
|
||||
import { TranslateService, provideTranslateService } from '@ngx-translate/core';
|
||||
import { provideTranslateHttpLoader } from '@ngx-translate/http-loader';
|
||||
import { appInitializerFactory } from './custom-initializer';
|
||||
|
||||
export function createTranslateLoader(http: HttpClient): TranslateHttpLoader {
|
||||
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sustituye a `PiSharedUtilTranslateModule`: ngx-translate 18 ya no expone
|
||||
* `TranslateModule.forRoot()`, la configuración se hace con providers.
|
||||
* `TranslateModule.forRoot()` y `TranslateHttpLoader` se configura con
|
||||
* `provideTranslateHttpLoader` en vez de por constructor.
|
||||
*/
|
||||
export function providePiTranslate(): EnvironmentProviders {
|
||||
return makeEnvironmentProviders([
|
||||
provideTranslateService({
|
||||
fallbackLang: 'es',
|
||||
loader: {
|
||||
provide: TranslateLoader,
|
||||
useFactory: createTranslateLoader,
|
||||
deps: [HttpClient],
|
||||
},
|
||||
}),
|
||||
provideTranslateService({ fallbackLang: 'es' }),
|
||||
provideTranslateHttpLoader({ prefix: './assets/i18n/', suffix: '.json' }),
|
||||
provideAppInitializer(() => appInitializerFactory(inject(TranslateService))()),
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user