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/icon-registry';
|
||||||
export * from './lib/util/infinite-scroll';
|
export * from './lib/util/infinite-scroll';
|
||||||
// ./lib/util/list-configs: omitido(s) por colisión con otro módulo -> featureKey, getFeatureState, initialState
|
// ./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/loaders';
|
||||||
export * from './lib/util/local-storage';
|
export * from './lib/util/local-storage';
|
||||||
export * from './lib/util/menu';
|
export * from './lib/util/menu';
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
import { DatasetColor } from '../../util/models';
|
import { DatasetColor } from '../../util/models';
|
||||||
import {
|
import { ChartOptions } from 'chart.js';
|
||||||
ChartTypeRegistry,
|
|
||||||
ScaleOptionsByType,
|
|
||||||
TooltipOptions
|
|
||||||
} 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,
|
backgroundColor: DatasetColor.white,
|
||||||
bodyFont: {
|
bodyFont: {
|
||||||
family: 'Soehne',
|
family: 'Soehne',
|
||||||
@@ -34,9 +36,7 @@ export const tooltipConfig: DeepPartial<TooltipOptions<'line'>> = {
|
|||||||
titleMarginBottom: 0,
|
titleMarginBottom: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const scalesConfig: DeepPartial<{
|
export const scalesConfig: ScalesConfig = {
|
||||||
[key: string]: ScaleOptionsByType<ChartTypeRegistry['line']['scales']>;
|
|
||||||
}> = {
|
|
||||||
x: {
|
x: {
|
||||||
display: true,
|
display: true,
|
||||||
grid: {
|
grid: {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export class I18nService {
|
|||||||
return new Observable((observer) => {
|
return new Observable((observer) => {
|
||||||
this.translateService.use(lang).subscribe({
|
this.translateService.use(lang).subscribe({
|
||||||
next: () => {
|
next: () => {
|
||||||
observer.next();
|
observer.next(undefined);
|
||||||
observer.complete();
|
observer.complete();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -1,35 +1,25 @@
|
|||||||
import { Observable } from 'rxjs';
|
import { Observable, of } from 'rxjs';
|
||||||
import { TranslateLoader } from '@ngx-translate/core';
|
import { TranslateLoader } from '@ngx-translate/core';
|
||||||
|
|
||||||
import { makeStateKey, StateKey, TransferState } from '@angular/core';
|
import { Injectable, makeStateKey, StateKey, TransferState, inject } from '@angular/core';
|
||||||
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
|
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
|
||||||
import { HttpClient } from '@angular/common/http';
|
|
||||||
|
/**
|
||||||
export class TranslateBrowserLoader implements TranslateLoader {
|
* En ngx-translate 18 `TranslateHttpLoader` tiene constructor sin argumentos y
|
||||||
constructor(private http: HttpClient, private transferState: TransferState) {}
|
* 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.
|
||||||
public getTranslation(lang: string): Observable<any> {
|
*/
|
||||||
const key: StateKey<number> = makeStateKey<number>(
|
@Injectable()
|
||||||
'transfer-translate-' + lang
|
export class TranslateBrowserLoader implements TranslateLoader {
|
||||||
);
|
private readonly transferState = inject(TransferState);
|
||||||
const data = this.transferState.get(key, null);
|
private readonly httpLoader = inject(TranslateHttpLoader);
|
||||||
|
|
||||||
// First we are looking for the translations in transfer-state,
|
public getTranslation(lang: string): Observable<any> {
|
||||||
// if none found, http load as fallback
|
const key: StateKey<number> = makeStateKey<number>('transfer-translate-' + lang);
|
||||||
if (data) {
|
const data = this.transferState.get(key, null);
|
||||||
return new Observable((observer) => {
|
|
||||||
observer.next(data);
|
// First we are looking for the translations in transfer-state,
|
||||||
observer.complete();
|
// if none found, http load as fallback
|
||||||
});
|
return data ? of(data) : this.httpLoader.getTranslation(lang);
|
||||||
} else {
|
}
|
||||||
return new TranslateHttpLoader(this.http).getTranslation(lang);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function translateBrowserLoaderFactory(
|
|
||||||
httpClient: HttpClient,
|
|
||||||
transferState: TransferState
|
|
||||||
) {
|
|
||||||
return new TranslateBrowserLoader(httpClient, transferState);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,28 +1,18 @@
|
|||||||
import { HttpClient } from '@angular/common/http';
|
|
||||||
import { EnvironmentProviders, makeEnvironmentProviders, provideAppInitializer, inject } from '@angular/core';
|
import { EnvironmentProviders, makeEnvironmentProviders, provideAppInitializer, inject } from '@angular/core';
|
||||||
|
|
||||||
import { TranslateLoader, TranslateService, provideTranslateService } from '@ngx-translate/core';
|
import { TranslateService, provideTranslateService } from '@ngx-translate/core';
|
||||||
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
|
import { provideTranslateHttpLoader } from '@ngx-translate/http-loader';
|
||||||
import { appInitializerFactory } from './custom-initializer';
|
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
|
* 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 {
|
export function providePiTranslate(): EnvironmentProviders {
|
||||||
return makeEnvironmentProviders([
|
return makeEnvironmentProviders([
|
||||||
provideTranslateService({
|
provideTranslateService({ fallbackLang: 'es' }),
|
||||||
fallbackLang: 'es',
|
provideTranslateHttpLoader({ prefix: './assets/i18n/', suffix: '.json' }),
|
||||||
loader: {
|
|
||||||
provide: TranslateLoader,
|
|
||||||
useFactory: createTranslateLoader,
|
|
||||||
deps: [HttpClient],
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
provideAppInitializer(() => appInitializerFactory(inject(TranslateService))()),
|
provideAppInitializer(() => appInitializerFactory(inject(TranslateService))()),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,9 @@
|
|||||||
"declaration": true,
|
"declaration": true,
|
||||||
"declarationMap": true,
|
"declarationMap": true,
|
||||||
"inlineSources": true,
|
"inlineSources": true,
|
||||||
"types": []
|
"types": [
|
||||||
|
"node"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"src/**/*.ts"
|
"src/**/*.ts"
|
||||||
|
|||||||
Reference in New Issue
Block a user