@eui/core 22.0.0-alpha.72 → 22.0.0-alpha.74
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.
- package/CHANGELOG.md +33 -0
- package/docs/changelog.html +26 -0
- package/docs/classes/EuiAppShellServiceMock.html +2 -2
- package/docs/classes/TranslateServiceMock.html +8 -8
- package/docs/injectables/EuiDynamicMenuService.html +4 -4
- package/docs/injectables/I18nLoader.html +1 -1
- package/docs/interfaces/LoadedResources.html +2 -2
- package/docs/interfaces/Schema-1.html +46 -1
- package/docs/interfaces/Schema.html +1 -46
- package/docs/js/menu-wc.js +6 -12
- package/docs/js/search/search_index.js +2 -2
- package/docs/json/documentation.json +385 -429
- package/docs/llms.txt +26 -37
- package/docs/miscellaneous/functions.html +7 -8
- package/docs/miscellaneous/typealiases.html +48 -0
- package/docs/miscellaneous/variables.html +11 -12
- package/docs/overview.html +1 -1
- package/docs/properties.html +1 -1
- package/fesm2022/eui-core.mjs.map +1 -1
- package/package.json +2 -2
- package/types/eui-core.d.ts +11 -19
- package/types/eui-core.d.ts.map +1 -1
- package/docs/interfaces/ActionReducer.html +0 -317
- package/docs/interfaces/TranslationKeys.html +0 -272
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"pipes": [
|
|
3
3
|
{
|
|
4
4
|
"name": "TranslateMockPipe",
|
|
5
|
-
"id": "pipe-TranslateMockPipe-
|
|
5
|
+
"id": "pipe-TranslateMockPipe-4e142e09c2fb49dd6e2aa331c22b84fb560efa570a17d82a10eff3c15c008e178bccf39722626a097b93a32b8810c81f1464430e56e7ad783b79a70b96300b1e",
|
|
6
6
|
"file": "packages/core/src/lib/mocks/translate.module.mock.ts",
|
|
7
7
|
"type": "pipe",
|
|
8
8
|
"coverageIgnore": false,
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
],
|
|
51
51
|
"standalone": false,
|
|
52
52
|
"ngname": "translate",
|
|
53
|
-
"sourceCode": "import {\n AfterViewChecked,\n Directive,\n ElementRef,\n Input,\n NgModule,\n Pipe,\n PipeTransform,\n inject,\n signal,\n input,\n} from '@angular/core';\nimport { LangChangeEvent, TranslateLoader, TranslateService } from '@ngx-translate/core';\nimport { BehaviorSubject, Observable, of, Subject } from 'rxjs';\n\nexport const TRANSLATED_STRING = 'i18n';\nexport const DEFAULT_LANGUAGE = 'en';\n\nexport class TranslateServiceMock {\n onLangChangeSubject
|
|
53
|
+
"sourceCode": "import {\n AfterViewChecked,\n Directive,\n ElementRef,\n Input,\n NgModule,\n Pipe,\n PipeTransform,\n inject,\n signal,\n input,\n} from '@angular/core';\nimport { LangChangeEvent, TranslateLoader, TranslateService } from '@ngx-translate/core';\nimport { BehaviorSubject, Observable, of, Subject } from 'rxjs';\n\nexport const TRANSLATED_STRING = 'i18n';\nexport const DEFAULT_LANGUAGE = 'en';\n\nexport class TranslateServiceMock {\n onLangChangeSubject = new Subject<LangChangeEvent>();\n onTranslationChangeSubject = new Subject<string>();\n onFallbackLangChangeSubject = new Subject<string>();\n isLoadedSubject = new BehaviorSubject<boolean>(true);\n\n onLangChange: Observable<LangChangeEvent> = this.onLangChangeSubject.asObservable();\n onTranslationChange: Observable<string> = this.onTranslationChangeSubject.asObservable();\n onFallbackLangChange: Observable<string> = this.onFallbackLangChangeSubject.asObservable();\n isLoaded: Observable<boolean> = this.isLoadedSubject.asObservable();\n\n currentLang = signal<string | null>(null);\n\n languages: string[] = [DEFAULT_LANGUAGE];\n\n get(content: string): Observable<string> {\n return of(TRANSLATED_STRING + content);\n }\n\n use(lang: string): void {\n this.currentLang.set(lang);\n this.onLangChangeSubject.next({ lang } as LangChangeEvent);\n }\n\n addLangs(langs: string[]): void {\n this.languages = [...this.languages, ...langs];\n }\n\n getBrowserLang(): string {\n return DEFAULT_LANGUAGE;\n }\n\n getLangs(): string[] {\n return this.languages;\n }\n\n // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n getTranslation(): Observable<any> {\n return of({});\n }\n\n instant(key: string | string[]): string {\n return TRANSLATED_STRING + key.toString();\n }\n\n setFallbackLang(lang: string): void {\n this.onFallbackLangChangeSubject.next(lang);\n }\n}\n\n@Pipe({ name: 'translate' })\nexport class TranslateMockPipe implements PipeTransform {\n transform(text: string): string {\n return !text ? TRANSLATED_STRING : `${text}-${TRANSLATED_STRING}`;\n }\n}\n\n@Directive({\n // eslint-disable-next-line @angular-eslint/directive-selector\n selector: '[translate]',\n})\n \nexport class TranslateMockDirective implements AfterViewChecked {\n readonly translateParams = input();\n\n private readonly _element = inject(ElementRef);\n\n ngAfterViewChecked(): void {\n this._element.nativeElement.innerText += TRANSLATED_STRING;\n }\n}\n\nexport class TranslateLoaderMock implements TranslateLoader {\n getTranslation(): Observable<Record<string, string>> {\n return of({});\n }\n}\n\n@NgModule({\n imports: [TranslateMockPipe, TranslateMockDirective],\n exports: [TranslateMockPipe, TranslateMockDirective],\n providers: [\n { provide: TranslateService, useClass: TranslateServiceMock },\n { provide: TranslateLoader, useClass: TranslateLoaderMock },\n ],\n})\nexport class TranslateMockModule {}\n",
|
|
54
54
|
"relationships": {
|
|
55
55
|
"incoming": [
|
|
56
56
|
{
|
|
@@ -65,12 +65,12 @@
|
|
|
65
65
|
"interfaces": [
|
|
66
66
|
{
|
|
67
67
|
"name": "Action",
|
|
68
|
-
"id": "interface-Action-
|
|
68
|
+
"id": "interface-Action-0a0526fdcac47c7960ef767570c109d5ebaf26773cbeda85cd6f1497609565a9547497d50a2a81aa71bde65e5fce2184cadf078a8ab08d7476d1e8edafa2ce51",
|
|
69
69
|
"file": "packages/core/src/lib/services/store/ngrx_kit.ts",
|
|
70
70
|
"deprecated": false,
|
|
71
71
|
"deprecationMessage": "",
|
|
72
72
|
"type": "interface",
|
|
73
|
-
"sourceCode": "export interface ActionReducer<T, V extends Action = Action> {\n (state: T | undefined, action: V): T;\n}\n\nexport type ActionReducerMap<T, V extends Action = Action> = {\n [p in keyof T]: ActionReducer<T[p], V>;\n};\nexport interface Action<Type extends string = string> {\n type: Type;\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/explicit-function-return-type */\nexport type Selector<T, V> = (state: T) => V;\nexport type SelectorWithProps<State, Props, Result> = (\n state: State,\n props: Props\n) => Result;\n\nexport type AnyFn = (...args: any[]) => any;\n\nexport type MemoizedProjection = {\n memoized: AnyFn;\n reset: () => void;\n setResult: (result?: any) => void;\n clearResult: () => void;\n};\n\nexport type MemoizeFn = (t: AnyFn) => MemoizedProjection;\n\nexport type ComparatorFn = (a: any, b: any) => boolean;\n\nexport type DefaultProjectorFn<T> = (...args: any[]) => T;\n\nexport interface MemoizedSelector<\n State,\n Result,\n ProjectorFn = DefaultProjectorFn<Result>\n> extends Selector<State, Result> {\n release(): void;\n projector: ProjectorFn;\n setResult: (result?: Result) => void;\n clearResult: () => void;\n}\n\n/**\n * @deprecated Selectors with props are deprecated, for more info see the {@link https://ngrx.io/guide/migration/v12#ngrxstore migration guide}\n */\nexport interface MemoizedSelectorWithProps<\n State,\n Props,\n Result,\n ProjectorFn = DefaultProjectorFn<Result>\n> extends SelectorWithProps<State, Props, Result> {\n release(): void;\n projector: ProjectorFn;\n setResult: (result?: Result) => void;\n clearResult: () => void;\n}\n\nexport function isEqualCheck(a: any, b: any): boolean {\n return a === b;\n}\n\nfunction isArgumentsChanged(\n args: IArguments,\n lastArguments: IArguments,\n comparator: ComparatorFn,\n) {\n for (let i = 0; i < args.length; i++) {\n if (!comparator(args[i], lastArguments[i])) {\n return true;\n }\n }\n return false;\n}\n\nexport function defaultMemoize(\n projectionFn: AnyFn,\n isArgumentsEqual = isEqualCheck,\n isResultEqual = isEqualCheck,\n): MemoizedProjection {\n let lastArguments: null | IArguments = null;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, , , , ,\n let lastResult: any = null;\n let overrideResult: any;\n\n function reset() {\n lastArguments = null;\n lastResult = null;\n }\n\n function setResult(result: any = undefined) {\n overrideResult = { result };\n }\n\n function clearResult() {\n overrideResult = undefined;\n }\n\n /* eslint-disable prefer-rest-params, prefer-spread */\n\n // disabled because of the use of `arguments`\n function memoized(): any {\n if (overrideResult !== undefined) {\n return overrideResult.result;\n }\n\n if (!lastArguments) {\n lastResult = projectionFn.apply(null, arguments as any);\n lastArguments = arguments;\n return lastResult;\n }\n\n if (!isArgumentsChanged(arguments, lastArguments, isArgumentsEqual)) {\n return lastResult;\n }\n\n const newResult = projectionFn.apply(null, arguments as any);\n lastArguments = arguments;\n\n if (isResultEqual(lastResult, newResult)) {\n return lastResult;\n }\n\n lastResult = newResult;\n\n return newResult;\n }\n\n return { memoized, reset, setResult, clearResult };\n}\n\nexport function createSelector<State, S1, Result>(\n s1: Selector<State, S1>,\n projector: (s1: S1) => Result\n): MemoizedSelector<State, Result, typeof projector>;\n\nexport function createSelector<State, Slices extends unknown[], Result>(\n selectors: Selector<State, unknown>[] &\n [...{ [i in keyof Slices]: Selector<State, Slices[i]> }],\n projector: (...s: Slices) => Result\n): MemoizedSelector<State, Result, (...s: Slices) => Result>;\n\nexport function createSelector(\n ...input: any[]\n): MemoizedSelector<any, any> | MemoizedSelectorWithProps<any, any, any> {\n return createSelectorFactory(defaultMemoize)(...input);\n}\n\nexport function defaultStateFn(\n state: any,\n selectors: Selector<any, any>[] | SelectorWithProps<any, any, any>[],\n props: any,\n memoizedProjector: MemoizedProjection,\n): any {\n if (props === undefined) {\n const args = (<Selector<any, any>[]>selectors).map((fn) => fn(state));\n return memoizedProjector.memoized.apply(null, args);\n }\n\n const args = (<SelectorWithProps<any, any, any>[]>selectors).map((fn) =>\n fn(state, props),\n );\n return memoizedProjector.memoized.apply(null, [...args, props]);\n}\n\nexport type SelectorFactoryConfig<T = any, V = any> = {\n stateFn: (\n state: T,\n selectors: Selector<any, any>[],\n props: any,\n memoizedProjector: MemoizedProjection\n ) => V;\n};\n\nexport function createSelectorFactory<T = any, V = any>(\n memoize: MemoizeFn\n): (...input: any[]) => MemoizedSelector<T, V>;\n\n/**\n *\n * @param memoize The function used to memoize selectors\n * @param options Config Object that may include a `stateFn` function defining how to return the selector's value, given the entire `Store`'s state, parent `Selector`s, `Props`, and a `MemoizedProjection`\n *\n * @usageNotes\n *\n * **Creating a Selector Factory Where Array Order Does Not Matter**\n *\n * ```ts\n * function removeMatch(arr: string[], target: string): string[] {\n * const matchIndex = arr.indexOf(target);\n * return [...arr.slice(0, matchIndex), ...arr.slice(matchIndex + 1)];\n * }\n *\n * function orderDoesNotMatterComparer(a: any, b: any): boolean {\n * if (!Array.isArray(a) || !Array.isArray(b)) {\n * return a === b;\n * }\n * if (a.length !== b.length) {\n * return false;\n * }\n * let tempB = [...b];\n * function reduceToDetermineIfArraysContainSameContents(\n * previousCallResult: boolean,\n * arrayMember: any\n * ): boolean {\n * if (previousCallResult === false) {\n * return false;\n * }\n * if (tempB.includes(arrayMember)) {\n * tempB = removeMatch(tempB, arrayMember);\n * return true;\n * }\n * return false;\n * }\n * return a.reduce(reduceToDetermineIfArraysContainSameContents, true);\n * }\n *\n * export const createOrderDoesNotMatterSelector = createSelectorFactory(\n * (projectionFun) => defaultMemoize(\n * projectionFun,\n * orderDoesNotMatterComparer,\n * orderDoesNotMatterComparer\n * )\n * );\n * ```\n *\n * **Creating an Alternative Memoization Strategy**\n *\n * ```ts\n * function serialize(x: any): string {\n * return JSON.stringify(x);\n * }\n *\n * export const createFullHistorySelector = createSelectorFactory(\n * (projectionFunction) => {\n * const cache = {};\n *\n * function memoized() {\n * const serializedArguments = serialize(...arguments);\n * if (cache[serializedArguments] != null) {\n * cache[serializedArguments] = projectionFunction.apply(null, arguments);\n * }\n * return cache[serializedArguments];\n * }\n * return {\n * memoized,\n * reset: () => {},\n * setResult: () => {},\n * clearResult: () => {},\n * };\n * }\n * );\n * ```\n */\nexport function createSelectorFactory(\n memoize: MemoizeFn,\n options: SelectorFactoryConfig<any, any> = {\n stateFn: defaultStateFn,\n },\n) {\n return function (\n ...input: any[]\n ): MemoizedSelector<any, any> | MemoizedSelectorWithProps<any, any, any> {\n let args = input;\n if (Array.isArray(args[0])) {\n const [head, ...tail] = args;\n args = [...head, ...tail];\n } else if (args.length === 1 && isSelectorsDictionary(args[0])) {\n args = extractArgsFromSelectorsDictionary(args[0]);\n }\n\n const selectors = args.slice(0, args.length - 1);\n const projector = args[args.length - 1];\n const memoizedSelectors = selectors.filter(\n (selector: any) =>\n selector.release && typeof selector.release === 'function',\n );\n\n const memoizedProjector = memoize(function (...selectors: any[]) {\n return projector.apply(null, selectors);\n });\n\n const memoizedState = defaultMemoize(function (state: any, props: any) {\n return options.stateFn.apply(null, [\n state,\n selectors,\n props,\n memoizedProjector,\n ]);\n });\n\n function release() {\n memoizedState.reset();\n memoizedProjector.reset();\n\n memoizedSelectors.forEach((selector) => selector.release());\n }\n\n return Object.assign(memoizedState.memoized, {\n release,\n projector: memoizedProjector.memoized,\n setResult: memoizedState.setResult,\n clearResult: memoizedState.clearResult,\n });\n };\n}\n\nfunction isSelectorsDictionary(\n selectors: unknown,\n): selectors is Record<string, Selector<unknown, unknown>> {\n return (\n !!selectors &&\n typeof selectors === 'object' &&\n Object.values(selectors).every((selector) => typeof selector === 'function')\n );\n}\n\nfunction extractArgsFromSelectorsDictionary(\n selectorsDictionary: Record<string, Selector<unknown, unknown>>,\n): [\n ...selectors: Selector<unknown, unknown>[],\n projector: (...selectorResults: unknown[]) => unknown\n] {\n const selectors = Object.values(selectorsDictionary);\n const resultKeys = Object.keys(selectorsDictionary);\n const projector = (...selectorResults: unknown[]) =>\n resultKeys.reduce(\n (result, key, index) => ({\n ...result,\n [key]: selectorResults[index],\n }),\n {},\n );\n\n return [...selectors, projector];\n}\n",
|
|
73
|
+
"sourceCode": "export type ActionReducer<T, V extends Action = Action> = (state: T | undefined, action: V) => T;\n\nexport type ActionReducerMap<T, V extends Action = Action> = {\n [p in keyof T]: ActionReducer<T[p], V>;\n};\nexport interface Action<Type extends string = string> {\n type: Type;\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/explicit-function-return-type */\nexport type Selector<T, V> = (state: T) => V;\nexport type SelectorWithProps<State, Props, Result> = (\n state: State,\n props: Props\n) => Result;\n\nexport type AnyFn = (...args: any[]) => any;\n\nexport type MemoizedProjection = {\n memoized: AnyFn;\n reset: () => void;\n setResult: (result?: any) => void;\n clearResult: () => void;\n};\n\nexport type MemoizeFn = (t: AnyFn) => MemoizedProjection;\n\nexport type ComparatorFn = (a: any, b: any) => boolean;\n\nexport type DefaultProjectorFn<T> = (...args: any[]) => T;\n\nexport interface MemoizedSelector<\n State,\n Result,\n ProjectorFn = DefaultProjectorFn<Result>\n> extends Selector<State, Result> {\n release(): void;\n projector: ProjectorFn;\n setResult: (result?: Result) => void;\n clearResult: () => void;\n}\n\n/**\n * @deprecated Selectors with props are deprecated, for more info see the {@link https://ngrx.io/guide/migration/v12#ngrxstore migration guide}\n */\nexport interface MemoizedSelectorWithProps<\n State,\n Props,\n Result,\n ProjectorFn = DefaultProjectorFn<Result>\n> extends SelectorWithProps<State, Props, Result> {\n release(): void;\n projector: ProjectorFn;\n setResult: (result?: Result) => void;\n clearResult: () => void;\n}\n\nexport function isEqualCheck(a: any, b: any): boolean {\n return a === b;\n}\n\nfunction isArgumentsChanged(\n args: IArguments,\n lastArguments: IArguments,\n comparator: ComparatorFn,\n) {\n for (let i = 0; i < args.length; i++) {\n if (!comparator(args[i], lastArguments[i])) {\n return true;\n }\n }\n return false;\n}\n\nexport function defaultMemoize(\n projectionFn: AnyFn,\n isArgumentsEqual = isEqualCheck,\n isResultEqual = isEqualCheck,\n): MemoizedProjection {\n let lastArguments: null | IArguments = null;\n \n let lastResult: any = null;\n let overrideResult: any;\n\n const reset = () => {\n lastArguments = null;\n lastResult = null;\n };\n\n const setResult = (result: any = undefined) => {\n overrideResult = { result };\n };\n\n const clearResult = () => {\n overrideResult = undefined;\n };\n\n /* eslint-disable prefer-rest-params, prefer-spread */\n\n // disabled because of the use of `arguments`\n // eslint-disable-next-line prefer-arrow/prefer-arrow-functions\n function memoized(): any {\n if (overrideResult !== undefined) {\n return overrideResult.result;\n }\n\n if (!lastArguments) {\n lastResult = projectionFn.apply(null, arguments as any);\n lastArguments = arguments;\n return lastResult;\n }\n\n if (!isArgumentsChanged(arguments, lastArguments, isArgumentsEqual)) {\n return lastResult;\n }\n\n const newResult = projectionFn.apply(null, arguments as any);\n lastArguments = arguments;\n\n if (isResultEqual(lastResult, newResult)) {\n return lastResult;\n }\n\n lastResult = newResult;\n\n return newResult;\n }\n\n return { memoized, reset, setResult, clearResult };\n}\n\nexport function createSelector<State, S1, Result>(\n s1: Selector<State, S1>,\n projector: (s1: S1) => Result\n): MemoizedSelector<State, Result, typeof projector>;\n\nexport function createSelector<State, Slices extends unknown[], Result>(\n selectors: Selector<State, unknown>[] &\n [...{ [i in keyof Slices]: Selector<State, Slices[i]> }],\n projector: (...s: Slices) => Result\n): MemoizedSelector<State, Result, (...s: Slices) => Result>;\n\nexport function createSelector(\n ...input: any[]\n): MemoizedSelector<any, any> | MemoizedSelectorWithProps<any, any, any> {\n return createSelectorFactory(defaultMemoize)(...input);\n}\n\nexport function defaultStateFn(\n state: any,\n selectors: Selector<any, any>[] | SelectorWithProps<any, any, any>[],\n props: any,\n memoizedProjector: MemoizedProjection,\n): any {\n if (props === undefined) {\n const args = (selectors as Selector<any, any>[]).map((fn) => fn(state));\n return memoizedProjector.memoized.apply(null, args);\n }\n\n const args = (selectors as SelectorWithProps<any, any, any>[]).map((fn) =>\n fn(state, props),\n );\n return memoizedProjector.memoized.apply(null, [...args, props]);\n}\n\nexport type SelectorFactoryConfig<T = any, V = any> = {\n stateFn: (\n state: T,\n selectors: Selector<any, any>[],\n props: any,\n memoizedProjector: MemoizedProjection\n ) => V;\n};\n\nexport function createSelectorFactory<T = any, V = any>(\n memoize: MemoizeFn\n): (...input: any[]) => MemoizedSelector<T, V>;\n\n/**\n *\n * @param memoize The function used to memoize selectors\n * @param options Config Object that may include a `stateFn` function defining how to return the selector's value, given the entire `Store`'s state, parent `Selector`s, `Props`, and a `MemoizedProjection`\n *\n * @usageNotes\n *\n * **Creating a Selector Factory Where Array Order Does Not Matter**\n *\n * ```ts\n * function removeMatch(arr: string[], target: string): string[] {\n * const matchIndex = arr.indexOf(target);\n * return [...arr.slice(0, matchIndex), ...arr.slice(matchIndex + 1)];\n * }\n *\n * function orderDoesNotMatterComparer(a: any, b: any): boolean {\n * if (!Array.isArray(a) || !Array.isArray(b)) {\n * return a === b;\n * }\n * if (a.length !== b.length) {\n * return false;\n * }\n * let tempB = [...b];\n * function reduceToDetermineIfArraysContainSameContents(\n * previousCallResult: boolean,\n * arrayMember: any\n * ): boolean {\n * if (previousCallResult === false) {\n * return false;\n * }\n * if (tempB.includes(arrayMember)) {\n * tempB = removeMatch(tempB, arrayMember);\n * return true;\n * }\n * return false;\n * }\n * return a.reduce(reduceToDetermineIfArraysContainSameContents, true);\n * }\n *\n * export const createOrderDoesNotMatterSelector = createSelectorFactory(\n * (projectionFun) => defaultMemoize(\n * projectionFun,\n * orderDoesNotMatterComparer,\n * orderDoesNotMatterComparer\n * )\n * );\n * ```\n *\n * **Creating an Alternative Memoization Strategy**\n *\n * ```ts\n * function serialize(x: any): string {\n * return JSON.stringify(x);\n * }\n *\n * export const createFullHistorySelector = createSelectorFactory(\n * (projectionFunction) => {\n * const cache = {};\n *\n * function memoized() {\n * const serializedArguments = serialize(...arguments);\n * if (cache[serializedArguments] != null) {\n * cache[serializedArguments] = projectionFunction.apply(null, arguments);\n * }\n * return cache[serializedArguments];\n * }\n * return {\n * memoized,\n * reset: () => {},\n * setResult: () => {},\n * clearResult: () => {},\n * };\n * }\n * );\n * ```\n */\nexport function createSelectorFactory(\n memoize: MemoizeFn,\n options: SelectorFactoryConfig<any, any> = {\n stateFn: defaultStateFn,\n },\n) {\n return (...input: any[]): MemoizedSelector<any, any> | MemoizedSelectorWithProps<any, any, any> => {\n let args = input;\n if (Array.isArray(args[0])) {\n const [head, ...tail] = args;\n args = [...head, ...tail];\n } else if (args.length === 1 && isSelectorsDictionary(args[0])) {\n args = extractArgsFromSelectorsDictionary(args[0]);\n }\n\n const selectors = args.slice(0, args.length - 1);\n const projector = args[args.length - 1];\n const memoizedSelectors = selectors.filter(\n (selector: any) =>\n selector.release && typeof selector.release === 'function',\n );\n\n const memoizedProjector = memoize((...selectors: any[]) => projector.apply(null, selectors));\n\n const memoizedState = defaultMemoize((state: any, props: any) => options.stateFn.apply(null, [\n state,\n selectors,\n props,\n memoizedProjector,\n ]));\n\n const release = () => {\n memoizedState.reset();\n memoizedProjector.reset();\n\n memoizedSelectors.forEach((selector) => selector.release());\n }\n\n return Object.assign(memoizedState.memoized, {\n release,\n projector: memoizedProjector.memoized,\n setResult: memoizedState.setResult,\n clearResult: memoizedState.clearResult,\n });\n };\n}\n\nfunction isSelectorsDictionary(\n selectors: unknown,\n): selectors is Record<string, Selector<unknown, unknown>> {\n return (\n !!selectors &&\n typeof selectors === 'object' &&\n Object.values(selectors).every((selector) => typeof selector === 'function')\n );\n}\n\nfunction extractArgsFromSelectorsDictionary(\n selectorsDictionary: Record<string, Selector<unknown, unknown>>,\n): [\n ...selectors: Selector<unknown, unknown>[],\n projector: (...selectorResults: unknown[]) => unknown\n] {\n const selectors = Object.values(selectorsDictionary);\n const resultKeys = Object.keys(selectorsDictionary);\n const projector = (...selectorResults: unknown[]) =>\n resultKeys.reduce(\n (result, key, index) => ({\n ...result,\n [key]: selectorResults[index],\n }),\n {},\n );\n\n return [...selectors, projector];\n}\n",
|
|
74
74
|
"displayName": "Action<Type extends string = string>",
|
|
75
75
|
"typeParameters": [
|
|
76
76
|
"Type extends string = string"
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"indexKey": "",
|
|
86
86
|
"optional": false,
|
|
87
87
|
"description": "",
|
|
88
|
-
"line":
|
|
88
|
+
"line": 11,
|
|
89
89
|
"rawdescription": "\n"
|
|
90
90
|
}
|
|
91
91
|
],
|
|
@@ -171,59 +171,6 @@
|
|
|
171
171
|
"outgoing": []
|
|
172
172
|
}
|
|
173
173
|
},
|
|
174
|
-
{
|
|
175
|
-
"name": "ActionReducer",
|
|
176
|
-
"id": "interface-ActionReducer-0136320203d97c7881bc4d6f04f191ddd421f8a65d2d2a9a01c3a3174522e7dc3e7b4ee0f4bc8fff944b4d830517645eb2c39fd77526c8658ea00ed54906a926",
|
|
177
|
-
"file": "packages/core/src/lib/services/store/ngrx_kit.ts",
|
|
178
|
-
"deprecated": false,
|
|
179
|
-
"deprecationMessage": "",
|
|
180
|
-
"type": "interface",
|
|
181
|
-
"sourceCode": "export interface ActionReducer<T, V extends Action = Action> {\n (state: T | undefined, action: V): T;\n}\n\nexport type ActionReducerMap<T, V extends Action = Action> = {\n [p in keyof T]: ActionReducer<T[p], V>;\n};\nexport interface Action<Type extends string = string> {\n type: Type;\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/explicit-function-return-type */\nexport type Selector<T, V> = (state: T) => V;\nexport type SelectorWithProps<State, Props, Result> = (\n state: State,\n props: Props\n) => Result;\n\nexport type AnyFn = (...args: any[]) => any;\n\nexport type MemoizedProjection = {\n memoized: AnyFn;\n reset: () => void;\n setResult: (result?: any) => void;\n clearResult: () => void;\n};\n\nexport type MemoizeFn = (t: AnyFn) => MemoizedProjection;\n\nexport type ComparatorFn = (a: any, b: any) => boolean;\n\nexport type DefaultProjectorFn<T> = (...args: any[]) => T;\n\nexport interface MemoizedSelector<\n State,\n Result,\n ProjectorFn = DefaultProjectorFn<Result>\n> extends Selector<State, Result> {\n release(): void;\n projector: ProjectorFn;\n setResult: (result?: Result) => void;\n clearResult: () => void;\n}\n\n/**\n * @deprecated Selectors with props are deprecated, for more info see the {@link https://ngrx.io/guide/migration/v12#ngrxstore migration guide}\n */\nexport interface MemoizedSelectorWithProps<\n State,\n Props,\n Result,\n ProjectorFn = DefaultProjectorFn<Result>\n> extends SelectorWithProps<State, Props, Result> {\n release(): void;\n projector: ProjectorFn;\n setResult: (result?: Result) => void;\n clearResult: () => void;\n}\n\nexport function isEqualCheck(a: any, b: any): boolean {\n return a === b;\n}\n\nfunction isArgumentsChanged(\n args: IArguments,\n lastArguments: IArguments,\n comparator: ComparatorFn,\n) {\n for (let i = 0; i < args.length; i++) {\n if (!comparator(args[i], lastArguments[i])) {\n return true;\n }\n }\n return false;\n}\n\nexport function defaultMemoize(\n projectionFn: AnyFn,\n isArgumentsEqual = isEqualCheck,\n isResultEqual = isEqualCheck,\n): MemoizedProjection {\n let lastArguments: null | IArguments = null;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, , , , ,\n let lastResult: any = null;\n let overrideResult: any;\n\n function reset() {\n lastArguments = null;\n lastResult = null;\n }\n\n function setResult(result: any = undefined) {\n overrideResult = { result };\n }\n\n function clearResult() {\n overrideResult = undefined;\n }\n\n /* eslint-disable prefer-rest-params, prefer-spread */\n\n // disabled because of the use of `arguments`\n function memoized(): any {\n if (overrideResult !== undefined) {\n return overrideResult.result;\n }\n\n if (!lastArguments) {\n lastResult = projectionFn.apply(null, arguments as any);\n lastArguments = arguments;\n return lastResult;\n }\n\n if (!isArgumentsChanged(arguments, lastArguments, isArgumentsEqual)) {\n return lastResult;\n }\n\n const newResult = projectionFn.apply(null, arguments as any);\n lastArguments = arguments;\n\n if (isResultEqual(lastResult, newResult)) {\n return lastResult;\n }\n\n lastResult = newResult;\n\n return newResult;\n }\n\n return { memoized, reset, setResult, clearResult };\n}\n\nexport function createSelector<State, S1, Result>(\n s1: Selector<State, S1>,\n projector: (s1: S1) => Result\n): MemoizedSelector<State, Result, typeof projector>;\n\nexport function createSelector<State, Slices extends unknown[], Result>(\n selectors: Selector<State, unknown>[] &\n [...{ [i in keyof Slices]: Selector<State, Slices[i]> }],\n projector: (...s: Slices) => Result\n): MemoizedSelector<State, Result, (...s: Slices) => Result>;\n\nexport function createSelector(\n ...input: any[]\n): MemoizedSelector<any, any> | MemoizedSelectorWithProps<any, any, any> {\n return createSelectorFactory(defaultMemoize)(...input);\n}\n\nexport function defaultStateFn(\n state: any,\n selectors: Selector<any, any>[] | SelectorWithProps<any, any, any>[],\n props: any,\n memoizedProjector: MemoizedProjection,\n): any {\n if (props === undefined) {\n const args = (<Selector<any, any>[]>selectors).map((fn) => fn(state));\n return memoizedProjector.memoized.apply(null, args);\n }\n\n const args = (<SelectorWithProps<any, any, any>[]>selectors).map((fn) =>\n fn(state, props),\n );\n return memoizedProjector.memoized.apply(null, [...args, props]);\n}\n\nexport type SelectorFactoryConfig<T = any, V = any> = {\n stateFn: (\n state: T,\n selectors: Selector<any, any>[],\n props: any,\n memoizedProjector: MemoizedProjection\n ) => V;\n};\n\nexport function createSelectorFactory<T = any, V = any>(\n memoize: MemoizeFn\n): (...input: any[]) => MemoizedSelector<T, V>;\n\n/**\n *\n * @param memoize The function used to memoize selectors\n * @param options Config Object that may include a `stateFn` function defining how to return the selector's value, given the entire `Store`'s state, parent `Selector`s, `Props`, and a `MemoizedProjection`\n *\n * @usageNotes\n *\n * **Creating a Selector Factory Where Array Order Does Not Matter**\n *\n * ```ts\n * function removeMatch(arr: string[], target: string): string[] {\n * const matchIndex = arr.indexOf(target);\n * return [...arr.slice(0, matchIndex), ...arr.slice(matchIndex + 1)];\n * }\n *\n * function orderDoesNotMatterComparer(a: any, b: any): boolean {\n * if (!Array.isArray(a) || !Array.isArray(b)) {\n * return a === b;\n * }\n * if (a.length !== b.length) {\n * return false;\n * }\n * let tempB = [...b];\n * function reduceToDetermineIfArraysContainSameContents(\n * previousCallResult: boolean,\n * arrayMember: any\n * ): boolean {\n * if (previousCallResult === false) {\n * return false;\n * }\n * if (tempB.includes(arrayMember)) {\n * tempB = removeMatch(tempB, arrayMember);\n * return true;\n * }\n * return false;\n * }\n * return a.reduce(reduceToDetermineIfArraysContainSameContents, true);\n * }\n *\n * export const createOrderDoesNotMatterSelector = createSelectorFactory(\n * (projectionFun) => defaultMemoize(\n * projectionFun,\n * orderDoesNotMatterComparer,\n * orderDoesNotMatterComparer\n * )\n * );\n * ```\n *\n * **Creating an Alternative Memoization Strategy**\n *\n * ```ts\n * function serialize(x: any): string {\n * return JSON.stringify(x);\n * }\n *\n * export const createFullHistorySelector = createSelectorFactory(\n * (projectionFunction) => {\n * const cache = {};\n *\n * function memoized() {\n * const serializedArguments = serialize(...arguments);\n * if (cache[serializedArguments] != null) {\n * cache[serializedArguments] = projectionFunction.apply(null, arguments);\n * }\n * return cache[serializedArguments];\n * }\n * return {\n * memoized,\n * reset: () => {},\n * setResult: () => {},\n * clearResult: () => {},\n * };\n * }\n * );\n * ```\n */\nexport function createSelectorFactory(\n memoize: MemoizeFn,\n options: SelectorFactoryConfig<any, any> = {\n stateFn: defaultStateFn,\n },\n) {\n return function (\n ...input: any[]\n ): MemoizedSelector<any, any> | MemoizedSelectorWithProps<any, any, any> {\n let args = input;\n if (Array.isArray(args[0])) {\n const [head, ...tail] = args;\n args = [...head, ...tail];\n } else if (args.length === 1 && isSelectorsDictionary(args[0])) {\n args = extractArgsFromSelectorsDictionary(args[0]);\n }\n\n const selectors = args.slice(0, args.length - 1);\n const projector = args[args.length - 1];\n const memoizedSelectors = selectors.filter(\n (selector: any) =>\n selector.release && typeof selector.release === 'function',\n );\n\n const memoizedProjector = memoize(function (...selectors: any[]) {\n return projector.apply(null, selectors);\n });\n\n const memoizedState = defaultMemoize(function (state: any, props: any) {\n return options.stateFn.apply(null, [\n state,\n selectors,\n props,\n memoizedProjector,\n ]);\n });\n\n function release() {\n memoizedState.reset();\n memoizedProjector.reset();\n\n memoizedSelectors.forEach((selector) => selector.release());\n }\n\n return Object.assign(memoizedState.memoized, {\n release,\n projector: memoizedProjector.memoized,\n setResult: memoizedState.setResult,\n clearResult: memoizedState.clearResult,\n });\n };\n}\n\nfunction isSelectorsDictionary(\n selectors: unknown,\n): selectors is Record<string, Selector<unknown, unknown>> {\n return (\n !!selectors &&\n typeof selectors === 'object' &&\n Object.values(selectors).every((selector) => typeof selector === 'function')\n );\n}\n\nfunction extractArgsFromSelectorsDictionary(\n selectorsDictionary: Record<string, Selector<unknown, unknown>>,\n): [\n ...selectors: Selector<unknown, unknown>[],\n projector: (...selectorResults: unknown[]) => unknown\n] {\n const selectors = Object.values(selectorsDictionary);\n const resultKeys = Object.keys(selectorsDictionary);\n const projector = (...selectorResults: unknown[]) =>\n resultKeys.reduce(\n (result, key, index) => ({\n ...result,\n [key]: selectorResults[index],\n }),\n {},\n );\n\n return [...selectors, projector];\n}\n",
|
|
182
|
-
"displayName": "ActionReducer<T, V extends Action = Action>",
|
|
183
|
-
"typeParameters": [
|
|
184
|
-
"T",
|
|
185
|
-
"V extends Action = Action"
|
|
186
|
-
],
|
|
187
|
-
"properties": [
|
|
188
|
-
{
|
|
189
|
-
"id": "call-declaration-0136320203d97c7881bc4d6f04f191ddd421f8a65d2d2a9a01c3a3174522e7dc3e7b4ee0f4bc8fff944b4d830517645eb2c39fd77526c8658ea00ed54906a926",
|
|
190
|
-
"args": [
|
|
191
|
-
{
|
|
192
|
-
"name": "state",
|
|
193
|
-
"type": "T | undefined",
|
|
194
|
-
"optional": false,
|
|
195
|
-
"dotDotDotToken": false,
|
|
196
|
-
"deprecated": false,
|
|
197
|
-
"deprecationMessage": ""
|
|
198
|
-
},
|
|
199
|
-
{
|
|
200
|
-
"name": "action",
|
|
201
|
-
"type": "V",
|
|
202
|
-
"optional": false,
|
|
203
|
-
"dotDotDotToken": false,
|
|
204
|
-
"deprecated": false,
|
|
205
|
-
"deprecationMessage": ""
|
|
206
|
-
}
|
|
207
|
-
],
|
|
208
|
-
"returnType": "T",
|
|
209
|
-
"line": 5,
|
|
210
|
-
"deprecated": false,
|
|
211
|
-
"deprecationMessage": "",
|
|
212
|
-
"rawdescription": "\n",
|
|
213
|
-
"description": ""
|
|
214
|
-
}
|
|
215
|
-
],
|
|
216
|
-
"indexSignatures": [],
|
|
217
|
-
"kind": 180,
|
|
218
|
-
"description": "<p>A function that takes an <code>Action</code> and a <code>State</code>, and returns a <code>State</code>.\nSee <code>createReducer</code>.</p>\n",
|
|
219
|
-
"rawdescription": "\n\nA function that takes an `Action` and a `State`, and returns a `State`.\nSee `createReducer`.\n",
|
|
220
|
-
"methods": [],
|
|
221
|
-
"extends": [],
|
|
222
|
-
"relationships": {
|
|
223
|
-
"incoming": [],
|
|
224
|
-
"outgoing": []
|
|
225
|
-
}
|
|
226
|
-
},
|
|
227
174
|
{
|
|
228
175
|
"name": "Annotation",
|
|
229
176
|
"id": "interface-Annotation-0802af7de093a6df989cd8f4bc7da55cd9729f34d4642b7f5d9eae9f9a14cae4d644922a9d7ece99ba5b1c23696d54d83436ff79a54a50c37ade3ebbf0cbf92a",
|
|
@@ -284,12 +231,12 @@
|
|
|
284
231
|
},
|
|
285
232
|
{
|
|
286
233
|
"name": "body",
|
|
287
|
-
"id": "interface-body-
|
|
234
|
+
"id": "interface-body-fccb761e8d5849baa5005029d5b63ce5da9abf59e665ab7d08910bd0b4b237bee688744c7650083b0c68eaaeec208267921e73ada3ebc977b8d4265ea729aacf",
|
|
288
235
|
"file": "packages/core/src/lib/interceptors/eu-login-session-timeout-handling.interceptor.ts",
|
|
289
236
|
"deprecated": false,
|
|
290
237
|
"deprecationMessage": "",
|
|
291
238
|
"type": "interface",
|
|
292
|
-
"sourceCode": "import { Injectable } from '@angular/core';\nimport { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse, HttpResponseBase } from '@angular/common/http';\nimport { Observable } from 'rxjs';\nimport { tap } from 'rxjs/operators';\n\ninterface body {\n success: boolean;\n status: string;\n code: number;\n message: string;\n}\n\n// The EuLoginSessionTimeoutHandlingInterceptor assumes that the EU login client is configured with:\n// <redirectionInterceptor>eu.cec.digit.ecas.client.http.ajax.JsonAjaxRedirectionInterceptor</redirectionInterceptor>\n// WARNING: The default EU login client behaviour that provides the JSON-un-parsable login HTML page, is no longer supported!\n@Injectable()\nexport class EuLoginSessionTimeoutHandlingInterceptor implements HttpInterceptor {\n intercept<T extends body>(request: HttpRequest<T>, next: HttpHandler): Observable<HttpEvent<T>> {\n return next.handle(request).pipe(\n tap({\n next: (event) => {\n this.checkRequestSuccessForEULoginSessionTimeout(request, event);\n return event;\n },\n error: (error) => {\n this.checkRequestErrorForEULoginSessionTimeout(request, error);\n },\n }),\n );\n }\n\n protected checkRequestSuccessForEULoginSessionTimeout<T extends body, E>(request: HttpRequest<T>, event: HttpEvent<E>): void {\n if (event instanceof HttpResponse) {\n if (this.isSsoResponse((
|
|
239
|
+
"sourceCode": "import { Injectable } from '@angular/core';\nimport { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse, HttpResponseBase } from '@angular/common/http';\nimport { Observable } from 'rxjs';\nimport { tap } from 'rxjs/operators';\n\ninterface body {\n success: boolean;\n status: string;\n code: number;\n message: string;\n}\n\n// The EuLoginSessionTimeoutHandlingInterceptor assumes that the EU login client is configured with:\n// <redirectionInterceptor>eu.cec.digit.ecas.client.http.ajax.JsonAjaxRedirectionInterceptor</redirectionInterceptor>\n// WARNING: The default EU login client behaviour that provides the JSON-un-parsable login HTML page, is no longer supported!\n@Injectable()\nexport class EuLoginSessionTimeoutHandlingInterceptor implements HttpInterceptor {\n intercept<T extends body>(request: HttpRequest<T>, next: HttpHandler): Observable<HttpEvent<T>> {\n return next.handle(request).pipe(\n tap({\n next: (event) => {\n this.checkRequestSuccessForEULoginSessionTimeout(request, event);\n return event;\n },\n error: (error) => {\n this.checkRequestErrorForEULoginSessionTimeout(request, error);\n },\n }),\n );\n }\n\n protected checkRequestSuccessForEULoginSessionTimeout<T extends body, E>(request: HttpRequest<T>, event: HttpEvent<E>): void {\n if (event instanceof HttpResponse) {\n if (this.isSsoResponse((event as HttpResponse<string | body>).body)) {\n this.reauthenticate();\n }\n }\n }\n\n protected checkRequestErrorForEULoginSessionTimeout<T = unknown>(request: HttpRequest<T>, response: HttpResponseBase): void {\n /* intentionally blank; meant for overriding */\n }\n\n protected isSsoResponse(body: string | body | null): boolean {\n if (body) {\n if (typeof body !== 'string') {\n return (\n body.success === false &&\n body.status === 'ECAS_AUTHENTICATION_REQUIRED' &&\n body.code === 303 &&\n body.message === 'session expired'\n );\n } else {\n const html = body;\n try {\n return (\n (html.indexOf('<meta name=\"Keywords\" content=\"EU Login, ECAS, Authentication, Security\" />') >= 0 &&\n html.indexOf('<meta name=\"Description\" content=\"EU Login\" />') >= 0) ||\n html.indexOf('<meta name=\"Description\" content=\"European Commission Authentication Service\" />') >= 0 ||\n html.indexOf('<title>Mock Login Form</title>') >= 0 ||\n html.indexOf('<title>Redirecting To ECAS</title>') >= 0 ||\n html === '{ success : false, status : \"ECAS_AUTHENTICATION_REQUIRED\", code : 303, message : \"session expired\" }' ||\n \n JSON.stringify(JSON.parse(html)) ===\n JSON.stringify({\n success: false,\n status: 'ECAS_AUTHENTICATION_REQUIRED',\n code: 303,\n message: 'session expired',\n })\n );\n } catch (e) {\n return false;\n }\n }\n } else {\n return false;\n }\n }\n\n protected reauthenticate(): void {\n document.location.reload();\n }\n}\n",
|
|
293
240
|
"displayName": "body",
|
|
294
241
|
"properties": [
|
|
295
242
|
{
|
|
@@ -2202,12 +2149,12 @@
|
|
|
2202
2149
|
},
|
|
2203
2150
|
{
|
|
2204
2151
|
"name": "LoadedResources",
|
|
2205
|
-
"id": "interface-LoadedResources-
|
|
2152
|
+
"id": "interface-LoadedResources-5c76c65c641a590c27fa827029ac4ce1fd7224732a481d314bfbbb45f31b0f77fb51f6478ac93e8d43f8d8694d33a791b51931801364c1b6b8d9589141ed8171",
|
|
2206
2153
|
"file": "packages/core/src/lib/services/i18n/i18n.loader.ts",
|
|
2207
2154
|
"deprecated": false,
|
|
2208
2155
|
"deprecationMessage": "",
|
|
2209
2156
|
"type": "interface",
|
|
2210
|
-
"sourceCode": "import { Injectable, inject } from '@angular/core';\nimport { HttpClient } from '@angular/common/http';\nimport { TranslateLoader, TranslationObject, provideTranslateLoader } from '@ngx-translate/core';\nimport { forkJoin, Observable, of } from 'rxjs';\nimport { catchError, map } from 'rxjs/operators';\n\nimport {\n getI18nLoaderConfig,\n I18nResource,\n type EuiAppConfig,\n mergeAll,\n Logger,\n I18nLoaderConfig,\n I18nConfig,\n TranslationsCompiler,\n} from '@eui/base';\nimport { I18nResourceImpl } from './i18n.resource';\nimport { CONFIG_TOKEN } from '../config/tokens';\nimport { LogService } from '../log/log.service';\nimport { transformTranslations } from './i18n-utils';\n\ninterface ResourceError {\n isError: boolean;\n error?: string;\n resource?: I18nResourceImpl;\n}\n\nexport interface LoadedResources {\n translations: TranslationObject;\n hasError: boolean;\n errors?:
|
|
2157
|
+
"sourceCode": "import { Injectable, inject } from '@angular/core';\nimport { HttpClient } from '@angular/common/http';\nimport { TranslateLoader, TranslationObject, provideTranslateLoader } from '@ngx-translate/core';\nimport { forkJoin, Observable, of } from 'rxjs';\nimport { catchError, map } from 'rxjs/operators';\n\nimport {\n getI18nLoaderConfig,\n I18nResource,\n type EuiAppConfig,\n mergeAll,\n Logger,\n I18nLoaderConfig,\n I18nConfig,\n TranslationsCompiler,\n} from '@eui/base';\nimport { I18nResourceImpl } from './i18n.resource';\nimport { CONFIG_TOKEN } from '../config/tokens';\nimport { LogService } from '../log/log.service';\nimport { transformTranslations } from './i18n-utils';\n\ninterface ResourceError {\n isError: boolean;\n error?: string;\n resource?: I18nResourceImpl;\n}\n\nexport interface LoadedResources {\n translations: TranslationObject;\n hasError: boolean;\n errors?: LoadedResourcesError[];\n}\n\nexport interface LoadedResourcesError {\n resource: I18nResourceImpl;\n error: string;\n}\n\nexport type TranslationKeys = Record<string, string>;\n\n@Injectable()\nexport class I18nLoader implements TranslateLoader {\n protected http = inject(HttpClient);\n protected logService = inject(LogService, { optional: true });\n protected euiAppConfig = inject<EuiAppConfig>(CONFIG_TOKEN);\n\n protected resources: I18nResourceImpl[] = [];\n protected failedResources: LoadedResourcesError[] = [];\n private logger: Logger | undefined;\n private icuEnabled: boolean;\n\n constructor() {\n const logService = this.logService;\n\n if (logService) {\n this.logger = logService.getLogger('core.I18nLoader')\n }\n\n // create the resources from the config object\n const i18nConfig: I18nConfig | undefined = this.euiAppConfig.global && this.euiAppConfig.global.i18n;\n const i18nLoaderConfig: I18nLoaderConfig | undefined = i18nConfig && i18nConfig.i18nLoader;\n this.resources.push(...this.createResources(i18nLoaderConfig as I18nLoaderConfig));\n\n // Auto-detect ICU mode from config\n this.icuEnabled = !!(i18nConfig && i18nConfig.icuEnabled);\n }\n\n /**\n * Gets the translations from the server\n *\n * @param lang\n * @returns Observable<object>\n */\n public getTranslation(lang: string): Observable<TranslationObject> {\n return this.loadResources(this.resources, lang).pipe(\n map((loadedResources: LoadedResources) => {\n this.failedResources = loadedResources.hasError ? (loadedResources.errors as LoadedResourcesError[]) : [];\n const translations = loadedResources.translations;\n return this.icuEnabled ? transformTranslations(translations) : translations;\n }),\n );\n }\n\n /**\n * Adds resources\n *\n * @param config loader configuration\n * @returns Observable<any> | false\n */\n public addResources(config: I18nLoaderConfig): I18nResourceImpl[] {\n // create the resources\n let resources = this.createResources(config);\n\n // filter the resources first, to avoid duplicates\n resources = resources.filter((resource) => !this.resources.some((res) => res.equals(resource)));\n\n // add the new resources to the list of existing resources\n this.resources.push(...resources);\n\n // return the filtered resources\n return resources;\n }\n\n /**\n * Removes resources from the loader instance\n */\n public removeResources(removedResources: I18nResourceImpl[]): void {\n this.resources = this.resources.filter((res) => !removedResources.some((removedResource) => removedResource.equals(res)));\n }\n\n /**\n * Loads an array of resources, by language\n *\n * @param resources the definition of the resources\n * @param lang the resource language to load\n * @returns Observable<any>\n */\n public loadResources(resources: I18nResourceImpl[], lang: string): Observable<{ hasError: boolean; translations: TranslationObject; errors?: LoadedResourcesError[] }> {\n // if there are resources to load\n if (Array.isArray(resources) && resources.length > 0) {\n // load all the resources in an array of Observable\n const requests = resources.map((resource) => this.loadResource(resource, lang));\n // group all the observables with forkJoin and deep merge them\n return forkJoin(requests).pipe(\n map((response) => {\n const successResp: TranslationKeys[] = [];\n const errResp: LoadedResourcesError[] = [];\n response.forEach((item) => {\n if ((item as ResourceError).isError) {\n errResp.push({ resource: (item as ResourceError).resource as I18nResourceImpl, error: (item as ResourceError).error as string });\n } else {\n successResp.push(item as TranslationKeys);\n }\n });\n if (successResp.length === response.length) {\n return { hasError: false, translations: mergeAll(successResp) };\n } else {\n return { hasError: true, translations: mergeAll(successResp), errors: errResp };\n }\n }),\n );\n } else {\n // no resources to load\n return of({ hasError: false, translations: {} });\n }\n }\n\n /**\n * Returns resources that failed\n */\n public getFailedResources(): LoadedResourcesError[] {\n return this.failedResources;\n }\n\n /**\n * Create resources from a config file\n *\n * @param config loader configuration\n * @returns I18nResourceImpl[] resources\n */\n protected createResources(config: I18nLoaderConfig): I18nResourceImpl[] {\n // use the default config as a reference base\n config = getI18nLoaderConfig(config);\n\n const resources: I18nResourceImpl[] = [];\n\n // extract the i18n folders from config\n const i18nFolders: string[] = Array.isArray(config.i18nFolders)\n ? config.i18nFolders\n : config.i18nFolders\n ? [config.i18nFolders]\n : [];\n if (i18nFolders) {\n // add the i18n folders to resources\n resources.push(...i18nFolders.map((folder) => new I18nResourceImpl(`assets/${folder}/`, '.json')));\n }\n\n // extract the i18n services from config\n const i18nServices: string[] = Array.isArray(config.i18nServices)\n ? config.i18nServices\n : config.i18nServices\n ? [config.i18nServices]\n : [];\n if (i18nServices) {\n // add the i18n services to resources\n resources.push(...i18nServices.map((service) => new I18nResourceImpl(service)));\n }\n\n // extract the i18n resources from config\n const i18nResources: I18nResource[] = Array.isArray(config.i18nResources)\n ? config.i18nResources\n : config.i18nResources\n ? [config.i18nResources]\n : [];\n if (i18nResources) {\n // add the i18n resources to resources\n resources.push(\n ...i18nResources.map(\n (resource) =>\n new I18nResourceImpl(\n resource.prefix,\n resource.suffix,\n this.getResourceCompileFunction(resource.compileTranslations as string),\n ),\n ),\n );\n }\n\n return resources;\n }\n\n /**\n * Loads a resource, by language\n *\n * @param resource the definition of the resource\n * @param lang the resource language to load\n * @returns Observable<any>\n */\n protected loadResource(resource: I18nResourceImpl, lang: string): Observable<TranslationKeys | ResourceError> {\n // the path to the resource\n const path = resource.getPath(lang);\n\n // load the translations from the path\n return this.http.get(path).pipe(\n // preprocess the translations using the resource compiler\n map((translations: unknown) => resource.compileTranslations(translations, lang) as TranslationKeys),\n map((translations: TranslationKeys) => {\n // resource loaded properly, send a info message\n this.logger?.info(`I18n resource loaded from path ${path}`);\n // return the translations\n return translations;\n }),\n catchError((err) => {\n // remove failed resource from loaded resource array\n // this.removeResources([resource]);\n // resource not loaded properly, send a warning message\n this.logger?.warn(`I18n resource NOT loaded from path ${path}`, err);\n const resourceError: ResourceError = { error: `I18n resource NOT loaded from path ${path}`, resource, isError: true };\n return of(resourceError);\n }),\n );\n }\n\n private getResourceCompileFunction(id: string): TranslationsCompiler | undefined {\n const customHandlers = this.euiAppConfig.customHandler;\n if (customHandlers && typeof customHandlers[id] === 'function') {\n return customHandlers[id];\n }\n return undefined;\n }\n}\n\nexport const translateConfig = {\n loader: provideTranslateLoader(I18nLoader),\n};\n",
|
|
2211
2158
|
"displayName": "LoadedResources",
|
|
2212
2159
|
"properties": [
|
|
2213
2160
|
{
|
|
@@ -2215,7 +2162,7 @@
|
|
|
2215
2162
|
"coverageIgnore": false,
|
|
2216
2163
|
"deprecated": false,
|
|
2217
2164
|
"deprecationMessage": "",
|
|
2218
|
-
"type": "
|
|
2165
|
+
"type": "LoadedResourcesError[]",
|
|
2219
2166
|
"indexKey": "",
|
|
2220
2167
|
"optional": true,
|
|
2221
2168
|
"description": "",
|
|
@@ -2258,12 +2205,12 @@
|
|
|
2258
2205
|
},
|
|
2259
2206
|
{
|
|
2260
2207
|
"name": "LoadedResourcesError",
|
|
2261
|
-
"id": "interface-LoadedResourcesError-
|
|
2208
|
+
"id": "interface-LoadedResourcesError-5c76c65c641a590c27fa827029ac4ce1fd7224732a481d314bfbbb45f31b0f77fb51f6478ac93e8d43f8d8694d33a791b51931801364c1b6b8d9589141ed8171",
|
|
2262
2209
|
"file": "packages/core/src/lib/services/i18n/i18n.loader.ts",
|
|
2263
2210
|
"deprecated": false,
|
|
2264
2211
|
"deprecationMessage": "",
|
|
2265
2212
|
"type": "interface",
|
|
2266
|
-
"sourceCode": "import { Injectable, inject } from '@angular/core';\nimport { HttpClient } from '@angular/common/http';\nimport { TranslateLoader, TranslationObject, provideTranslateLoader } from '@ngx-translate/core';\nimport { forkJoin, Observable, of } from 'rxjs';\nimport { catchError, map } from 'rxjs/operators';\n\nimport {\n getI18nLoaderConfig,\n I18nResource,\n type EuiAppConfig,\n mergeAll,\n Logger,\n I18nLoaderConfig,\n I18nConfig,\n TranslationsCompiler,\n} from '@eui/base';\nimport { I18nResourceImpl } from './i18n.resource';\nimport { CONFIG_TOKEN } from '../config/tokens';\nimport { LogService } from '../log/log.service';\nimport { transformTranslations } from './i18n-utils';\n\ninterface ResourceError {\n isError: boolean;\n error?: string;\n resource?: I18nResourceImpl;\n}\n\nexport interface LoadedResources {\n translations: TranslationObject;\n hasError: boolean;\n errors?:
|
|
2213
|
+
"sourceCode": "import { Injectable, inject } from '@angular/core';\nimport { HttpClient } from '@angular/common/http';\nimport { TranslateLoader, TranslationObject, provideTranslateLoader } from '@ngx-translate/core';\nimport { forkJoin, Observable, of } from 'rxjs';\nimport { catchError, map } from 'rxjs/operators';\n\nimport {\n getI18nLoaderConfig,\n I18nResource,\n type EuiAppConfig,\n mergeAll,\n Logger,\n I18nLoaderConfig,\n I18nConfig,\n TranslationsCompiler,\n} from '@eui/base';\nimport { I18nResourceImpl } from './i18n.resource';\nimport { CONFIG_TOKEN } from '../config/tokens';\nimport { LogService } from '../log/log.service';\nimport { transformTranslations } from './i18n-utils';\n\ninterface ResourceError {\n isError: boolean;\n error?: string;\n resource?: I18nResourceImpl;\n}\n\nexport interface LoadedResources {\n translations: TranslationObject;\n hasError: boolean;\n errors?: LoadedResourcesError[];\n}\n\nexport interface LoadedResourcesError {\n resource: I18nResourceImpl;\n error: string;\n}\n\nexport type TranslationKeys = Record<string, string>;\n\n@Injectable()\nexport class I18nLoader implements TranslateLoader {\n protected http = inject(HttpClient);\n protected logService = inject(LogService, { optional: true });\n protected euiAppConfig = inject<EuiAppConfig>(CONFIG_TOKEN);\n\n protected resources: I18nResourceImpl[] = [];\n protected failedResources: LoadedResourcesError[] = [];\n private logger: Logger | undefined;\n private icuEnabled: boolean;\n\n constructor() {\n const logService = this.logService;\n\n if (logService) {\n this.logger = logService.getLogger('core.I18nLoader')\n }\n\n // create the resources from the config object\n const i18nConfig: I18nConfig | undefined = this.euiAppConfig.global && this.euiAppConfig.global.i18n;\n const i18nLoaderConfig: I18nLoaderConfig | undefined = i18nConfig && i18nConfig.i18nLoader;\n this.resources.push(...this.createResources(i18nLoaderConfig as I18nLoaderConfig));\n\n // Auto-detect ICU mode from config\n this.icuEnabled = !!(i18nConfig && i18nConfig.icuEnabled);\n }\n\n /**\n * Gets the translations from the server\n *\n * @param lang\n * @returns Observable<object>\n */\n public getTranslation(lang: string): Observable<TranslationObject> {\n return this.loadResources(this.resources, lang).pipe(\n map((loadedResources: LoadedResources) => {\n this.failedResources = loadedResources.hasError ? (loadedResources.errors as LoadedResourcesError[]) : [];\n const translations = loadedResources.translations;\n return this.icuEnabled ? transformTranslations(translations) : translations;\n }),\n );\n }\n\n /**\n * Adds resources\n *\n * @param config loader configuration\n * @returns Observable<any> | false\n */\n public addResources(config: I18nLoaderConfig): I18nResourceImpl[] {\n // create the resources\n let resources = this.createResources(config);\n\n // filter the resources first, to avoid duplicates\n resources = resources.filter((resource) => !this.resources.some((res) => res.equals(resource)));\n\n // add the new resources to the list of existing resources\n this.resources.push(...resources);\n\n // return the filtered resources\n return resources;\n }\n\n /**\n * Removes resources from the loader instance\n */\n public removeResources(removedResources: I18nResourceImpl[]): void {\n this.resources = this.resources.filter((res) => !removedResources.some((removedResource) => removedResource.equals(res)));\n }\n\n /**\n * Loads an array of resources, by language\n *\n * @param resources the definition of the resources\n * @param lang the resource language to load\n * @returns Observable<any>\n */\n public loadResources(resources: I18nResourceImpl[], lang: string): Observable<{ hasError: boolean; translations: TranslationObject; errors?: LoadedResourcesError[] }> {\n // if there are resources to load\n if (Array.isArray(resources) && resources.length > 0) {\n // load all the resources in an array of Observable\n const requests = resources.map((resource) => this.loadResource(resource, lang));\n // group all the observables with forkJoin and deep merge them\n return forkJoin(requests).pipe(\n map((response) => {\n const successResp: TranslationKeys[] = [];\n const errResp: LoadedResourcesError[] = [];\n response.forEach((item) => {\n if ((item as ResourceError).isError) {\n errResp.push({ resource: (item as ResourceError).resource as I18nResourceImpl, error: (item as ResourceError).error as string });\n } else {\n successResp.push(item as TranslationKeys);\n }\n });\n if (successResp.length === response.length) {\n return { hasError: false, translations: mergeAll(successResp) };\n } else {\n return { hasError: true, translations: mergeAll(successResp), errors: errResp };\n }\n }),\n );\n } else {\n // no resources to load\n return of({ hasError: false, translations: {} });\n }\n }\n\n /**\n * Returns resources that failed\n */\n public getFailedResources(): LoadedResourcesError[] {\n return this.failedResources;\n }\n\n /**\n * Create resources from a config file\n *\n * @param config loader configuration\n * @returns I18nResourceImpl[] resources\n */\n protected createResources(config: I18nLoaderConfig): I18nResourceImpl[] {\n // use the default config as a reference base\n config = getI18nLoaderConfig(config);\n\n const resources: I18nResourceImpl[] = [];\n\n // extract the i18n folders from config\n const i18nFolders: string[] = Array.isArray(config.i18nFolders)\n ? config.i18nFolders\n : config.i18nFolders\n ? [config.i18nFolders]\n : [];\n if (i18nFolders) {\n // add the i18n folders to resources\n resources.push(...i18nFolders.map((folder) => new I18nResourceImpl(`assets/${folder}/`, '.json')));\n }\n\n // extract the i18n services from config\n const i18nServices: string[] = Array.isArray(config.i18nServices)\n ? config.i18nServices\n : config.i18nServices\n ? [config.i18nServices]\n : [];\n if (i18nServices) {\n // add the i18n services to resources\n resources.push(...i18nServices.map((service) => new I18nResourceImpl(service)));\n }\n\n // extract the i18n resources from config\n const i18nResources: I18nResource[] = Array.isArray(config.i18nResources)\n ? config.i18nResources\n : config.i18nResources\n ? [config.i18nResources]\n : [];\n if (i18nResources) {\n // add the i18n resources to resources\n resources.push(\n ...i18nResources.map(\n (resource) =>\n new I18nResourceImpl(\n resource.prefix,\n resource.suffix,\n this.getResourceCompileFunction(resource.compileTranslations as string),\n ),\n ),\n );\n }\n\n return resources;\n }\n\n /**\n * Loads a resource, by language\n *\n * @param resource the definition of the resource\n * @param lang the resource language to load\n * @returns Observable<any>\n */\n protected loadResource(resource: I18nResourceImpl, lang: string): Observable<TranslationKeys | ResourceError> {\n // the path to the resource\n const path = resource.getPath(lang);\n\n // load the translations from the path\n return this.http.get(path).pipe(\n // preprocess the translations using the resource compiler\n map((translations: unknown) => resource.compileTranslations(translations, lang) as TranslationKeys),\n map((translations: TranslationKeys) => {\n // resource loaded properly, send a info message\n this.logger?.info(`I18n resource loaded from path ${path}`);\n // return the translations\n return translations;\n }),\n catchError((err) => {\n // remove failed resource from loaded resource array\n // this.removeResources([resource]);\n // resource not loaded properly, send a warning message\n this.logger?.warn(`I18n resource NOT loaded from path ${path}`, err);\n const resourceError: ResourceError = { error: `I18n resource NOT loaded from path ${path}`, resource, isError: true };\n return of(resourceError);\n }),\n );\n }\n\n private getResourceCompileFunction(id: string): TranslationsCompiler | undefined {\n const customHandlers = this.euiAppConfig.customHandler;\n if (customHandlers && typeof customHandlers[id] === 'function') {\n return customHandlers[id];\n }\n return undefined;\n }\n}\n\nexport const translateConfig = {\n loader: provideTranslateLoader(I18nLoader),\n};\n",
|
|
2267
2214
|
"displayName": "LoadedResourcesError",
|
|
2268
2215
|
"properties": [
|
|
2269
2216
|
{
|
|
@@ -2302,12 +2249,12 @@
|
|
|
2302
2249
|
},
|
|
2303
2250
|
{
|
|
2304
2251
|
"name": "MemoizedSelector",
|
|
2305
|
-
"id": "interface-MemoizedSelector-
|
|
2252
|
+
"id": "interface-MemoizedSelector-0a0526fdcac47c7960ef767570c109d5ebaf26773cbeda85cd6f1497609565a9547497d50a2a81aa71bde65e5fce2184cadf078a8ab08d7476d1e8edafa2ce51",
|
|
2306
2253
|
"file": "packages/core/src/lib/services/store/ngrx_kit.ts",
|
|
2307
2254
|
"deprecated": false,
|
|
2308
2255
|
"deprecationMessage": "",
|
|
2309
2256
|
"type": "interface",
|
|
2310
|
-
"sourceCode": "export interface ActionReducer<T, V extends Action = Action> {\n (state: T | undefined, action: V): T;\n}\n\nexport type ActionReducerMap<T, V extends Action = Action> = {\n [p in keyof T]: ActionReducer<T[p], V>;\n};\nexport interface Action<Type extends string = string> {\n type: Type;\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/explicit-function-return-type */\nexport type Selector<T, V> = (state: T) => V;\nexport type SelectorWithProps<State, Props, Result> = (\n state: State,\n props: Props\n) => Result;\n\nexport type AnyFn = (...args: any[]) => any;\n\nexport type MemoizedProjection = {\n memoized: AnyFn;\n reset: () => void;\n setResult: (result?: any) => void;\n clearResult: () => void;\n};\n\nexport type MemoizeFn = (t: AnyFn) => MemoizedProjection;\n\nexport type ComparatorFn = (a: any, b: any) => boolean;\n\nexport type DefaultProjectorFn<T> = (...args: any[]) => T;\n\nexport interface MemoizedSelector<\n State,\n Result,\n ProjectorFn = DefaultProjectorFn<Result>\n> extends Selector<State, Result> {\n release(): void;\n projector: ProjectorFn;\n setResult: (result?: Result) => void;\n clearResult: () => void;\n}\n\n/**\n * @deprecated Selectors with props are deprecated, for more info see the {@link https://ngrx.io/guide/migration/v12#ngrxstore migration guide}\n */\nexport interface MemoizedSelectorWithProps<\n State,\n Props,\n Result,\n ProjectorFn = DefaultProjectorFn<Result>\n> extends SelectorWithProps<State, Props, Result> {\n release(): void;\n projector: ProjectorFn;\n setResult: (result?: Result) => void;\n clearResult: () => void;\n}\n\nexport function isEqualCheck(a: any, b: any): boolean {\n return a === b;\n}\n\nfunction isArgumentsChanged(\n args: IArguments,\n lastArguments: IArguments,\n comparator: ComparatorFn,\n) {\n for (let i = 0; i < args.length; i++) {\n if (!comparator(args[i], lastArguments[i])) {\n return true;\n }\n }\n return false;\n}\n\nexport function defaultMemoize(\n projectionFn: AnyFn,\n isArgumentsEqual = isEqualCheck,\n isResultEqual = isEqualCheck,\n): MemoizedProjection {\n let lastArguments: null | IArguments = null;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, , , , ,\n let lastResult: any = null;\n let overrideResult: any;\n\n function reset() {\n lastArguments = null;\n lastResult = null;\n }\n\n function setResult(result: any = undefined) {\n overrideResult = { result };\n }\n\n function clearResult() {\n overrideResult = undefined;\n }\n\n /* eslint-disable prefer-rest-params, prefer-spread */\n\n // disabled because of the use of `arguments`\n function memoized(): any {\n if (overrideResult !== undefined) {\n return overrideResult.result;\n }\n\n if (!lastArguments) {\n lastResult = projectionFn.apply(null, arguments as any);\n lastArguments = arguments;\n return lastResult;\n }\n\n if (!isArgumentsChanged(arguments, lastArguments, isArgumentsEqual)) {\n return lastResult;\n }\n\n const newResult = projectionFn.apply(null, arguments as any);\n lastArguments = arguments;\n\n if (isResultEqual(lastResult, newResult)) {\n return lastResult;\n }\n\n lastResult = newResult;\n\n return newResult;\n }\n\n return { memoized, reset, setResult, clearResult };\n}\n\nexport function createSelector<State, S1, Result>(\n s1: Selector<State, S1>,\n projector: (s1: S1) => Result\n): MemoizedSelector<State, Result, typeof projector>;\n\nexport function createSelector<State, Slices extends unknown[], Result>(\n selectors: Selector<State, unknown>[] &\n [...{ [i in keyof Slices]: Selector<State, Slices[i]> }],\n projector: (...s: Slices) => Result\n): MemoizedSelector<State, Result, (...s: Slices) => Result>;\n\nexport function createSelector(\n ...input: any[]\n): MemoizedSelector<any, any> | MemoizedSelectorWithProps<any, any, any> {\n return createSelectorFactory(defaultMemoize)(...input);\n}\n\nexport function defaultStateFn(\n state: any,\n selectors: Selector<any, any>[] | SelectorWithProps<any, any, any>[],\n props: any,\n memoizedProjector: MemoizedProjection,\n): any {\n if (props === undefined) {\n const args = (<Selector<any, any>[]>selectors).map((fn) => fn(state));\n return memoizedProjector.memoized.apply(null, args);\n }\n\n const args = (<SelectorWithProps<any, any, any>[]>selectors).map((fn) =>\n fn(state, props),\n );\n return memoizedProjector.memoized.apply(null, [...args, props]);\n}\n\nexport type SelectorFactoryConfig<T = any, V = any> = {\n stateFn: (\n state: T,\n selectors: Selector<any, any>[],\n props: any,\n memoizedProjector: MemoizedProjection\n ) => V;\n};\n\nexport function createSelectorFactory<T = any, V = any>(\n memoize: MemoizeFn\n): (...input: any[]) => MemoizedSelector<T, V>;\n\n/**\n *\n * @param memoize The function used to memoize selectors\n * @param options Config Object that may include a `stateFn` function defining how to return the selector's value, given the entire `Store`'s state, parent `Selector`s, `Props`, and a `MemoizedProjection`\n *\n * @usageNotes\n *\n * **Creating a Selector Factory Where Array Order Does Not Matter**\n *\n * ```ts\n * function removeMatch(arr: string[], target: string): string[] {\n * const matchIndex = arr.indexOf(target);\n * return [...arr.slice(0, matchIndex), ...arr.slice(matchIndex + 1)];\n * }\n *\n * function orderDoesNotMatterComparer(a: any, b: any): boolean {\n * if (!Array.isArray(a) || !Array.isArray(b)) {\n * return a === b;\n * }\n * if (a.length !== b.length) {\n * return false;\n * }\n * let tempB = [...b];\n * function reduceToDetermineIfArraysContainSameContents(\n * previousCallResult: boolean,\n * arrayMember: any\n * ): boolean {\n * if (previousCallResult === false) {\n * return false;\n * }\n * if (tempB.includes(arrayMember)) {\n * tempB = removeMatch(tempB, arrayMember);\n * return true;\n * }\n * return false;\n * }\n * return a.reduce(reduceToDetermineIfArraysContainSameContents, true);\n * }\n *\n * export const createOrderDoesNotMatterSelector = createSelectorFactory(\n * (projectionFun) => defaultMemoize(\n * projectionFun,\n * orderDoesNotMatterComparer,\n * orderDoesNotMatterComparer\n * )\n * );\n * ```\n *\n * **Creating an Alternative Memoization Strategy**\n *\n * ```ts\n * function serialize(x: any): string {\n * return JSON.stringify(x);\n * }\n *\n * export const createFullHistorySelector = createSelectorFactory(\n * (projectionFunction) => {\n * const cache = {};\n *\n * function memoized() {\n * const serializedArguments = serialize(...arguments);\n * if (cache[serializedArguments] != null) {\n * cache[serializedArguments] = projectionFunction.apply(null, arguments);\n * }\n * return cache[serializedArguments];\n * }\n * return {\n * memoized,\n * reset: () => {},\n * setResult: () => {},\n * clearResult: () => {},\n * };\n * }\n * );\n * ```\n */\nexport function createSelectorFactory(\n memoize: MemoizeFn,\n options: SelectorFactoryConfig<any, any> = {\n stateFn: defaultStateFn,\n },\n) {\n return function (\n ...input: any[]\n ): MemoizedSelector<any, any> | MemoizedSelectorWithProps<any, any, any> {\n let args = input;\n if (Array.isArray(args[0])) {\n const [head, ...tail] = args;\n args = [...head, ...tail];\n } else if (args.length === 1 && isSelectorsDictionary(args[0])) {\n args = extractArgsFromSelectorsDictionary(args[0]);\n }\n\n const selectors = args.slice(0, args.length - 1);\n const projector = args[args.length - 1];\n const memoizedSelectors = selectors.filter(\n (selector: any) =>\n selector.release && typeof selector.release === 'function',\n );\n\n const memoizedProjector = memoize(function (...selectors: any[]) {\n return projector.apply(null, selectors);\n });\n\n const memoizedState = defaultMemoize(function (state: any, props: any) {\n return options.stateFn.apply(null, [\n state,\n selectors,\n props,\n memoizedProjector,\n ]);\n });\n\n function release() {\n memoizedState.reset();\n memoizedProjector.reset();\n\n memoizedSelectors.forEach((selector) => selector.release());\n }\n\n return Object.assign(memoizedState.memoized, {\n release,\n projector: memoizedProjector.memoized,\n setResult: memoizedState.setResult,\n clearResult: memoizedState.clearResult,\n });\n };\n}\n\nfunction isSelectorsDictionary(\n selectors: unknown,\n): selectors is Record<string, Selector<unknown, unknown>> {\n return (\n !!selectors &&\n typeof selectors === 'object' &&\n Object.values(selectors).every((selector) => typeof selector === 'function')\n );\n}\n\nfunction extractArgsFromSelectorsDictionary(\n selectorsDictionary: Record<string, Selector<unknown, unknown>>,\n): [\n ...selectors: Selector<unknown, unknown>[],\n projector: (...selectorResults: unknown[]) => unknown\n] {\n const selectors = Object.values(selectorsDictionary);\n const resultKeys = Object.keys(selectorsDictionary);\n const projector = (...selectorResults: unknown[]) =>\n resultKeys.reduce(\n (result, key, index) => ({\n ...result,\n [key]: selectorResults[index],\n }),\n {},\n );\n\n return [...selectors, projector];\n}\n",
|
|
2257
|
+
"sourceCode": "export type ActionReducer<T, V extends Action = Action> = (state: T | undefined, action: V) => T;\n\nexport type ActionReducerMap<T, V extends Action = Action> = {\n [p in keyof T]: ActionReducer<T[p], V>;\n};\nexport interface Action<Type extends string = string> {\n type: Type;\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/explicit-function-return-type */\nexport type Selector<T, V> = (state: T) => V;\nexport type SelectorWithProps<State, Props, Result> = (\n state: State,\n props: Props\n) => Result;\n\nexport type AnyFn = (...args: any[]) => any;\n\nexport type MemoizedProjection = {\n memoized: AnyFn;\n reset: () => void;\n setResult: (result?: any) => void;\n clearResult: () => void;\n};\n\nexport type MemoizeFn = (t: AnyFn) => MemoizedProjection;\n\nexport type ComparatorFn = (a: any, b: any) => boolean;\n\nexport type DefaultProjectorFn<T> = (...args: any[]) => T;\n\nexport interface MemoizedSelector<\n State,\n Result,\n ProjectorFn = DefaultProjectorFn<Result>\n> extends Selector<State, Result> {\n release(): void;\n projector: ProjectorFn;\n setResult: (result?: Result) => void;\n clearResult: () => void;\n}\n\n/**\n * @deprecated Selectors with props are deprecated, for more info see the {@link https://ngrx.io/guide/migration/v12#ngrxstore migration guide}\n */\nexport interface MemoizedSelectorWithProps<\n State,\n Props,\n Result,\n ProjectorFn = DefaultProjectorFn<Result>\n> extends SelectorWithProps<State, Props, Result> {\n release(): void;\n projector: ProjectorFn;\n setResult: (result?: Result) => void;\n clearResult: () => void;\n}\n\nexport function isEqualCheck(a: any, b: any): boolean {\n return a === b;\n}\n\nfunction isArgumentsChanged(\n args: IArguments,\n lastArguments: IArguments,\n comparator: ComparatorFn,\n) {\n for (let i = 0; i < args.length; i++) {\n if (!comparator(args[i], lastArguments[i])) {\n return true;\n }\n }\n return false;\n}\n\nexport function defaultMemoize(\n projectionFn: AnyFn,\n isArgumentsEqual = isEqualCheck,\n isResultEqual = isEqualCheck,\n): MemoizedProjection {\n let lastArguments: null | IArguments = null;\n \n let lastResult: any = null;\n let overrideResult: any;\n\n const reset = () => {\n lastArguments = null;\n lastResult = null;\n };\n\n const setResult = (result: any = undefined) => {\n overrideResult = { result };\n };\n\n const clearResult = () => {\n overrideResult = undefined;\n };\n\n /* eslint-disable prefer-rest-params, prefer-spread */\n\n // disabled because of the use of `arguments`\n // eslint-disable-next-line prefer-arrow/prefer-arrow-functions\n function memoized(): any {\n if (overrideResult !== undefined) {\n return overrideResult.result;\n }\n\n if (!lastArguments) {\n lastResult = projectionFn.apply(null, arguments as any);\n lastArguments = arguments;\n return lastResult;\n }\n\n if (!isArgumentsChanged(arguments, lastArguments, isArgumentsEqual)) {\n return lastResult;\n }\n\n const newResult = projectionFn.apply(null, arguments as any);\n lastArguments = arguments;\n\n if (isResultEqual(lastResult, newResult)) {\n return lastResult;\n }\n\n lastResult = newResult;\n\n return newResult;\n }\n\n return { memoized, reset, setResult, clearResult };\n}\n\nexport function createSelector<State, S1, Result>(\n s1: Selector<State, S1>,\n projector: (s1: S1) => Result\n): MemoizedSelector<State, Result, typeof projector>;\n\nexport function createSelector<State, Slices extends unknown[], Result>(\n selectors: Selector<State, unknown>[] &\n [...{ [i in keyof Slices]: Selector<State, Slices[i]> }],\n projector: (...s: Slices) => Result\n): MemoizedSelector<State, Result, (...s: Slices) => Result>;\n\nexport function createSelector(\n ...input: any[]\n): MemoizedSelector<any, any> | MemoizedSelectorWithProps<any, any, any> {\n return createSelectorFactory(defaultMemoize)(...input);\n}\n\nexport function defaultStateFn(\n state: any,\n selectors: Selector<any, any>[] | SelectorWithProps<any, any, any>[],\n props: any,\n memoizedProjector: MemoizedProjection,\n): any {\n if (props === undefined) {\n const args = (selectors as Selector<any, any>[]).map((fn) => fn(state));\n return memoizedProjector.memoized.apply(null, args);\n }\n\n const args = (selectors as SelectorWithProps<any, any, any>[]).map((fn) =>\n fn(state, props),\n );\n return memoizedProjector.memoized.apply(null, [...args, props]);\n}\n\nexport type SelectorFactoryConfig<T = any, V = any> = {\n stateFn: (\n state: T,\n selectors: Selector<any, any>[],\n props: any,\n memoizedProjector: MemoizedProjection\n ) => V;\n};\n\nexport function createSelectorFactory<T = any, V = any>(\n memoize: MemoizeFn\n): (...input: any[]) => MemoizedSelector<T, V>;\n\n/**\n *\n * @param memoize The function used to memoize selectors\n * @param options Config Object that may include a `stateFn` function defining how to return the selector's value, given the entire `Store`'s state, parent `Selector`s, `Props`, and a `MemoizedProjection`\n *\n * @usageNotes\n *\n * **Creating a Selector Factory Where Array Order Does Not Matter**\n *\n * ```ts\n * function removeMatch(arr: string[], target: string): string[] {\n * const matchIndex = arr.indexOf(target);\n * return [...arr.slice(0, matchIndex), ...arr.slice(matchIndex + 1)];\n * }\n *\n * function orderDoesNotMatterComparer(a: any, b: any): boolean {\n * if (!Array.isArray(a) || !Array.isArray(b)) {\n * return a === b;\n * }\n * if (a.length !== b.length) {\n * return false;\n * }\n * let tempB = [...b];\n * function reduceToDetermineIfArraysContainSameContents(\n * previousCallResult: boolean,\n * arrayMember: any\n * ): boolean {\n * if (previousCallResult === false) {\n * return false;\n * }\n * if (tempB.includes(arrayMember)) {\n * tempB = removeMatch(tempB, arrayMember);\n * return true;\n * }\n * return false;\n * }\n * return a.reduce(reduceToDetermineIfArraysContainSameContents, true);\n * }\n *\n * export const createOrderDoesNotMatterSelector = createSelectorFactory(\n * (projectionFun) => defaultMemoize(\n * projectionFun,\n * orderDoesNotMatterComparer,\n * orderDoesNotMatterComparer\n * )\n * );\n * ```\n *\n * **Creating an Alternative Memoization Strategy**\n *\n * ```ts\n * function serialize(x: any): string {\n * return JSON.stringify(x);\n * }\n *\n * export const createFullHistorySelector = createSelectorFactory(\n * (projectionFunction) => {\n * const cache = {};\n *\n * function memoized() {\n * const serializedArguments = serialize(...arguments);\n * if (cache[serializedArguments] != null) {\n * cache[serializedArguments] = projectionFunction.apply(null, arguments);\n * }\n * return cache[serializedArguments];\n * }\n * return {\n * memoized,\n * reset: () => {},\n * setResult: () => {},\n * clearResult: () => {},\n * };\n * }\n * );\n * ```\n */\nexport function createSelectorFactory(\n memoize: MemoizeFn,\n options: SelectorFactoryConfig<any, any> = {\n stateFn: defaultStateFn,\n },\n) {\n return (...input: any[]): MemoizedSelector<any, any> | MemoizedSelectorWithProps<any, any, any> => {\n let args = input;\n if (Array.isArray(args[0])) {\n const [head, ...tail] = args;\n args = [...head, ...tail];\n } else if (args.length === 1 && isSelectorsDictionary(args[0])) {\n args = extractArgsFromSelectorsDictionary(args[0]);\n }\n\n const selectors = args.slice(0, args.length - 1);\n const projector = args[args.length - 1];\n const memoizedSelectors = selectors.filter(\n (selector: any) =>\n selector.release && typeof selector.release === 'function',\n );\n\n const memoizedProjector = memoize((...selectors: any[]) => projector.apply(null, selectors));\n\n const memoizedState = defaultMemoize((state: any, props: any) => options.stateFn.apply(null, [\n state,\n selectors,\n props,\n memoizedProjector,\n ]));\n\n const release = () => {\n memoizedState.reset();\n memoizedProjector.reset();\n\n memoizedSelectors.forEach((selector) => selector.release());\n }\n\n return Object.assign(memoizedState.memoized, {\n release,\n projector: memoizedProjector.memoized,\n setResult: memoizedState.setResult,\n clearResult: memoizedState.clearResult,\n });\n };\n}\n\nfunction isSelectorsDictionary(\n selectors: unknown,\n): selectors is Record<string, Selector<unknown, unknown>> {\n return (\n !!selectors &&\n typeof selectors === 'object' &&\n Object.values(selectors).every((selector) => typeof selector === 'function')\n );\n}\n\nfunction extractArgsFromSelectorsDictionary(\n selectorsDictionary: Record<string, Selector<unknown, unknown>>,\n): [\n ...selectors: Selector<unknown, unknown>[],\n projector: (...selectorResults: unknown[]) => unknown\n] {\n const selectors = Object.values(selectorsDictionary);\n const resultKeys = Object.keys(selectorsDictionary);\n const projector = (...selectorResults: unknown[]) =>\n resultKeys.reduce(\n (result, key, index) => ({\n ...result,\n [key]: selectorResults[index],\n }),\n {},\n );\n\n return [...selectors, projector];\n}\n",
|
|
2311
2258
|
"displayName": "MemoizedSelector<State, Result, ProjectorFn = DefaultProjectorFn<Result>>",
|
|
2312
2259
|
"typeParameters": [
|
|
2313
2260
|
"State",
|
|
@@ -2324,7 +2271,7 @@
|
|
|
2324
2271
|
"indexKey": "",
|
|
2325
2272
|
"optional": false,
|
|
2326
2273
|
"description": "",
|
|
2327
|
-
"line":
|
|
2274
|
+
"line": 45,
|
|
2328
2275
|
"rawdescription": "\n"
|
|
2329
2276
|
},
|
|
2330
2277
|
{
|
|
@@ -2336,7 +2283,7 @@
|
|
|
2336
2283
|
"indexKey": "",
|
|
2337
2284
|
"optional": false,
|
|
2338
2285
|
"description": "",
|
|
2339
|
-
"line":
|
|
2286
|
+
"line": 43,
|
|
2340
2287
|
"rawdescription": "\n"
|
|
2341
2288
|
},
|
|
2342
2289
|
{
|
|
@@ -2348,7 +2295,7 @@
|
|
|
2348
2295
|
"indexKey": "",
|
|
2349
2296
|
"optional": false,
|
|
2350
2297
|
"description": "",
|
|
2351
|
-
"line":
|
|
2298
|
+
"line": 44,
|
|
2352
2299
|
"rawdescription": "\n"
|
|
2353
2300
|
}
|
|
2354
2301
|
],
|
|
@@ -2362,7 +2309,7 @@
|
|
|
2362
2309
|
"optional": false,
|
|
2363
2310
|
"returnType": "void",
|
|
2364
2311
|
"typeParameters": [],
|
|
2365
|
-
"line":
|
|
2312
|
+
"line": 42,
|
|
2366
2313
|
"deprecated": false,
|
|
2367
2314
|
"deprecationMessage": "",
|
|
2368
2315
|
"rawdescription": "\n",
|
|
@@ -2384,12 +2331,12 @@
|
|
|
2384
2331
|
},
|
|
2385
2332
|
{
|
|
2386
2333
|
"name": "MemoizedSelectorWithProps",
|
|
2387
|
-
"id": "interface-MemoizedSelectorWithProps-
|
|
2334
|
+
"id": "interface-MemoizedSelectorWithProps-0a0526fdcac47c7960ef767570c109d5ebaf26773cbeda85cd6f1497609565a9547497d50a2a81aa71bde65e5fce2184cadf078a8ab08d7476d1e8edafa2ce51",
|
|
2388
2335
|
"file": "packages/core/src/lib/services/store/ngrx_kit.ts",
|
|
2389
2336
|
"deprecated": true,
|
|
2390
2337
|
"deprecationMessage": "Selectors with props are deprecated, for more info see the ://ngrx.io/guide/migration/v12#ngrxstore migration guide{@link https}",
|
|
2391
2338
|
"type": "interface",
|
|
2392
|
-
"sourceCode": "export interface ActionReducer<T, V extends Action = Action> {\n (state: T | undefined, action: V): T;\n}\n\nexport type ActionReducerMap<T, V extends Action = Action> = {\n [p in keyof T]: ActionReducer<T[p], V>;\n};\nexport interface Action<Type extends string = string> {\n type: Type;\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/explicit-function-return-type */\nexport type Selector<T, V> = (state: T) => V;\nexport type SelectorWithProps<State, Props, Result> = (\n state: State,\n props: Props\n) => Result;\n\nexport type AnyFn = (...args: any[]) => any;\n\nexport type MemoizedProjection = {\n memoized: AnyFn;\n reset: () => void;\n setResult: (result?: any) => void;\n clearResult: () => void;\n};\n\nexport type MemoizeFn = (t: AnyFn) => MemoizedProjection;\n\nexport type ComparatorFn = (a: any, b: any) => boolean;\n\nexport type DefaultProjectorFn<T> = (...args: any[]) => T;\n\nexport interface MemoizedSelector<\n State,\n Result,\n ProjectorFn = DefaultProjectorFn<Result>\n> extends Selector<State, Result> {\n release(): void;\n projector: ProjectorFn;\n setResult: (result?: Result) => void;\n clearResult: () => void;\n}\n\n/**\n * @deprecated Selectors with props are deprecated, for more info see the {@link https://ngrx.io/guide/migration/v12#ngrxstore migration guide}\n */\nexport interface MemoizedSelectorWithProps<\n State,\n Props,\n Result,\n ProjectorFn = DefaultProjectorFn<Result>\n> extends SelectorWithProps<State, Props, Result> {\n release(): void;\n projector: ProjectorFn;\n setResult: (result?: Result) => void;\n clearResult: () => void;\n}\n\nexport function isEqualCheck(a: any, b: any): boolean {\n return a === b;\n}\n\nfunction isArgumentsChanged(\n args: IArguments,\n lastArguments: IArguments,\n comparator: ComparatorFn,\n) {\n for (let i = 0; i < args.length; i++) {\n if (!comparator(args[i], lastArguments[i])) {\n return true;\n }\n }\n return false;\n}\n\nexport function defaultMemoize(\n projectionFn: AnyFn,\n isArgumentsEqual = isEqualCheck,\n isResultEqual = isEqualCheck,\n): MemoizedProjection {\n let lastArguments: null | IArguments = null;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, , , , ,\n let lastResult: any = null;\n let overrideResult: any;\n\n function reset() {\n lastArguments = null;\n lastResult = null;\n }\n\n function setResult(result: any = undefined) {\n overrideResult = { result };\n }\n\n function clearResult() {\n overrideResult = undefined;\n }\n\n /* eslint-disable prefer-rest-params, prefer-spread */\n\n // disabled because of the use of `arguments`\n function memoized(): any {\n if (overrideResult !== undefined) {\n return overrideResult.result;\n }\n\n if (!lastArguments) {\n lastResult = projectionFn.apply(null, arguments as any);\n lastArguments = arguments;\n return lastResult;\n }\n\n if (!isArgumentsChanged(arguments, lastArguments, isArgumentsEqual)) {\n return lastResult;\n }\n\n const newResult = projectionFn.apply(null, arguments as any);\n lastArguments = arguments;\n\n if (isResultEqual(lastResult, newResult)) {\n return lastResult;\n }\n\n lastResult = newResult;\n\n return newResult;\n }\n\n return { memoized, reset, setResult, clearResult };\n}\n\nexport function createSelector<State, S1, Result>(\n s1: Selector<State, S1>,\n projector: (s1: S1) => Result\n): MemoizedSelector<State, Result, typeof projector>;\n\nexport function createSelector<State, Slices extends unknown[], Result>(\n selectors: Selector<State, unknown>[] &\n [...{ [i in keyof Slices]: Selector<State, Slices[i]> }],\n projector: (...s: Slices) => Result\n): MemoizedSelector<State, Result, (...s: Slices) => Result>;\n\nexport function createSelector(\n ...input: any[]\n): MemoizedSelector<any, any> | MemoizedSelectorWithProps<any, any, any> {\n return createSelectorFactory(defaultMemoize)(...input);\n}\n\nexport function defaultStateFn(\n state: any,\n selectors: Selector<any, any>[] | SelectorWithProps<any, any, any>[],\n props: any,\n memoizedProjector: MemoizedProjection,\n): any {\n if (props === undefined) {\n const args = (<Selector<any, any>[]>selectors).map((fn) => fn(state));\n return memoizedProjector.memoized.apply(null, args);\n }\n\n const args = (<SelectorWithProps<any, any, any>[]>selectors).map((fn) =>\n fn(state, props),\n );\n return memoizedProjector.memoized.apply(null, [...args, props]);\n}\n\nexport type SelectorFactoryConfig<T = any, V = any> = {\n stateFn: (\n state: T,\n selectors: Selector<any, any>[],\n props: any,\n memoizedProjector: MemoizedProjection\n ) => V;\n};\n\nexport function createSelectorFactory<T = any, V = any>(\n memoize: MemoizeFn\n): (...input: any[]) => MemoizedSelector<T, V>;\n\n/**\n *\n * @param memoize The function used to memoize selectors\n * @param options Config Object that may include a `stateFn` function defining how to return the selector's value, given the entire `Store`'s state, parent `Selector`s, `Props`, and a `MemoizedProjection`\n *\n * @usageNotes\n *\n * **Creating a Selector Factory Where Array Order Does Not Matter**\n *\n * ```ts\n * function removeMatch(arr: string[], target: string): string[] {\n * const matchIndex = arr.indexOf(target);\n * return [...arr.slice(0, matchIndex), ...arr.slice(matchIndex + 1)];\n * }\n *\n * function orderDoesNotMatterComparer(a: any, b: any): boolean {\n * if (!Array.isArray(a) || !Array.isArray(b)) {\n * return a === b;\n * }\n * if (a.length !== b.length) {\n * return false;\n * }\n * let tempB = [...b];\n * function reduceToDetermineIfArraysContainSameContents(\n * previousCallResult: boolean,\n * arrayMember: any\n * ): boolean {\n * if (previousCallResult === false) {\n * return false;\n * }\n * if (tempB.includes(arrayMember)) {\n * tempB = removeMatch(tempB, arrayMember);\n * return true;\n * }\n * return false;\n * }\n * return a.reduce(reduceToDetermineIfArraysContainSameContents, true);\n * }\n *\n * export const createOrderDoesNotMatterSelector = createSelectorFactory(\n * (projectionFun) => defaultMemoize(\n * projectionFun,\n * orderDoesNotMatterComparer,\n * orderDoesNotMatterComparer\n * )\n * );\n * ```\n *\n * **Creating an Alternative Memoization Strategy**\n *\n * ```ts\n * function serialize(x: any): string {\n * return JSON.stringify(x);\n * }\n *\n * export const createFullHistorySelector = createSelectorFactory(\n * (projectionFunction) => {\n * const cache = {};\n *\n * function memoized() {\n * const serializedArguments = serialize(...arguments);\n * if (cache[serializedArguments] != null) {\n * cache[serializedArguments] = projectionFunction.apply(null, arguments);\n * }\n * return cache[serializedArguments];\n * }\n * return {\n * memoized,\n * reset: () => {},\n * setResult: () => {},\n * clearResult: () => {},\n * };\n * }\n * );\n * ```\n */\nexport function createSelectorFactory(\n memoize: MemoizeFn,\n options: SelectorFactoryConfig<any, any> = {\n stateFn: defaultStateFn,\n },\n) {\n return function (\n ...input: any[]\n ): MemoizedSelector<any, any> | MemoizedSelectorWithProps<any, any, any> {\n let args = input;\n if (Array.isArray(args[0])) {\n const [head, ...tail] = args;\n args = [...head, ...tail];\n } else if (args.length === 1 && isSelectorsDictionary(args[0])) {\n args = extractArgsFromSelectorsDictionary(args[0]);\n }\n\n const selectors = args.slice(0, args.length - 1);\n const projector = args[args.length - 1];\n const memoizedSelectors = selectors.filter(\n (selector: any) =>\n selector.release && typeof selector.release === 'function',\n );\n\n const memoizedProjector = memoize(function (...selectors: any[]) {\n return projector.apply(null, selectors);\n });\n\n const memoizedState = defaultMemoize(function (state: any, props: any) {\n return options.stateFn.apply(null, [\n state,\n selectors,\n props,\n memoizedProjector,\n ]);\n });\n\n function release() {\n memoizedState.reset();\n memoizedProjector.reset();\n\n memoizedSelectors.forEach((selector) => selector.release());\n }\n\n return Object.assign(memoizedState.memoized, {\n release,\n projector: memoizedProjector.memoized,\n setResult: memoizedState.setResult,\n clearResult: memoizedState.clearResult,\n });\n };\n}\n\nfunction isSelectorsDictionary(\n selectors: unknown,\n): selectors is Record<string, Selector<unknown, unknown>> {\n return (\n !!selectors &&\n typeof selectors === 'object' &&\n Object.values(selectors).every((selector) => typeof selector === 'function')\n );\n}\n\nfunction extractArgsFromSelectorsDictionary(\n selectorsDictionary: Record<string, Selector<unknown, unknown>>,\n): [\n ...selectors: Selector<unknown, unknown>[],\n projector: (...selectorResults: unknown[]) => unknown\n] {\n const selectors = Object.values(selectorsDictionary);\n const resultKeys = Object.keys(selectorsDictionary);\n const projector = (...selectorResults: unknown[]) =>\n resultKeys.reduce(\n (result, key, index) => ({\n ...result,\n [key]: selectorResults[index],\n }),\n {},\n );\n\n return [...selectors, projector];\n}\n",
|
|
2339
|
+
"sourceCode": "export type ActionReducer<T, V extends Action = Action> = (state: T | undefined, action: V) => T;\n\nexport type ActionReducerMap<T, V extends Action = Action> = {\n [p in keyof T]: ActionReducer<T[p], V>;\n};\nexport interface Action<Type extends string = string> {\n type: Type;\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/explicit-function-return-type */\nexport type Selector<T, V> = (state: T) => V;\nexport type SelectorWithProps<State, Props, Result> = (\n state: State,\n props: Props\n) => Result;\n\nexport type AnyFn = (...args: any[]) => any;\n\nexport type MemoizedProjection = {\n memoized: AnyFn;\n reset: () => void;\n setResult: (result?: any) => void;\n clearResult: () => void;\n};\n\nexport type MemoizeFn = (t: AnyFn) => MemoizedProjection;\n\nexport type ComparatorFn = (a: any, b: any) => boolean;\n\nexport type DefaultProjectorFn<T> = (...args: any[]) => T;\n\nexport interface MemoizedSelector<\n State,\n Result,\n ProjectorFn = DefaultProjectorFn<Result>\n> extends Selector<State, Result> {\n release(): void;\n projector: ProjectorFn;\n setResult: (result?: Result) => void;\n clearResult: () => void;\n}\n\n/**\n * @deprecated Selectors with props are deprecated, for more info see the {@link https://ngrx.io/guide/migration/v12#ngrxstore migration guide}\n */\nexport interface MemoizedSelectorWithProps<\n State,\n Props,\n Result,\n ProjectorFn = DefaultProjectorFn<Result>\n> extends SelectorWithProps<State, Props, Result> {\n release(): void;\n projector: ProjectorFn;\n setResult: (result?: Result) => void;\n clearResult: () => void;\n}\n\nexport function isEqualCheck(a: any, b: any): boolean {\n return a === b;\n}\n\nfunction isArgumentsChanged(\n args: IArguments,\n lastArguments: IArguments,\n comparator: ComparatorFn,\n) {\n for (let i = 0; i < args.length; i++) {\n if (!comparator(args[i], lastArguments[i])) {\n return true;\n }\n }\n return false;\n}\n\nexport function defaultMemoize(\n projectionFn: AnyFn,\n isArgumentsEqual = isEqualCheck,\n isResultEqual = isEqualCheck,\n): MemoizedProjection {\n let lastArguments: null | IArguments = null;\n \n let lastResult: any = null;\n let overrideResult: any;\n\n const reset = () => {\n lastArguments = null;\n lastResult = null;\n };\n\n const setResult = (result: any = undefined) => {\n overrideResult = { result };\n };\n\n const clearResult = () => {\n overrideResult = undefined;\n };\n\n /* eslint-disable prefer-rest-params, prefer-spread */\n\n // disabled because of the use of `arguments`\n // eslint-disable-next-line prefer-arrow/prefer-arrow-functions\n function memoized(): any {\n if (overrideResult !== undefined) {\n return overrideResult.result;\n }\n\n if (!lastArguments) {\n lastResult = projectionFn.apply(null, arguments as any);\n lastArguments = arguments;\n return lastResult;\n }\n\n if (!isArgumentsChanged(arguments, lastArguments, isArgumentsEqual)) {\n return lastResult;\n }\n\n const newResult = projectionFn.apply(null, arguments as any);\n lastArguments = arguments;\n\n if (isResultEqual(lastResult, newResult)) {\n return lastResult;\n }\n\n lastResult = newResult;\n\n return newResult;\n }\n\n return { memoized, reset, setResult, clearResult };\n}\n\nexport function createSelector<State, S1, Result>(\n s1: Selector<State, S1>,\n projector: (s1: S1) => Result\n): MemoizedSelector<State, Result, typeof projector>;\n\nexport function createSelector<State, Slices extends unknown[], Result>(\n selectors: Selector<State, unknown>[] &\n [...{ [i in keyof Slices]: Selector<State, Slices[i]> }],\n projector: (...s: Slices) => Result\n): MemoizedSelector<State, Result, (...s: Slices) => Result>;\n\nexport function createSelector(\n ...input: any[]\n): MemoizedSelector<any, any> | MemoizedSelectorWithProps<any, any, any> {\n return createSelectorFactory(defaultMemoize)(...input);\n}\n\nexport function defaultStateFn(\n state: any,\n selectors: Selector<any, any>[] | SelectorWithProps<any, any, any>[],\n props: any,\n memoizedProjector: MemoizedProjection,\n): any {\n if (props === undefined) {\n const args = (selectors as Selector<any, any>[]).map((fn) => fn(state));\n return memoizedProjector.memoized.apply(null, args);\n }\n\n const args = (selectors as SelectorWithProps<any, any, any>[]).map((fn) =>\n fn(state, props),\n );\n return memoizedProjector.memoized.apply(null, [...args, props]);\n}\n\nexport type SelectorFactoryConfig<T = any, V = any> = {\n stateFn: (\n state: T,\n selectors: Selector<any, any>[],\n props: any,\n memoizedProjector: MemoizedProjection\n ) => V;\n};\n\nexport function createSelectorFactory<T = any, V = any>(\n memoize: MemoizeFn\n): (...input: any[]) => MemoizedSelector<T, V>;\n\n/**\n *\n * @param memoize The function used to memoize selectors\n * @param options Config Object that may include a `stateFn` function defining how to return the selector's value, given the entire `Store`'s state, parent `Selector`s, `Props`, and a `MemoizedProjection`\n *\n * @usageNotes\n *\n * **Creating a Selector Factory Where Array Order Does Not Matter**\n *\n * ```ts\n * function removeMatch(arr: string[], target: string): string[] {\n * const matchIndex = arr.indexOf(target);\n * return [...arr.slice(0, matchIndex), ...arr.slice(matchIndex + 1)];\n * }\n *\n * function orderDoesNotMatterComparer(a: any, b: any): boolean {\n * if (!Array.isArray(a) || !Array.isArray(b)) {\n * return a === b;\n * }\n * if (a.length !== b.length) {\n * return false;\n * }\n * let tempB = [...b];\n * function reduceToDetermineIfArraysContainSameContents(\n * previousCallResult: boolean,\n * arrayMember: any\n * ): boolean {\n * if (previousCallResult === false) {\n * return false;\n * }\n * if (tempB.includes(arrayMember)) {\n * tempB = removeMatch(tempB, arrayMember);\n * return true;\n * }\n * return false;\n * }\n * return a.reduce(reduceToDetermineIfArraysContainSameContents, true);\n * }\n *\n * export const createOrderDoesNotMatterSelector = createSelectorFactory(\n * (projectionFun) => defaultMemoize(\n * projectionFun,\n * orderDoesNotMatterComparer,\n * orderDoesNotMatterComparer\n * )\n * );\n * ```\n *\n * **Creating an Alternative Memoization Strategy**\n *\n * ```ts\n * function serialize(x: any): string {\n * return JSON.stringify(x);\n * }\n *\n * export const createFullHistorySelector = createSelectorFactory(\n * (projectionFunction) => {\n * const cache = {};\n *\n * function memoized() {\n * const serializedArguments = serialize(...arguments);\n * if (cache[serializedArguments] != null) {\n * cache[serializedArguments] = projectionFunction.apply(null, arguments);\n * }\n * return cache[serializedArguments];\n * }\n * return {\n * memoized,\n * reset: () => {},\n * setResult: () => {},\n * clearResult: () => {},\n * };\n * }\n * );\n * ```\n */\nexport function createSelectorFactory(\n memoize: MemoizeFn,\n options: SelectorFactoryConfig<any, any> = {\n stateFn: defaultStateFn,\n },\n) {\n return (...input: any[]): MemoizedSelector<any, any> | MemoizedSelectorWithProps<any, any, any> => {\n let args = input;\n if (Array.isArray(args[0])) {\n const [head, ...tail] = args;\n args = [...head, ...tail];\n } else if (args.length === 1 && isSelectorsDictionary(args[0])) {\n args = extractArgsFromSelectorsDictionary(args[0]);\n }\n\n const selectors = args.slice(0, args.length - 1);\n const projector = args[args.length - 1];\n const memoizedSelectors = selectors.filter(\n (selector: any) =>\n selector.release && typeof selector.release === 'function',\n );\n\n const memoizedProjector = memoize((...selectors: any[]) => projector.apply(null, selectors));\n\n const memoizedState = defaultMemoize((state: any, props: any) => options.stateFn.apply(null, [\n state,\n selectors,\n props,\n memoizedProjector,\n ]));\n\n const release = () => {\n memoizedState.reset();\n memoizedProjector.reset();\n\n memoizedSelectors.forEach((selector) => selector.release());\n }\n\n return Object.assign(memoizedState.memoized, {\n release,\n projector: memoizedProjector.memoized,\n setResult: memoizedState.setResult,\n clearResult: memoizedState.clearResult,\n });\n };\n}\n\nfunction isSelectorsDictionary(\n selectors: unknown,\n): selectors is Record<string, Selector<unknown, unknown>> {\n return (\n !!selectors &&\n typeof selectors === 'object' &&\n Object.values(selectors).every((selector) => typeof selector === 'function')\n );\n}\n\nfunction extractArgsFromSelectorsDictionary(\n selectorsDictionary: Record<string, Selector<unknown, unknown>>,\n): [\n ...selectors: Selector<unknown, unknown>[],\n projector: (...selectorResults: unknown[]) => unknown\n] {\n const selectors = Object.values(selectorsDictionary);\n const resultKeys = Object.keys(selectorsDictionary);\n const projector = (...selectorResults: unknown[]) =>\n resultKeys.reduce(\n (result, key, index) => ({\n ...result,\n [key]: selectorResults[index],\n }),\n {},\n );\n\n return [...selectors, projector];\n}\n",
|
|
2393
2340
|
"displayName": "MemoizedSelectorWithProps<State, Props, Result, ProjectorFn = DefaultProjectorFn<Result>>",
|
|
2394
2341
|
"typeParameters": [
|
|
2395
2342
|
"State",
|
|
@@ -2407,7 +2354,7 @@
|
|
|
2407
2354
|
"indexKey": "",
|
|
2408
2355
|
"optional": false,
|
|
2409
2356
|
"description": "",
|
|
2410
|
-
"line":
|
|
2357
|
+
"line": 60,
|
|
2411
2358
|
"rawdescription": "\n"
|
|
2412
2359
|
},
|
|
2413
2360
|
{
|
|
@@ -2419,7 +2366,7 @@
|
|
|
2419
2366
|
"indexKey": "",
|
|
2420
2367
|
"optional": false,
|
|
2421
2368
|
"description": "",
|
|
2422
|
-
"line":
|
|
2369
|
+
"line": 58,
|
|
2423
2370
|
"rawdescription": "\n"
|
|
2424
2371
|
},
|
|
2425
2372
|
{
|
|
@@ -2431,7 +2378,7 @@
|
|
|
2431
2378
|
"indexKey": "",
|
|
2432
2379
|
"optional": false,
|
|
2433
2380
|
"description": "",
|
|
2434
|
-
"line":
|
|
2381
|
+
"line": 59,
|
|
2435
2382
|
"rawdescription": "\n"
|
|
2436
2383
|
}
|
|
2437
2384
|
],
|
|
@@ -2445,7 +2392,7 @@
|
|
|
2445
2392
|
"optional": false,
|
|
2446
2393
|
"returnType": "void",
|
|
2447
2394
|
"typeParameters": [],
|
|
2448
|
-
"line":
|
|
2395
|
+
"line": 57,
|
|
2449
2396
|
"deprecated": false,
|
|
2450
2397
|
"deprecationMessage": "",
|
|
2451
2398
|
"rawdescription": "\n",
|
|
@@ -2691,12 +2638,12 @@
|
|
|
2691
2638
|
},
|
|
2692
2639
|
{
|
|
2693
2640
|
"name": "ModuleLoadEvent",
|
|
2694
|
-
"id": "interface-ModuleLoadEvent-
|
|
2641
|
+
"id": "interface-ModuleLoadEvent-2ebba83f2a934dc788aa9e117b7bda050be69e26ecbdbdda1d9e6e9a378e46e78a069988f2e5db079668ca60e83b9a1ee5e67b4c9d146ffba19f3bc5de4783c7",
|
|
2695
2642
|
"file": "packages/core/src/lib/services/i18n/i18n.service.ts",
|
|
2696
2643
|
"deprecated": false,
|
|
2697
2644
|
"deprecationMessage": "",
|
|
2698
2645
|
"type": "interface",
|
|
2699
|
-
"sourceCode": "import { DOCUMENT } from '@angular/common';\nimport { Injectable, OnDestroy, Signal, inject } from '@angular/core';\nimport { LangChangeEvent, TranslateLoader, TranslateService } from '@ngx-translate/core';\nimport { BehaviorSubject, forkJoin, Observable, of, Subject } from 'rxjs';\nimport {\n catchError,\n filter,\n map,\n take,\n tap,\n switchMap,\n takeUntil,\n distinctUntilChanged,\n} from 'rxjs/operators';\nimport {\n GlobalConfig,\n EuiLazyService,\n EuiServiceStatus,\n getI18nServiceConfigFromBase,\n I18nLoaderConfig,\n I18nServiceConfig,\n I18nState,\n ModuleConfig,\n getBrowserDefaultLanguage,\n EuiEuLanguages,\n CoreState,\n DeepPartial,\n} from '@eui/base';\n\nimport { I18nLoader, LoadedResources } from './i18n.loader';\nimport { GLOBAL_CONFIG_TOKEN } from '../config/tokens';\nimport { LogService } from '../log';\nimport { StoreService } from '../store';\nimport { DEFAULT_I18N_SERVICE_CONFIG } from '../config/defaults';\nimport { isEqual } from 'lodash-es';\nimport { Selector } from 'reselect';\nimport { toSignal } from '@angular/core/rxjs-interop';\n\nexport interface ModuleLoadEvent {\n ready: boolean;\n name: string | null | undefined;\n // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n error?: any;\n}\n\nconst getLastAddedModule: Selector<CoreState, string> = (state: CoreState) => state.app?.loadedConfigModules?.lastAddedModule as string;\n\n@Injectable({\n providedIn: 'root',\n})\nexport class I18nService<T extends I18nState = I18nState> extends EuiLazyService<T | I18nState> implements OnDestroy {\n protected config: I18nServiceConfig;\n protected onModuleLoad: BehaviorSubject<ModuleLoadEvent>;\n protected baseGlobalConfig = inject<GlobalConfig>(GLOBAL_CONFIG_TOKEN);\n protected translateService = inject(TranslateService);\n protected logService = inject(LogService, { optional: true });\n private translateLoader = inject(TranslateLoader);\n protected store = inject<StoreService<T>>(StoreService);\n private static readonly DEFAULT_STATE: I18nState = { activeLang: 'en' };\n private document = inject<Document>(DOCUMENT);\n /**\n * a single signal holding the state - initial state is null\n */\n private state: Signal<T>;\n /**\n * a BehaviorSubject holding the state - initial state is null\n * This is the main source of truth for the state\n */\n private stateSubject: BehaviorSubject<T>;\n private subNotifier: Subject<void> = new Subject();\n\n constructor() {\n super(I18nService.DEFAULT_STATE as T);\n // Create a BehaviorSubject with the initial state\n this.stateSubject = new BehaviorSubject<T>(this.stateInstance as T);\n\n // Initialize signal with base state\n this.state = toSignal(this.stateSubject, { equal: isEqual, requireSync: true });\n\n // Subscribe to base class state changes\n this.onStateChange.subscribe((newState) => {\n // const clonedState = structuredClone(newState as T);\n this.stateSubject.next(newState as T);\n });\n\n this.config = getI18nServiceConfigFromBase(this.baseGlobalConfig);\n this.onModuleLoad = new BehaviorSubject<ModuleLoadEvent>({ ready: false, name: null });\n }\n\n ngOnDestroy(): void {\n this.subNotifier.next(void 0);\n this.subNotifier.complete();\n }\n\n getState(): Observable<T>;\n /**\n * @deprecated this will be removed in a future version\n * @param mapFn\n */\n getState<K = T>(mapFn?: (state: T) => K): Observable<K>;\n getState<a extends keyof DeepPartial<T>>(key?: a): Observable<DeepPartial<a>>;\n getState<K = T>(keyOrMapFn?: ((state: T) => K) | string): Observable<DeepPartial<K>> {\n if (!keyOrMapFn) {\n return this.stateSubject.asObservable().pipe(\n takeUntil(this.subNotifier),\n distinctUntilChanged((x, y) => isEqual(x, y)),\n ) as Observable<DeepPartial<K>>;\n }\n\n if (typeof keyOrMapFn === 'function') {\n return this.stateSubject.asObservable().pipe(\n takeUntil(this.subNotifier),\n map(state => keyOrMapFn(state)),\n distinctUntilChanged((x, y) => isEqual(x, y)),\n );\n }\n\n return this.stateSubject.asObservable().pipe(\n takeUntil(this.subNotifier),\n map(state => {\n const keys = (keyOrMapFn as string).split('.');\n\n // Traverse the object based on the dot notation\n return keys.reduce<unknown>((acc, currKey) => {\n const record = acc as Record<string, unknown> | null | undefined;\n return record && record[currKey] !== undefined ? record[currKey] : undefined;\n }, state);\n }),\n distinctUntilChanged((x, y) => isEqual(x, y)),\n ) as unknown as Observable<DeepPartial<K>>;\n }\n\n updateState(state: DeepPartial<T>): void;\n /**\n * @deprecated it will be removed in next version. Use updateState(partialState: DeepPartial<T>) instead\n * @param slice\n * @param reducer\n */\n updateState(slice: DeepPartial<T>, reducer: (state: T, action: DeepPartial<T>) => T): void;\n updateState<K extends T>(state: DeepPartial<K>, reducer?: (state: T, action: DeepPartial<K>) => T): void {\n if(state.activeLang) {\n this.updateHTMLDOMLang(state.activeLang as string);\n }\n this.stateInstance = super.deepMerge(this.stateInstance as T, { ...state });\n // Emit state change\n this.onStateChange.next(this.stateInstance);\n }\n\n /**\n * This method is used to get the state as readonly signal.\n */\n getSignal(): Signal<T> {\n return this.state;\n }\n\n init(langState?: T): Observable<EuiServiceStatus> {\n const initLang = langState && langState.activeLang ? langState.activeLang : this.preparedDefaultLanguage();\n const initState = {\n ...langState,\n activeLang: initLang,\n };\n if (typeof initLang === 'string') {\n super.initEuiService(this.store);\n this.updateState(initState as DeepPartial<T>);\n return this.setup(initLang);\n }\n return of({ success: false, error: 'Initial active lang should be string' });\n }\n\n /**\n * A pipe function that could serve as a wrapper of another observable\n * e.g. ngx-translate i18n.onReady('my_module').pipe(switchMap(()=>translate.get('eui.KEY')));\n * WARNING: onReady will emit only once for a loaded Module, going to another and then going back will not result\n * into another emission.\n *\n * @param moduleName the name of the module that has been given through the eUI globalConfig. In case non provided\n * fetch module name from the state.\n */\n onReady(moduleName?: string): Observable<ModuleLoadEvent> {\n return this.onModuleLoad.pipe(\n switchMap((evt: ModuleLoadEvent) =>\n moduleName\n ? of(evt)\n : this.store.select(getLastAddedModule).pipe(\n tap((m) => (moduleName = m)),\n map(() => evt),\n ),\n ),\n // emit only if event emitted matches the module name and is ready\n filter((evt: ModuleLoadEvent) => evt.ready === true && evt.name === moduleName),\n // make sure that observable completes\n take(1),\n );\n }\n\n public lazyLoad(config: I18nLoaderConfig): Observable<EuiServiceStatus> {\n const moduleId = Math.floor(Math.random() * 100000 + 1).toLocaleString();\n return this.addResources(config, moduleId);\n }\n\n lazyLoadInit(moduleConfig: ModuleConfig, moduleName?: string): Observable<EuiServiceStatus> {\n const i18nLoaderConfig = moduleConfig as I18nLoaderConfig;\n // add resources\n return this.addResources(i18nLoaderConfig, moduleName);\n }\n\n /**\n * Add resources based of a config loader\n *\n * @param config I18nLoaderConfig\n * @param moduleName\n * @return Promise<EuiServiceStatus> an EuiServiceStatus when translation has fully loaded\n */\n public addResources(config: I18nLoaderConfig, moduleName?: string): Observable<EuiServiceStatus> {\n // emit that module is loading\n this.onModuleLoad.next({ ready: false, name: moduleName });\n\n const loader = this.translateLoader;\n if (loader instanceof I18nLoader) {\n // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const langSubscription: Observable<any>[] = [];\n const i18nLoader = <I18nLoader>loader;\n\n // add the resources to the loader\n const resources = i18nLoader.addResources(config);\n\n // manually load the resources for the CURRENT language and add them to the translate service\n langSubscription.push(\n i18nLoader.loadResources(resources, this.translateService.currentLang() as string).pipe(\n take(1),\n tap((loadedResources: LoadedResources) => {\n // add the new set of translations to the current language\n this.translateService.setTranslation(this.translateService.currentLang() as string, loadedResources.translations, true);\n }),\n ),\n );\n\n // if the current language is different from the DEFAULT language\n const defaultLang = (this.config.defaultLanguage || this.translateService.fallbackLang()) as string;\n if (this.translateService.currentLang() !== defaultLang) {\n // manually load the resources for the default language and add them to the translation service\n langSubscription.push(\n i18nLoader.loadResources(resources, defaultLang).pipe(\n take(1),\n tap((loadedResources: LoadedResources) => {\n this.translateService.setTranslation(defaultLang, loadedResources.translations, true);\n }),\n ),\n );\n }\n\n return forkJoin(langSubscription).pipe(\n map((loadedResourcesArr: LoadedResources[]) =>\n !loadedResourcesArr[0].hasError ? { success: true } : { success: false, error: loadedResourcesArr[0].errors },\n ),\n tap(() => {\n // emit status of module loading progress\n this.onModuleLoad.next({ ready: true, name: moduleName });\n }),\n catchError((error) => {\n // emit status of module loading progress\n this.onModuleLoad.next({ ready: true, name: moduleName, error });\n return of({ success: false, error });\n }),\n );\n } else {\n return of({ success: false, error: 'currentLoader is not an I18nLoader.' });\n }\n }\n\n /**\n * Prepares the default language\n */\n private preparedDefaultLanguage(): string {\n const browserPref = getBrowserDefaultLanguage();\n // If user has browser preferred lang, and that language is part of the languages array\n if (browserPref && this.config.languages && EuiEuLanguages.getLanguageCodes(this.config.languages).includes(browserPref)) {\n return browserPref;\n }\n return this.config.defaultLanguage as string;\n }\n\n /**\n * @param initLanguage if given default language to override default language coming from the\n * configuration token.\n */\n private setup(initLanguage: string): Observable<EuiServiceStatus> {\n // use the default config as a reference base\n this.config = Object.assign({}, DEFAULT_I18N_SERVICE_CONFIG, this.config);\n // configure the translation config service\n if (this.config.languages) {\n this.translateService.addLangs(EuiEuLanguages.getLanguageCodes(this.config.languages));\n if (this.logService) {\n this.logService.info(`I18n accepted languages set to ${EuiEuLanguages.getLanguageCodes(this.config.languages)}`);\n }\n }\n // set the current language, causing to load translations\n return this.translateService.use(initLanguage).pipe(\n tap(() => {\n this.bindActiveLangStateToTranslateService();\n this.bindTranslateServiceLangChangeToState();\n if (this.config.defaultLanguage) {\n this.setDefaultLanguage(this.config.defaultLanguage);\n }\n }),\n map(() => {\n if (this.translateLoader instanceof I18nLoader) {\n const failedResources = this.translateLoader.getFailedResources();\n if (failedResources.length > 0) {\n return { success: false, error: failedResources };\n }\n }\n return { success: true };\n }),\n catchError((error) => of({ success: false, error })),\n );\n }\n\n private bindActiveLangStateToTranslateService(): void {\n this.getState((s) => s.activeLang)\n .pipe(takeUntil(this.subNotifier))\n .subscribe((lang) => {\n if (lang !== null && this.translateService.currentLang() !== lang) {\n this.use(lang);\n }\n });\n }\n\n private bindTranslateServiceLangChangeToState(): void {\n this.translateService.onLangChange.subscribe((event: LangChangeEvent) => {\n if (this.stateInstance.activeLang !== event.lang) {\n this.updateState({ activeLang: event.lang } as Partial<T>);\n }\n if (this.logService) {\n this.logService.info(`I18n current language set to ${event.lang}`);\n }\n });\n }\n\n private setDefaultLanguage(defaultLanguage: string): void {\n // removed, current language is already calculated in init, setup function fill use it directly, not default\n // this.translateService.currentLang = default_language || this.config.defaultLanguage;\n this.translateService.setFallbackLang(defaultLanguage);\n if (this.logService) {\n this.logService.info(`I18n default language set to ${defaultLanguage}`);\n }\n }\n\n /**\n * change the currently used language\n *\n * @param lang is the language code based on the convention you used e.g. (en or en-EN)\n * @returns Observable that returns an object contain the object translation for given language after language\n * fully loaded.\n */\n // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private use(lang: string): Observable<any> {\n return this.translateService.use(lang);\n }\n\n /**\n * updates the HTML element lang attribute\n *\n * @private\n */\n private updateHTMLDOMLang(lang: string): void {\n this.document.documentElement.lang = lang;\n }\n}\n",
|
|
2646
|
+
"sourceCode": "import { DOCUMENT } from '@angular/common';\nimport { Injectable, OnDestroy, Signal, inject } from '@angular/core';\nimport { LangChangeEvent, TranslateLoader, TranslateService } from '@ngx-translate/core';\nimport { BehaviorSubject, forkJoin, Observable, of, Subject } from 'rxjs';\nimport {\n catchError,\n filter,\n map,\n take,\n tap,\n switchMap,\n takeUntil,\n distinctUntilChanged,\n} from 'rxjs/operators';\nimport {\n GlobalConfig,\n EuiLazyService,\n EuiServiceStatus,\n getI18nServiceConfigFromBase,\n I18nLoaderConfig,\n I18nServiceConfig,\n I18nState,\n ModuleConfig,\n getBrowserDefaultLanguage,\n EuiEuLanguages,\n CoreState,\n DeepPartial,\n} from '@eui/base';\n\nimport { I18nLoader, LoadedResources } from './i18n.loader';\nimport { GLOBAL_CONFIG_TOKEN } from '../config/tokens';\nimport { LogService } from '../log';\nimport { StoreService } from '../store';\nimport { DEFAULT_I18N_SERVICE_CONFIG } from '../config/defaults';\nimport { isEqual } from 'lodash-es';\nimport { Selector } from 'reselect';\nimport { toSignal } from '@angular/core/rxjs-interop';\n\nexport interface ModuleLoadEvent {\n ready: boolean;\n name: string | null | undefined;\n // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n error?: any;\n}\n\nconst getLastAddedModule: Selector<CoreState, string> = (state: CoreState) => state.app?.loadedConfigModules?.lastAddedModule as string;\n\n@Injectable({\n providedIn: 'root',\n})\nexport class I18nService<T extends I18nState = I18nState> extends EuiLazyService<T | I18nState> implements OnDestroy {\n protected config: I18nServiceConfig;\n protected onModuleLoad: BehaviorSubject<ModuleLoadEvent>;\n private static readonly DEFAULT_STATE: I18nState = { activeLang: 'en' };\n protected baseGlobalConfig = inject<GlobalConfig>(GLOBAL_CONFIG_TOKEN);\n protected translateService = inject(TranslateService);\n protected logService = inject(LogService, { optional: true });\n private translateLoader = inject(TranslateLoader);\n protected store = inject<StoreService<T>>(StoreService);\n private document = inject<Document>(DOCUMENT);\n /**\n * a single signal holding the state - initial state is null\n */\n private state: Signal<T>;\n /**\n * a BehaviorSubject holding the state - initial state is null\n * This is the main source of truth for the state\n */\n private stateSubject: BehaviorSubject<T>;\n private subNotifier = new Subject<void>();\n\n constructor() {\n super(I18nService.DEFAULT_STATE as T);\n // Create a BehaviorSubject with the initial state\n this.stateSubject = new BehaviorSubject<T>(this.stateInstance as T);\n\n // Initialize signal with base state\n this.state = toSignal(this.stateSubject, { equal: isEqual, requireSync: true });\n\n // Subscribe to base class state changes\n this.onStateChange.subscribe((newState) => {\n // const clonedState = structuredClone(newState as T);\n this.stateSubject.next(newState as T);\n });\n\n this.config = getI18nServiceConfigFromBase(this.baseGlobalConfig);\n this.onModuleLoad = new BehaviorSubject<ModuleLoadEvent>({ ready: false, name: null });\n }\n\n ngOnDestroy(): void {\n this.subNotifier.next(void 0);\n this.subNotifier.complete();\n }\n\n getState(): Observable<T>;\n /**\n * @deprecated this will be removed in a future version\n * @param mapFn\n */\n getState<K = T>(mapFn?: (state: T) => K): Observable<K>;\n getState<a extends keyof DeepPartial<T>>(key?: a): Observable<DeepPartial<a>>;\n getState<K = T>(keyOrMapFn?: ((state: T) => K) | string): Observable<DeepPartial<K>> {\n if (!keyOrMapFn) {\n return this.stateSubject.asObservable().pipe(\n takeUntil(this.subNotifier),\n distinctUntilChanged((x, y) => isEqual(x, y)),\n ) as Observable<DeepPartial<K>>;\n }\n\n if (typeof keyOrMapFn === 'function') {\n return this.stateSubject.asObservable().pipe(\n takeUntil(this.subNotifier),\n map(state => keyOrMapFn(state)),\n distinctUntilChanged((x, y) => isEqual(x, y)),\n );\n }\n\n return this.stateSubject.asObservable().pipe(\n takeUntil(this.subNotifier),\n map(state => {\n const keys = (keyOrMapFn as string).split('.');\n\n // Traverse the object based on the dot notation\n return keys.reduce<unknown>((acc, currKey) => {\n const record = acc as Record<string, unknown> | null | undefined;\n return record && record[currKey] !== undefined ? record[currKey] : undefined;\n }, state);\n }),\n distinctUntilChanged((x, y) => isEqual(x, y)),\n ) as unknown as Observable<DeepPartial<K>>;\n }\n\n updateState(state: DeepPartial<T>): void;\n /**\n * @deprecated it will be removed in next version. Use updateState(partialState: DeepPartial<T>) instead\n * @param slice\n * @param reducer\n */\n updateState(slice: DeepPartial<T>, reducer: (state: T, action: DeepPartial<T>) => T): void;\n updateState<K extends T>(state: DeepPartial<K>, reducer?: (state: T, action: DeepPartial<K>) => T): void {\n if(state.activeLang) {\n this.updateHTMLDOMLang(state.activeLang as string);\n }\n this.stateInstance = super.deepMerge(this.stateInstance as T, { ...state });\n // Emit state change\n this.onStateChange.next(this.stateInstance);\n }\n\n /**\n * This method is used to get the state as readonly signal.\n */\n getSignal(): Signal<T> {\n return this.state;\n }\n\n init(langState?: T): Observable<EuiServiceStatus> {\n const initLang = langState && langState.activeLang ? langState.activeLang : this.preparedDefaultLanguage();\n const initState = {\n ...langState,\n activeLang: initLang,\n };\n if (typeof initLang === 'string') {\n super.initEuiService(this.store);\n this.updateState(initState as DeepPartial<T>);\n return this.setup(initLang);\n }\n return of({ success: false, error: 'Initial active lang should be string' });\n }\n\n /**\n * A pipe function that could serve as a wrapper of another observable\n * e.g. ngx-translate i18n.onReady('my_module').pipe(switchMap(()=>translate.get('eui.KEY')));\n * WARNING: onReady will emit only once for a loaded Module, going to another and then going back will not result\n * into another emission.\n *\n * @param moduleName the name of the module that has been given through the eUI globalConfig. In case non provided\n * fetch module name from the state.\n */\n onReady(moduleName?: string): Observable<ModuleLoadEvent> {\n return this.onModuleLoad.pipe(\n switchMap((evt: ModuleLoadEvent) =>\n moduleName\n ? of(evt)\n : this.store.select(getLastAddedModule).pipe(\n tap((m) => (moduleName = m)),\n map(() => evt),\n ),\n ),\n // emit only if event emitted matches the module name and is ready\n filter((evt: ModuleLoadEvent) => evt.ready === true && evt.name === moduleName),\n // make sure that observable completes\n take(1),\n );\n }\n\n public lazyLoad(config: I18nLoaderConfig): Observable<EuiServiceStatus> {\n const moduleId = Math.floor(Math.random() * 100000 + 1).toLocaleString();\n return this.addResources(config, moduleId);\n }\n\n lazyLoadInit(moduleConfig: ModuleConfig, moduleName?: string): Observable<EuiServiceStatus> {\n const i18nLoaderConfig = moduleConfig as I18nLoaderConfig;\n // add resources\n return this.addResources(i18nLoaderConfig, moduleName);\n }\n\n /**\n * Add resources based of a config loader\n *\n * @param config I18nLoaderConfig\n * @param moduleName\n * @return Promise<EuiServiceStatus> an EuiServiceStatus when translation has fully loaded\n */\n public addResources(config: I18nLoaderConfig, moduleName?: string): Observable<EuiServiceStatus> {\n // emit that module is loading\n this.onModuleLoad.next({ ready: false, name: moduleName });\n\n const loader = this.translateLoader;\n if (loader instanceof I18nLoader) {\n // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const langSubscription: Observable<any>[] = [];\n const i18nLoader = loader as I18nLoader;\n\n // add the resources to the loader\n const resources = i18nLoader.addResources(config);\n\n // manually load the resources for the CURRENT language and add them to the translate service\n langSubscription.push(\n i18nLoader.loadResources(resources, this.translateService.currentLang() as string).pipe(\n take(1),\n tap((loadedResources: LoadedResources) => {\n // add the new set of translations to the current language\n this.translateService.setTranslation(this.translateService.currentLang() as string, loadedResources.translations, true);\n }),\n ),\n );\n\n // if the current language is different from the DEFAULT language\n const defaultLang = (this.config.defaultLanguage || this.translateService.fallbackLang()) as string;\n if (this.translateService.currentLang() !== defaultLang) {\n // manually load the resources for the default language and add them to the translation service\n langSubscription.push(\n i18nLoader.loadResources(resources, defaultLang).pipe(\n take(1),\n tap((loadedResources: LoadedResources) => {\n this.translateService.setTranslation(defaultLang, loadedResources.translations, true);\n }),\n ),\n );\n }\n\n return forkJoin(langSubscription).pipe(\n map((loadedResourcesArr: LoadedResources[]) =>\n !loadedResourcesArr[0].hasError ? { success: true } : { success: false, error: loadedResourcesArr[0].errors },\n ),\n tap(() => {\n // emit status of module loading progress\n this.onModuleLoad.next({ ready: true, name: moduleName });\n }),\n catchError((error) => {\n // emit status of module loading progress\n this.onModuleLoad.next({ ready: true, name: moduleName, error });\n return of({ success: false, error });\n }),\n );\n } else {\n return of({ success: false, error: 'currentLoader is not an I18nLoader.' });\n }\n }\n\n /**\n * Prepares the default language\n */\n private preparedDefaultLanguage(): string {\n const browserPref = getBrowserDefaultLanguage();\n // If user has browser preferred lang, and that language is part of the languages array\n if (browserPref && this.config.languages && EuiEuLanguages.getLanguageCodes(this.config.languages).includes(browserPref)) {\n return browserPref;\n }\n return this.config.defaultLanguage as string;\n }\n\n /**\n * @param initLanguage if given default language to override default language coming from the\n * configuration token.\n */\n private setup(initLanguage: string): Observable<EuiServiceStatus> {\n // use the default config as a reference base\n this.config = Object.assign({}, DEFAULT_I18N_SERVICE_CONFIG, this.config);\n // configure the translation config service\n if (this.config.languages) {\n this.translateService.addLangs(EuiEuLanguages.getLanguageCodes(this.config.languages));\n if (this.logService) {\n this.logService.info(`I18n accepted languages set to ${EuiEuLanguages.getLanguageCodes(this.config.languages)}`);\n }\n }\n // set the current language, causing to load translations\n return this.translateService.use(initLanguage).pipe(\n tap(() => {\n this.bindActiveLangStateToTranslateService();\n this.bindTranslateServiceLangChangeToState();\n if (this.config.defaultLanguage) {\n this.setDefaultLanguage(this.config.defaultLanguage);\n }\n }),\n map(() => {\n if (this.translateLoader instanceof I18nLoader) {\n const failedResources = this.translateLoader.getFailedResources();\n if (failedResources.length > 0) {\n return { success: false, error: failedResources };\n }\n }\n return { success: true };\n }),\n catchError((error) => of({ success: false, error })),\n );\n }\n\n private bindActiveLangStateToTranslateService(): void {\n this.getState((s) => s.activeLang)\n .pipe(takeUntil(this.subNotifier))\n .subscribe((lang) => {\n if (lang !== null && this.translateService.currentLang() !== lang) {\n this.use(lang);\n }\n });\n }\n\n private bindTranslateServiceLangChangeToState(): void {\n this.translateService.onLangChange.subscribe((event: LangChangeEvent) => {\n if (this.stateInstance.activeLang !== event.lang) {\n this.updateState({ activeLang: event.lang } as Partial<T>);\n }\n if (this.logService) {\n this.logService.info(`I18n current language set to ${event.lang}`);\n }\n });\n }\n\n private setDefaultLanguage(defaultLanguage: string): void {\n // removed, current language is already calculated in init, setup function fill use it directly, not default\n // this.translateService.currentLang = default_language || this.config.defaultLanguage;\n this.translateService.setFallbackLang(defaultLanguage);\n if (this.logService) {\n this.logService.info(`I18n default language set to ${defaultLanguage}`);\n }\n }\n\n /**\n * change the currently used language\n *\n * @param lang is the language code based on the convention you used e.g. (en or en-EN)\n * @returns Observable that returns an object contain the object translation for given language after language\n * fully loaded.\n */\n // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private use(lang: string): Observable<any> {\n return this.translateService.use(lang);\n }\n\n /**\n * updates the HTML element lang attribute\n *\n * @private\n */\n private updateHTMLDOMLang(lang: string): void {\n this.document.documentElement.lang = lang;\n }\n}\n",
|
|
2700
2647
|
"displayName": "ModuleLoadEvent",
|
|
2701
2648
|
"properties": [
|
|
2702
2649
|
{
|
|
@@ -3117,12 +3064,12 @@
|
|
|
3117
3064
|
},
|
|
3118
3065
|
{
|
|
3119
3066
|
"name": "ResourceError",
|
|
3120
|
-
"id": "interface-ResourceError-
|
|
3067
|
+
"id": "interface-ResourceError-5c76c65c641a590c27fa827029ac4ce1fd7224732a481d314bfbbb45f31b0f77fb51f6478ac93e8d43f8d8694d33a791b51931801364c1b6b8d9589141ed8171",
|
|
3121
3068
|
"file": "packages/core/src/lib/services/i18n/i18n.loader.ts",
|
|
3122
3069
|
"deprecated": false,
|
|
3123
3070
|
"deprecationMessage": "",
|
|
3124
3071
|
"type": "interface",
|
|
3125
|
-
"sourceCode": "import { Injectable, inject } from '@angular/core';\nimport { HttpClient } from '@angular/common/http';\nimport { TranslateLoader, TranslationObject, provideTranslateLoader } from '@ngx-translate/core';\nimport { forkJoin, Observable, of } from 'rxjs';\nimport { catchError, map } from 'rxjs/operators';\n\nimport {\n getI18nLoaderConfig,\n I18nResource,\n type EuiAppConfig,\n mergeAll,\n Logger,\n I18nLoaderConfig,\n I18nConfig,\n TranslationsCompiler,\n} from '@eui/base';\nimport { I18nResourceImpl } from './i18n.resource';\nimport { CONFIG_TOKEN } from '../config/tokens';\nimport { LogService } from '../log/log.service';\nimport { transformTranslations } from './i18n-utils';\n\ninterface ResourceError {\n isError: boolean;\n error?: string;\n resource?: I18nResourceImpl;\n}\n\nexport interface LoadedResources {\n translations: TranslationObject;\n hasError: boolean;\n errors?:
|
|
3072
|
+
"sourceCode": "import { Injectable, inject } from '@angular/core';\nimport { HttpClient } from '@angular/common/http';\nimport { TranslateLoader, TranslationObject, provideTranslateLoader } from '@ngx-translate/core';\nimport { forkJoin, Observable, of } from 'rxjs';\nimport { catchError, map } from 'rxjs/operators';\n\nimport {\n getI18nLoaderConfig,\n I18nResource,\n type EuiAppConfig,\n mergeAll,\n Logger,\n I18nLoaderConfig,\n I18nConfig,\n TranslationsCompiler,\n} from '@eui/base';\nimport { I18nResourceImpl } from './i18n.resource';\nimport { CONFIG_TOKEN } from '../config/tokens';\nimport { LogService } from '../log/log.service';\nimport { transformTranslations } from './i18n-utils';\n\ninterface ResourceError {\n isError: boolean;\n error?: string;\n resource?: I18nResourceImpl;\n}\n\nexport interface LoadedResources {\n translations: TranslationObject;\n hasError: boolean;\n errors?: LoadedResourcesError[];\n}\n\nexport interface LoadedResourcesError {\n resource: I18nResourceImpl;\n error: string;\n}\n\nexport type TranslationKeys = Record<string, string>;\n\n@Injectable()\nexport class I18nLoader implements TranslateLoader {\n protected http = inject(HttpClient);\n protected logService = inject(LogService, { optional: true });\n protected euiAppConfig = inject<EuiAppConfig>(CONFIG_TOKEN);\n\n protected resources: I18nResourceImpl[] = [];\n protected failedResources: LoadedResourcesError[] = [];\n private logger: Logger | undefined;\n private icuEnabled: boolean;\n\n constructor() {\n const logService = this.logService;\n\n if (logService) {\n this.logger = logService.getLogger('core.I18nLoader')\n }\n\n // create the resources from the config object\n const i18nConfig: I18nConfig | undefined = this.euiAppConfig.global && this.euiAppConfig.global.i18n;\n const i18nLoaderConfig: I18nLoaderConfig | undefined = i18nConfig && i18nConfig.i18nLoader;\n this.resources.push(...this.createResources(i18nLoaderConfig as I18nLoaderConfig));\n\n // Auto-detect ICU mode from config\n this.icuEnabled = !!(i18nConfig && i18nConfig.icuEnabled);\n }\n\n /**\n * Gets the translations from the server\n *\n * @param lang\n * @returns Observable<object>\n */\n public getTranslation(lang: string): Observable<TranslationObject> {\n return this.loadResources(this.resources, lang).pipe(\n map((loadedResources: LoadedResources) => {\n this.failedResources = loadedResources.hasError ? (loadedResources.errors as LoadedResourcesError[]) : [];\n const translations = loadedResources.translations;\n return this.icuEnabled ? transformTranslations(translations) : translations;\n }),\n );\n }\n\n /**\n * Adds resources\n *\n * @param config loader configuration\n * @returns Observable<any> | false\n */\n public addResources(config: I18nLoaderConfig): I18nResourceImpl[] {\n // create the resources\n let resources = this.createResources(config);\n\n // filter the resources first, to avoid duplicates\n resources = resources.filter((resource) => !this.resources.some((res) => res.equals(resource)));\n\n // add the new resources to the list of existing resources\n this.resources.push(...resources);\n\n // return the filtered resources\n return resources;\n }\n\n /**\n * Removes resources from the loader instance\n */\n public removeResources(removedResources: I18nResourceImpl[]): void {\n this.resources = this.resources.filter((res) => !removedResources.some((removedResource) => removedResource.equals(res)));\n }\n\n /**\n * Loads an array of resources, by language\n *\n * @param resources the definition of the resources\n * @param lang the resource language to load\n * @returns Observable<any>\n */\n public loadResources(resources: I18nResourceImpl[], lang: string): Observable<{ hasError: boolean; translations: TranslationObject; errors?: LoadedResourcesError[] }> {\n // if there are resources to load\n if (Array.isArray(resources) && resources.length > 0) {\n // load all the resources in an array of Observable\n const requests = resources.map((resource) => this.loadResource(resource, lang));\n // group all the observables with forkJoin and deep merge them\n return forkJoin(requests).pipe(\n map((response) => {\n const successResp: TranslationKeys[] = [];\n const errResp: LoadedResourcesError[] = [];\n response.forEach((item) => {\n if ((item as ResourceError).isError) {\n errResp.push({ resource: (item as ResourceError).resource as I18nResourceImpl, error: (item as ResourceError).error as string });\n } else {\n successResp.push(item as TranslationKeys);\n }\n });\n if (successResp.length === response.length) {\n return { hasError: false, translations: mergeAll(successResp) };\n } else {\n return { hasError: true, translations: mergeAll(successResp), errors: errResp };\n }\n }),\n );\n } else {\n // no resources to load\n return of({ hasError: false, translations: {} });\n }\n }\n\n /**\n * Returns resources that failed\n */\n public getFailedResources(): LoadedResourcesError[] {\n return this.failedResources;\n }\n\n /**\n * Create resources from a config file\n *\n * @param config loader configuration\n * @returns I18nResourceImpl[] resources\n */\n protected createResources(config: I18nLoaderConfig): I18nResourceImpl[] {\n // use the default config as a reference base\n config = getI18nLoaderConfig(config);\n\n const resources: I18nResourceImpl[] = [];\n\n // extract the i18n folders from config\n const i18nFolders: string[] = Array.isArray(config.i18nFolders)\n ? config.i18nFolders\n : config.i18nFolders\n ? [config.i18nFolders]\n : [];\n if (i18nFolders) {\n // add the i18n folders to resources\n resources.push(...i18nFolders.map((folder) => new I18nResourceImpl(`assets/${folder}/`, '.json')));\n }\n\n // extract the i18n services from config\n const i18nServices: string[] = Array.isArray(config.i18nServices)\n ? config.i18nServices\n : config.i18nServices\n ? [config.i18nServices]\n : [];\n if (i18nServices) {\n // add the i18n services to resources\n resources.push(...i18nServices.map((service) => new I18nResourceImpl(service)));\n }\n\n // extract the i18n resources from config\n const i18nResources: I18nResource[] = Array.isArray(config.i18nResources)\n ? config.i18nResources\n : config.i18nResources\n ? [config.i18nResources]\n : [];\n if (i18nResources) {\n // add the i18n resources to resources\n resources.push(\n ...i18nResources.map(\n (resource) =>\n new I18nResourceImpl(\n resource.prefix,\n resource.suffix,\n this.getResourceCompileFunction(resource.compileTranslations as string),\n ),\n ),\n );\n }\n\n return resources;\n }\n\n /**\n * Loads a resource, by language\n *\n * @param resource the definition of the resource\n * @param lang the resource language to load\n * @returns Observable<any>\n */\n protected loadResource(resource: I18nResourceImpl, lang: string): Observable<TranslationKeys | ResourceError> {\n // the path to the resource\n const path = resource.getPath(lang);\n\n // load the translations from the path\n return this.http.get(path).pipe(\n // preprocess the translations using the resource compiler\n map((translations: unknown) => resource.compileTranslations(translations, lang) as TranslationKeys),\n map((translations: TranslationKeys) => {\n // resource loaded properly, send a info message\n this.logger?.info(`I18n resource loaded from path ${path}`);\n // return the translations\n return translations;\n }),\n catchError((err) => {\n // remove failed resource from loaded resource array\n // this.removeResources([resource]);\n // resource not loaded properly, send a warning message\n this.logger?.warn(`I18n resource NOT loaded from path ${path}`, err);\n const resourceError: ResourceError = { error: `I18n resource NOT loaded from path ${path}`, resource, isError: true };\n return of(resourceError);\n }),\n );\n }\n\n private getResourceCompileFunction(id: string): TranslationsCompiler | undefined {\n const customHandlers = this.euiAppConfig.customHandler;\n if (customHandlers && typeof customHandlers[id] === 'function') {\n return customHandlers[id];\n }\n return undefined;\n }\n}\n\nexport const translateConfig = {\n loader: provideTranslateLoader(I18nLoader),\n};\n",
|
|
3126
3073
|
"displayName": "ResourceError",
|
|
3127
3074
|
"properties": [
|
|
3128
3075
|
{
|
|
@@ -5475,45 +5422,6 @@
|
|
|
5475
5422
|
"outgoing": []
|
|
5476
5423
|
}
|
|
5477
5424
|
},
|
|
5478
|
-
{
|
|
5479
|
-
"name": "TranslationKeys",
|
|
5480
|
-
"id": "interface-TranslationKeys-75cb6d0d93d6a3f4e2fa1fd4b023f34987d8cebdfdf8b390384b098bd5c6709e337d1b60c7adca6332802ce507fd7b984451cd8c241dd24f640464af80a7cc36",
|
|
5481
|
-
"file": "packages/core/src/lib/services/i18n/i18n.loader.ts",
|
|
5482
|
-
"deprecated": false,
|
|
5483
|
-
"deprecationMessage": "",
|
|
5484
|
-
"type": "interface",
|
|
5485
|
-
"sourceCode": "import { Injectable, inject } from '@angular/core';\nimport { HttpClient } from '@angular/common/http';\nimport { TranslateLoader, TranslationObject, provideTranslateLoader } from '@ngx-translate/core';\nimport { forkJoin, Observable, of } from 'rxjs';\nimport { catchError, map } from 'rxjs/operators';\n\nimport {\n getI18nLoaderConfig,\n I18nResource,\n type EuiAppConfig,\n mergeAll,\n Logger,\n I18nLoaderConfig,\n I18nConfig,\n TranslationsCompiler,\n} from '@eui/base';\nimport { I18nResourceImpl } from './i18n.resource';\nimport { CONFIG_TOKEN } from '../config/tokens';\nimport { LogService } from '../log/log.service';\nimport { transformTranslations } from './i18n-utils';\n\ninterface ResourceError {\n isError: boolean;\n error?: string;\n resource?: I18nResourceImpl;\n}\n\nexport interface LoadedResources {\n translations: TranslationObject;\n hasError: boolean;\n errors?: Array<LoadedResourcesError>;\n}\n\nexport interface LoadedResourcesError {\n resource: I18nResourceImpl;\n error: string;\n}\n\nexport interface TranslationKeys {\n [key: string]: string\n}\n\n@Injectable()\nexport class I18nLoader implements TranslateLoader {\n protected http = inject(HttpClient);\n protected logService = inject(LogService, { optional: true });\n protected euiAppConfig = inject<EuiAppConfig>(CONFIG_TOKEN);\n\n protected resources: I18nResourceImpl[] = [];\n protected failedResources: Array<LoadedResourcesError> = [];\n private logger: Logger | undefined;\n private icuEnabled: boolean;\n\n constructor() {\n const logService = this.logService;\n\n if (logService) {\n this.logger = logService.getLogger('core.I18nLoader')\n }\n\n // create the resources from the config object\n const i18nConfig: I18nConfig | undefined = this.euiAppConfig.global && this.euiAppConfig.global.i18n;\n const i18nLoaderConfig: I18nLoaderConfig | undefined = i18nConfig && i18nConfig.i18nLoader;\n this.resources.push(...this.createResources(i18nLoaderConfig as I18nLoaderConfig));\n\n // Auto-detect ICU mode from config\n this.icuEnabled = !!(i18nConfig && i18nConfig.icuEnabled);\n }\n\n /**\n * Gets the translations from the server\n *\n * @param lang\n * @returns Observable<object>\n */\n public getTranslation(lang: string): Observable<TranslationObject> {\n return this.loadResources(this.resources, lang).pipe(\n map((loadedResources: LoadedResources) => {\n this.failedResources = loadedResources.hasError ? (loadedResources.errors as LoadedResourcesError[]) : [];\n const translations = loadedResources.translations;\n return this.icuEnabled ? transformTranslations(translations) : translations;\n }),\n );\n }\n\n /**\n * Adds resources\n *\n * @param config loader configuration\n * @returns Observable<any> | false\n */\n public addResources(config: I18nLoaderConfig): I18nResourceImpl[] {\n // create the resources\n let resources = this.createResources(config);\n\n // filter the resources first, to avoid duplicates\n resources = resources.filter((resource) => !this.resources.some((res) => res.equals(resource)));\n\n // add the new resources to the list of existing resources\n this.resources.push(...resources);\n\n // return the filtered resources\n return resources;\n }\n\n /**\n * Removes resources from the loader instance\n */\n public removeResources(removedResources: I18nResourceImpl[]): void {\n this.resources = this.resources.filter((res) => !removedResources.some((removedResource) => removedResource.equals(res)));\n }\n\n /**\n * Loads an array of resources, by language\n *\n * @param resources the definition of the resources\n * @param lang the resource language to load\n * @returns Observable<any>\n */\n public loadResources(resources: I18nResourceImpl[], lang: string): Observable<{ hasError: boolean; translations: TranslationObject; errors?: LoadedResourcesError[] }> {\n // if there are resources to load\n if (Array.isArray(resources) && resources.length > 0) {\n // load all the resources in an array of Observable\n const requests = resources.map((resource) => this.loadResource(resource, lang));\n // group all the observables with forkJoin and deep merge them\n return forkJoin(requests).pipe(\n map((response) => {\n const successResp: TranslationKeys[] = [];\n const errResp: Array<LoadedResourcesError> = [];\n response.forEach((item) => {\n if ((<ResourceError>item).isError) {\n errResp.push({ resource: (<ResourceError>item).resource as I18nResourceImpl, error: (<ResourceError>item).error as string });\n } else {\n successResp.push(item as TranslationKeys);\n }\n });\n if (successResp.length === response.length) {\n return { hasError: false, translations: mergeAll(successResp) };\n } else {\n return { hasError: true, translations: mergeAll(successResp), errors: errResp };\n }\n }),\n );\n } else {\n // no resources to load\n return of({ hasError: false, translations: {} });\n }\n }\n\n /**\n * Returns resources that failed\n */\n public getFailedResources(): Array<LoadedResourcesError> {\n return this.failedResources;\n }\n\n /**\n * Create resources from a config file\n *\n * @param config loader configuration\n * @returns I18nResourceImpl[] resources\n */\n protected createResources(config: I18nLoaderConfig): I18nResourceImpl[] {\n // use the default config as a reference base\n config = getI18nLoaderConfig(config);\n\n const resources: I18nResourceImpl[] = [];\n\n // extract the i18n folders from config\n const i18nFolders: string[] = Array.isArray(config.i18nFolders)\n ? config.i18nFolders\n : config.i18nFolders\n ? [config.i18nFolders]\n : [];\n if (i18nFolders) {\n // add the i18n folders to resources\n resources.push(...i18nFolders.map((folder) => new I18nResourceImpl(`assets/${folder}/`, '.json')));\n }\n\n // extract the i18n services from config\n const i18nServices: string[] = Array.isArray(config.i18nServices)\n ? config.i18nServices\n : config.i18nServices\n ? [config.i18nServices]\n : [];\n if (i18nServices) {\n // add the i18n services to resources\n resources.push(...i18nServices.map((service) => new I18nResourceImpl(service)));\n }\n\n // extract the i18n resources from config\n const i18nResources: I18nResource[] = Array.isArray(config.i18nResources)\n ? config.i18nResources\n : config.i18nResources\n ? [config.i18nResources]\n : [];\n if (i18nResources) {\n // add the i18n resources to resources\n resources.push(\n ...i18nResources.map(\n (resource) =>\n new I18nResourceImpl(\n resource.prefix,\n resource.suffix,\n this.getResourceCompileFunction(resource.compileTranslations as string),\n ),\n ),\n );\n }\n\n return resources;\n }\n\n /**\n * Loads a resource, by language\n *\n * @param resource the definition of the resource\n * @param lang the resource language to load\n * @returns Observable<any>\n */\n protected loadResource(resource: I18nResourceImpl, lang: string): Observable<TranslationKeys | ResourceError> {\n // the path to the resource\n const path = resource.getPath(lang);\n\n // load the translations from the path\n return this.http.get(path).pipe(\n // preprocess the translations using the resource compiler\n map((translations: unknown) => resource.compileTranslations(translations, lang) as TranslationKeys),\n map((translations: TranslationKeys) => {\n // resource loaded properly, send a info message\n this.logger?.info(`I18n resource loaded from path ${path}`);\n // return the translations\n return translations;\n }),\n catchError((err) => {\n // remove failed resource from loaded resource array\n // this.removeResources([resource]);\n // resource not loaded properly, send a warning message\n this.logger?.warn(`I18n resource NOT loaded from path ${path}`, err);\n const resourceError: ResourceError = { error: `I18n resource NOT loaded from path ${path}`, resource, isError: true };\n return of(resourceError);\n }),\n );\n }\n\n private getResourceCompileFunction(id: string): TranslationsCompiler | undefined {\n const customHandlers = this.euiAppConfig.customHandler;\n if (customHandlers && typeof customHandlers[id] === 'function') {\n return customHandlers[id];\n }\n return undefined;\n }\n}\n\nexport const translateConfig = {\n loader: provideTranslateLoader(I18nLoader),\n};\n",
|
|
5486
|
-
"displayName": "TranslationKeys",
|
|
5487
|
-
"properties": [],
|
|
5488
|
-
"indexSignatures": [
|
|
5489
|
-
{
|
|
5490
|
-
"id": "index-declaration-75cb6d0d93d6a3f4e2fa1fd4b023f34987d8cebdfdf8b390384b098bd5c6709e337d1b60c7adca6332802ce507fd7b984451cd8c241dd24f640464af80a7cc36",
|
|
5491
|
-
"args": [
|
|
5492
|
-
{
|
|
5493
|
-
"name": "key",
|
|
5494
|
-
"type": "string",
|
|
5495
|
-
"optional": false,
|
|
5496
|
-
"dotDotDotToken": false,
|
|
5497
|
-
"deprecated": false,
|
|
5498
|
-
"deprecationMessage": ""
|
|
5499
|
-
}
|
|
5500
|
-
],
|
|
5501
|
-
"returnType": "string",
|
|
5502
|
-
"line": 39,
|
|
5503
|
-
"deprecated": false,
|
|
5504
|
-
"deprecationMessage": "",
|
|
5505
|
-
"rawdescription": "\n",
|
|
5506
|
-
"description": ""
|
|
5507
|
-
}
|
|
5508
|
-
],
|
|
5509
|
-
"kind": 182,
|
|
5510
|
-
"methods": [],
|
|
5511
|
-
"extends": [],
|
|
5512
|
-
"relationships": {
|
|
5513
|
-
"incoming": [],
|
|
5514
|
-
"outgoing": []
|
|
5515
|
-
}
|
|
5516
|
-
},
|
|
5517
5425
|
{
|
|
5518
5426
|
"name": "UIState",
|
|
5519
5427
|
"id": "interface-UIState-7123a09221ac6d66b37d7ef7923cbac59975eb1c28a034354b2909a3f356748582bb8023c439f912dff26dc01e5c67bc64fb09e07c798741ee2af56b2c371cc6",
|
|
@@ -8051,7 +7959,7 @@
|
|
|
8051
7959
|
},
|
|
8052
7960
|
{
|
|
8053
7961
|
"name": "EuiDynamicMenuService",
|
|
8054
|
-
"id": "injectable-EuiDynamicMenuService-
|
|
7962
|
+
"id": "injectable-EuiDynamicMenuService-c487c876d1803592a1355e349f87ba777a16d37912d1b0a606bf4601e2105efbeb5a1ce63d0f083b1cd5489bbfeb69a0c6f59a05c8aec9f0050ab31b515f7fa3",
|
|
8055
7963
|
"file": "packages/core/src/lib/services/dynamic-menu/dynamic-menu.service.ts",
|
|
8056
7964
|
"coverageIgnore": false,
|
|
8057
7965
|
"properties": [
|
|
@@ -8061,7 +7969,7 @@
|
|
|
8061
7969
|
"defaultValue": "[]",
|
|
8062
7970
|
"deprecated": false,
|
|
8063
7971
|
"deprecationMessage": "",
|
|
8064
|
-
"type": "
|
|
7972
|
+
"type": "EuiMenuItem[]",
|
|
8065
7973
|
"indexKey": "",
|
|
8066
7974
|
"optional": false,
|
|
8067
7975
|
"description": "",
|
|
@@ -8076,7 +7984,7 @@
|
|
|
8076
7984
|
"args": [
|
|
8077
7985
|
{
|
|
8078
7986
|
"name": "links",
|
|
8079
|
-
"type": "
|
|
7987
|
+
"type": "EuiMenuItem[]",
|
|
8080
7988
|
"optional": false,
|
|
8081
7989
|
"dotDotDotToken": false,
|
|
8082
7990
|
"deprecated": false,
|
|
@@ -8084,7 +7992,7 @@
|
|
|
8084
7992
|
}
|
|
8085
7993
|
],
|
|
8086
7994
|
"optional": false,
|
|
8087
|
-
"returnType": "
|
|
7995
|
+
"returnType": "EuiMenuItem[]",
|
|
8088
7996
|
"typeParameters": [],
|
|
8089
7997
|
"line": 28,
|
|
8090
7998
|
"deprecated": false,
|
|
@@ -8094,7 +8002,7 @@
|
|
|
8094
8002
|
"jsdoctags": [
|
|
8095
8003
|
{
|
|
8096
8004
|
"name": "links",
|
|
8097
|
-
"type": "
|
|
8005
|
+
"type": "EuiMenuItem[]",
|
|
8098
8006
|
"optional": false,
|
|
8099
8007
|
"dotDotDotToken": false,
|
|
8100
8008
|
"deprecated": false,
|
|
@@ -8123,7 +8031,7 @@
|
|
|
8123
8031
|
"deprecationMessage": "",
|
|
8124
8032
|
"description": "",
|
|
8125
8033
|
"rawdescription": "\n",
|
|
8126
|
-
"sourceCode": "import { Injectable, inject } from '@angular/core';\nimport { getUserState, EuiMenuItem } from '@eui/base';\nimport { EuiPermissionService } from '../permission/permission.service';\nimport { StoreService } from '../store';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class EuiDynamicMenuService {\n menuLinks:
|
|
8034
|
+
"sourceCode": "import { Injectable, inject } from '@angular/core';\nimport { getUserState, EuiMenuItem } from '@eui/base';\nimport { EuiPermissionService } from '../permission/permission.service';\nimport { StoreService } from '../store';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class EuiDynamicMenuService {\n menuLinks: EuiMenuItem[] = [];\n private euiPermission = inject(EuiPermissionService);\n private store = inject(StoreService);\n\n // TODO: it should be moved euiService, or it should be static\n // TODO: can we moved that service inside the module of the component that's using it?\n constructor() {\n this.store.select(getUserState).subscribe((user) => {\n if (user?.menuLinks) {\n this.menuLinks = user.menuLinks;\n }\n });\n }\n\n getMenuLinks(): EuiMenuItem[] {\n return this.menuLinks;\n }\n\n filterEuiMenuItemsWithRights(links: EuiMenuItem[]): EuiMenuItem[] {\n return links.filter((link) => {\n if (link.children != null) {\n link.children = this.filterEuiMenuItemsWithRights(link.children);\n }\n\n // First check if the user is denied access:\n if (link.deniedRightId) {\n if (this.euiPermission.checkRight(link.deniedRightId)) {\n return false;\n }\n }\n if (link.deniedRightIds) {\n for (const deniedRightId of link.deniedRightIds) {\n if (this.euiPermission.checkRight(deniedRightId)) {\n return false;\n }\n }\n }\n\n // Then check if the user needs to be allowed access explicitly:\n if (link.allowedRightId) {\n return this.euiPermission.checkRight(link.allowedRightId);\n }\n if (link.allowedRightIds) {\n for (const allowedRightId of link.allowedRightIds) {\n if (this.euiPermission.checkRight(allowedRightId)) {\n return true;\n }\n }\n // User doesn't have one of the allowed rights. Deny access:\n return false;\n }\n\n // Access to the menu item is not denied, therefore allow it:\n return true;\n });\n }\n}\n",
|
|
8127
8035
|
"constructorObj": {
|
|
8128
8036
|
"name": "constructor",
|
|
8129
8037
|
"description": "",
|
|
@@ -10647,7 +10555,7 @@
|
|
|
10647
10555
|
},
|
|
10648
10556
|
{
|
|
10649
10557
|
"name": "I18nLoader",
|
|
10650
|
-
"id": "injectable-I18nLoader-
|
|
10558
|
+
"id": "injectable-I18nLoader-5c76c65c641a590c27fa827029ac4ce1fd7224732a481d314bfbbb45f31b0f77fb51f6478ac93e8d43f8d8694d33a791b51931801364c1b6b8d9589141ed8171",
|
|
10651
10559
|
"file": "packages/core/src/lib/services/i18n/i18n.loader.ts",
|
|
10652
10560
|
"coverageIgnore": false,
|
|
10653
10561
|
"properties": [
|
|
@@ -10661,7 +10569,7 @@
|
|
|
10661
10569
|
"indexKey": "",
|
|
10662
10570
|
"optional": false,
|
|
10663
10571
|
"description": "",
|
|
10664
|
-
"line":
|
|
10572
|
+
"line": 45,
|
|
10665
10573
|
"rawdescription": "\n",
|
|
10666
10574
|
"modifierKind": [
|
|
10667
10575
|
124
|
|
@@ -10673,11 +10581,11 @@
|
|
|
10673
10581
|
"defaultValue": "[]",
|
|
10674
10582
|
"deprecated": false,
|
|
10675
10583
|
"deprecationMessage": "",
|
|
10676
|
-
"type": "
|
|
10584
|
+
"type": "LoadedResourcesError[]",
|
|
10677
10585
|
"indexKey": "",
|
|
10678
10586
|
"optional": false,
|
|
10679
10587
|
"description": "",
|
|
10680
|
-
"line":
|
|
10588
|
+
"line": 48,
|
|
10681
10589
|
"rawdescription": "\n",
|
|
10682
10590
|
"modifierKind": [
|
|
10683
10591
|
124
|
|
@@ -10693,7 +10601,7 @@
|
|
|
10693
10601
|
"indexKey": "",
|
|
10694
10602
|
"optional": false,
|
|
10695
10603
|
"description": "",
|
|
10696
|
-
"line":
|
|
10604
|
+
"line": 43,
|
|
10697
10605
|
"rawdescription": "\n",
|
|
10698
10606
|
"modifierKind": [
|
|
10699
10607
|
124
|
|
@@ -10709,7 +10617,7 @@
|
|
|
10709
10617
|
"indexKey": "",
|
|
10710
10618
|
"optional": false,
|
|
10711
10619
|
"description": "",
|
|
10712
|
-
"line":
|
|
10620
|
+
"line": 44,
|
|
10713
10621
|
"rawdescription": "\n",
|
|
10714
10622
|
"modifierKind": [
|
|
10715
10623
|
124
|
|
@@ -10725,7 +10633,7 @@
|
|
|
10725
10633
|
"indexKey": "",
|
|
10726
10634
|
"optional": false,
|
|
10727
10635
|
"description": "",
|
|
10728
|
-
"line":
|
|
10636
|
+
"line": 47,
|
|
10729
10637
|
"rawdescription": "\n",
|
|
10730
10638
|
"modifierKind": [
|
|
10731
10639
|
124
|
|
@@ -10749,7 +10657,7 @@
|
|
|
10749
10657
|
"optional": false,
|
|
10750
10658
|
"returnType": "I18nResourceImpl[]",
|
|
10751
10659
|
"typeParameters": [],
|
|
10752
|
-
"line":
|
|
10660
|
+
"line": 90,
|
|
10753
10661
|
"deprecated": false,
|
|
10754
10662
|
"deprecationMessage": "",
|
|
10755
10663
|
"rawdescription": "\n\nAdds resources\n\n",
|
|
@@ -10760,8 +10668,8 @@
|
|
|
10760
10668
|
"jsdoctags": [
|
|
10761
10669
|
{
|
|
10762
10670
|
"name": {
|
|
10763
|
-
"pos":
|
|
10764
|
-
"end":
|
|
10671
|
+
"pos": 2829,
|
|
10672
|
+
"end": 2835,
|
|
10765
10673
|
"kind": 80,
|
|
10766
10674
|
"id": 0,
|
|
10767
10675
|
"flags": 16842752,
|
|
@@ -10774,8 +10682,8 @@
|
|
|
10774
10682
|
"deprecated": false,
|
|
10775
10683
|
"deprecationMessage": "",
|
|
10776
10684
|
"tagName": {
|
|
10777
|
-
"pos":
|
|
10778
|
-
"end":
|
|
10685
|
+
"pos": 2823,
|
|
10686
|
+
"end": 2828,
|
|
10779
10687
|
"kind": 80,
|
|
10780
10688
|
"id": 0,
|
|
10781
10689
|
"flags": 16842752,
|
|
@@ -10786,8 +10694,8 @@
|
|
|
10786
10694
|
},
|
|
10787
10695
|
{
|
|
10788
10696
|
"tagName": {
|
|
10789
|
-
"pos":
|
|
10790
|
-
"end":
|
|
10697
|
+
"pos": 2865,
|
|
10698
|
+
"end": 2872,
|
|
10791
10699
|
"kind": 80,
|
|
10792
10700
|
"id": 0,
|
|
10793
10701
|
"flags": 16842752,
|
|
@@ -10814,7 +10722,7 @@
|
|
|
10814
10722
|
"optional": false,
|
|
10815
10723
|
"returnType": "I18nResourceImpl[]",
|
|
10816
10724
|
"typeParameters": [],
|
|
10817
|
-
"line":
|
|
10725
|
+
"line": 161,
|
|
10818
10726
|
"deprecated": false,
|
|
10819
10727
|
"deprecationMessage": "",
|
|
10820
10728
|
"rawdescription": "\n\nCreate resources from a config file\n\n",
|
|
@@ -10825,8 +10733,8 @@
|
|
|
10825
10733
|
"jsdoctags": [
|
|
10826
10734
|
{
|
|
10827
10735
|
"name": {
|
|
10828
|
-
"pos":
|
|
10829
|
-
"end":
|
|
10736
|
+
"pos": 5746,
|
|
10737
|
+
"end": 5752,
|
|
10830
10738
|
"kind": 80,
|
|
10831
10739
|
"id": 0,
|
|
10832
10740
|
"flags": 16842752,
|
|
@@ -10839,8 +10747,8 @@
|
|
|
10839
10747
|
"deprecated": false,
|
|
10840
10748
|
"deprecationMessage": "",
|
|
10841
10749
|
"tagName": {
|
|
10842
|
-
"pos":
|
|
10843
|
-
"end":
|
|
10750
|
+
"pos": 5740,
|
|
10751
|
+
"end": 5745,
|
|
10844
10752
|
"kind": 80,
|
|
10845
10753
|
"id": 0,
|
|
10846
10754
|
"flags": 16842752,
|
|
@@ -10851,8 +10759,8 @@
|
|
|
10851
10759
|
},
|
|
10852
10760
|
{
|
|
10853
10761
|
"tagName": {
|
|
10854
|
-
"pos":
|
|
10855
|
-
"end":
|
|
10762
|
+
"pos": 5782,
|
|
10763
|
+
"end": 5789,
|
|
10856
10764
|
"kind": 80,
|
|
10857
10765
|
"id": 0,
|
|
10858
10766
|
"flags": 16842752,
|
|
@@ -10868,9 +10776,9 @@
|
|
|
10868
10776
|
"coverageIgnore": false,
|
|
10869
10777
|
"args": [],
|
|
10870
10778
|
"optional": false,
|
|
10871
|
-
"returnType": "
|
|
10779
|
+
"returnType": "LoadedResourcesError[]",
|
|
10872
10780
|
"typeParameters": [],
|
|
10873
|
-
"line":
|
|
10781
|
+
"line": 151,
|
|
10874
10782
|
"deprecated": false,
|
|
10875
10783
|
"deprecationMessage": "",
|
|
10876
10784
|
"rawdescription": "\n\nReturns resources that failed\n",
|
|
@@ -10895,7 +10803,7 @@
|
|
|
10895
10803
|
"optional": false,
|
|
10896
10804
|
"returnType": "Observable<TranslationObject>",
|
|
10897
10805
|
"typeParameters": [],
|
|
10898
|
-
"line":
|
|
10806
|
+
"line": 74,
|
|
10899
10807
|
"deprecated": false,
|
|
10900
10808
|
"deprecationMessage": "",
|
|
10901
10809
|
"rawdescription": "\n\nGets the translations from the server\n\n",
|
|
@@ -10906,8 +10814,8 @@
|
|
|
10906
10814
|
"jsdoctags": [
|
|
10907
10815
|
{
|
|
10908
10816
|
"name": {
|
|
10909
|
-
"pos":
|
|
10910
|
-
"end":
|
|
10817
|
+
"pos": 2222,
|
|
10818
|
+
"end": 2226,
|
|
10911
10819
|
"kind": 80,
|
|
10912
10820
|
"id": 0,
|
|
10913
10821
|
"flags": 16842752,
|
|
@@ -10920,8 +10828,8 @@
|
|
|
10920
10828
|
"deprecated": false,
|
|
10921
10829
|
"deprecationMessage": "",
|
|
10922
10830
|
"tagName": {
|
|
10923
|
-
"pos":
|
|
10924
|
-
"end":
|
|
10831
|
+
"pos": 2216,
|
|
10832
|
+
"end": 2221,
|
|
10925
10833
|
"kind": 80,
|
|
10926
10834
|
"id": 0,
|
|
10927
10835
|
"flags": 16842752,
|
|
@@ -10932,8 +10840,8 @@
|
|
|
10932
10840
|
},
|
|
10933
10841
|
{
|
|
10934
10842
|
"tagName": {
|
|
10935
|
-
"pos":
|
|
10936
|
-
"end":
|
|
10843
|
+
"pos": 2235,
|
|
10844
|
+
"end": 2242,
|
|
10937
10845
|
"kind": 80,
|
|
10938
10846
|
"id": 0,
|
|
10939
10847
|
"flags": 16842752,
|
|
@@ -10968,7 +10876,7 @@
|
|
|
10968
10876
|
"optional": false,
|
|
10969
10877
|
"returnType": "Observable<TranslationKeys | ResourceError>",
|
|
10970
10878
|
"typeParameters": [],
|
|
10971
|
-
"line":
|
|
10879
|
+
"line": 219,
|
|
10972
10880
|
"deprecated": false,
|
|
10973
10881
|
"deprecationMessage": "",
|
|
10974
10882
|
"rawdescription": "\n\nLoads a resource, by language\n\n",
|
|
@@ -10979,8 +10887,8 @@
|
|
|
10979
10887
|
"jsdoctags": [
|
|
10980
10888
|
{
|
|
10981
10889
|
"name": {
|
|
10982
|
-
"pos":
|
|
10983
|
-
"end":
|
|
10890
|
+
"pos": 7767,
|
|
10891
|
+
"end": 7775,
|
|
10984
10892
|
"kind": 80,
|
|
10985
10893
|
"id": 0,
|
|
10986
10894
|
"flags": 16842752,
|
|
@@ -10993,8 +10901,8 @@
|
|
|
10993
10901
|
"deprecated": false,
|
|
10994
10902
|
"deprecationMessage": "",
|
|
10995
10903
|
"tagName": {
|
|
10996
|
-
"pos":
|
|
10997
|
-
"end":
|
|
10904
|
+
"pos": 7761,
|
|
10905
|
+
"end": 7766,
|
|
10998
10906
|
"kind": 80,
|
|
10999
10907
|
"id": 0,
|
|
11000
10908
|
"flags": 16842752,
|
|
@@ -11005,8 +10913,8 @@
|
|
|
11005
10913
|
},
|
|
11006
10914
|
{
|
|
11007
10915
|
"name": {
|
|
11008
|
-
"pos":
|
|
11009
|
-
"end":
|
|
10916
|
+
"pos": 7821,
|
|
10917
|
+
"end": 7825,
|
|
11010
10918
|
"kind": 80,
|
|
11011
10919
|
"id": 0,
|
|
11012
10920
|
"flags": 16842752,
|
|
@@ -11019,8 +10927,8 @@
|
|
|
11019
10927
|
"deprecated": false,
|
|
11020
10928
|
"deprecationMessage": "",
|
|
11021
10929
|
"tagName": {
|
|
11022
|
-
"pos":
|
|
11023
|
-
"end":
|
|
10930
|
+
"pos": 7815,
|
|
10931
|
+
"end": 7820,
|
|
11024
10932
|
"kind": 80,
|
|
11025
10933
|
"id": 0,
|
|
11026
10934
|
"flags": 16842752,
|
|
@@ -11031,8 +10939,8 @@
|
|
|
11031
10939
|
},
|
|
11032
10940
|
{
|
|
11033
10941
|
"tagName": {
|
|
11034
|
-
"pos":
|
|
11035
|
-
"end":
|
|
10942
|
+
"pos": 7864,
|
|
10943
|
+
"end": 7871,
|
|
11036
10944
|
"kind": 80,
|
|
11037
10945
|
"id": 0,
|
|
11038
10946
|
"flags": 16842752,
|
|
@@ -11067,7 +10975,7 @@
|
|
|
11067
10975
|
"optional": false,
|
|
11068
10976
|
"returnType": "Observable<{ hasError: boolean; translations: TranslationObject; errors?: LoadedResourcesError[] }>",
|
|
11069
10977
|
"typeParameters": [],
|
|
11070
|
-
"line":
|
|
10978
|
+
"line": 118,
|
|
11071
10979
|
"deprecated": false,
|
|
11072
10980
|
"deprecationMessage": "",
|
|
11073
10981
|
"rawdescription": "\n\nLoads an array of resources, by language\n\n",
|
|
@@ -11078,8 +10986,8 @@
|
|
|
11078
10986
|
"jsdoctags": [
|
|
11079
10987
|
{
|
|
11080
10988
|
"name": {
|
|
11081
|
-
"pos":
|
|
11082
|
-
"end":
|
|
10989
|
+
"pos": 3768,
|
|
10990
|
+
"end": 3777,
|
|
11083
10991
|
"kind": 80,
|
|
11084
10992
|
"id": 0,
|
|
11085
10993
|
"flags": 16842752,
|
|
@@ -11092,8 +11000,8 @@
|
|
|
11092
11000
|
"deprecated": false,
|
|
11093
11001
|
"deprecationMessage": "",
|
|
11094
11002
|
"tagName": {
|
|
11095
|
-
"pos":
|
|
11096
|
-
"end":
|
|
11003
|
+
"pos": 3762,
|
|
11004
|
+
"end": 3767,
|
|
11097
11005
|
"kind": 80,
|
|
11098
11006
|
"id": 0,
|
|
11099
11007
|
"flags": 16842752,
|
|
@@ -11104,8 +11012,8 @@
|
|
|
11104
11012
|
},
|
|
11105
11013
|
{
|
|
11106
11014
|
"name": {
|
|
11107
|
-
"pos":
|
|
11108
|
-
"end":
|
|
11015
|
+
"pos": 3824,
|
|
11016
|
+
"end": 3828,
|
|
11109
11017
|
"kind": 80,
|
|
11110
11018
|
"id": 0,
|
|
11111
11019
|
"flags": 16842752,
|
|
@@ -11118,8 +11026,8 @@
|
|
|
11118
11026
|
"deprecated": false,
|
|
11119
11027
|
"deprecationMessage": "",
|
|
11120
11028
|
"tagName": {
|
|
11121
|
-
"pos":
|
|
11122
|
-
"end":
|
|
11029
|
+
"pos": 3818,
|
|
11030
|
+
"end": 3823,
|
|
11123
11031
|
"kind": 80,
|
|
11124
11032
|
"id": 0,
|
|
11125
11033
|
"flags": 16842752,
|
|
@@ -11130,8 +11038,8 @@
|
|
|
11130
11038
|
},
|
|
11131
11039
|
{
|
|
11132
11040
|
"tagName": {
|
|
11133
|
-
"pos":
|
|
11134
|
-
"end":
|
|
11041
|
+
"pos": 3867,
|
|
11042
|
+
"end": 3874,
|
|
11135
11043
|
"kind": 80,
|
|
11136
11044
|
"id": 0,
|
|
11137
11045
|
"flags": 16842752,
|
|
@@ -11158,7 +11066,7 @@
|
|
|
11158
11066
|
"optional": false,
|
|
11159
11067
|
"returnType": "void",
|
|
11160
11068
|
"typeParameters": [],
|
|
11161
|
-
"line":
|
|
11069
|
+
"line": 107,
|
|
11162
11070
|
"deprecated": false,
|
|
11163
11071
|
"deprecationMessage": "",
|
|
11164
11072
|
"rawdescription": "\n\nRemoves resources from the loader instance\n",
|
|
@@ -11185,14 +11093,14 @@
|
|
|
11185
11093
|
"deprecationMessage": "",
|
|
11186
11094
|
"description": "",
|
|
11187
11095
|
"rawdescription": "\n",
|
|
11188
|
-
"sourceCode": "import { Injectable, inject } from '@angular/core';\nimport { HttpClient } from '@angular/common/http';\nimport { TranslateLoader, TranslationObject, provideTranslateLoader } from '@ngx-translate/core';\nimport { forkJoin, Observable, of } from 'rxjs';\nimport { catchError, map } from 'rxjs/operators';\n\nimport {\n getI18nLoaderConfig,\n I18nResource,\n type EuiAppConfig,\n mergeAll,\n Logger,\n I18nLoaderConfig,\n I18nConfig,\n TranslationsCompiler,\n} from '@eui/base';\nimport { I18nResourceImpl } from './i18n.resource';\nimport { CONFIG_TOKEN } from '../config/tokens';\nimport { LogService } from '../log/log.service';\nimport { transformTranslations } from './i18n-utils';\n\ninterface ResourceError {\n isError: boolean;\n error?: string;\n resource?: I18nResourceImpl;\n}\n\nexport interface LoadedResources {\n translations: TranslationObject;\n hasError: boolean;\n errors?:
|
|
11096
|
+
"sourceCode": "import { Injectable, inject } from '@angular/core';\nimport { HttpClient } from '@angular/common/http';\nimport { TranslateLoader, TranslationObject, provideTranslateLoader } from '@ngx-translate/core';\nimport { forkJoin, Observable, of } from 'rxjs';\nimport { catchError, map } from 'rxjs/operators';\n\nimport {\n getI18nLoaderConfig,\n I18nResource,\n type EuiAppConfig,\n mergeAll,\n Logger,\n I18nLoaderConfig,\n I18nConfig,\n TranslationsCompiler,\n} from '@eui/base';\nimport { I18nResourceImpl } from './i18n.resource';\nimport { CONFIG_TOKEN } from '../config/tokens';\nimport { LogService } from '../log/log.service';\nimport { transformTranslations } from './i18n-utils';\n\ninterface ResourceError {\n isError: boolean;\n error?: string;\n resource?: I18nResourceImpl;\n}\n\nexport interface LoadedResources {\n translations: TranslationObject;\n hasError: boolean;\n errors?: LoadedResourcesError[];\n}\n\nexport interface LoadedResourcesError {\n resource: I18nResourceImpl;\n error: string;\n}\n\nexport type TranslationKeys = Record<string, string>;\n\n@Injectable()\nexport class I18nLoader implements TranslateLoader {\n protected http = inject(HttpClient);\n protected logService = inject(LogService, { optional: true });\n protected euiAppConfig = inject<EuiAppConfig>(CONFIG_TOKEN);\n\n protected resources: I18nResourceImpl[] = [];\n protected failedResources: LoadedResourcesError[] = [];\n private logger: Logger | undefined;\n private icuEnabled: boolean;\n\n constructor() {\n const logService = this.logService;\n\n if (logService) {\n this.logger = logService.getLogger('core.I18nLoader')\n }\n\n // create the resources from the config object\n const i18nConfig: I18nConfig | undefined = this.euiAppConfig.global && this.euiAppConfig.global.i18n;\n const i18nLoaderConfig: I18nLoaderConfig | undefined = i18nConfig && i18nConfig.i18nLoader;\n this.resources.push(...this.createResources(i18nLoaderConfig as I18nLoaderConfig));\n\n // Auto-detect ICU mode from config\n this.icuEnabled = !!(i18nConfig && i18nConfig.icuEnabled);\n }\n\n /**\n * Gets the translations from the server\n *\n * @param lang\n * @returns Observable<object>\n */\n public getTranslation(lang: string): Observable<TranslationObject> {\n return this.loadResources(this.resources, lang).pipe(\n map((loadedResources: LoadedResources) => {\n this.failedResources = loadedResources.hasError ? (loadedResources.errors as LoadedResourcesError[]) : [];\n const translations = loadedResources.translations;\n return this.icuEnabled ? transformTranslations(translations) : translations;\n }),\n );\n }\n\n /**\n * Adds resources\n *\n * @param config loader configuration\n * @returns Observable<any> | false\n */\n public addResources(config: I18nLoaderConfig): I18nResourceImpl[] {\n // create the resources\n let resources = this.createResources(config);\n\n // filter the resources first, to avoid duplicates\n resources = resources.filter((resource) => !this.resources.some((res) => res.equals(resource)));\n\n // add the new resources to the list of existing resources\n this.resources.push(...resources);\n\n // return the filtered resources\n return resources;\n }\n\n /**\n * Removes resources from the loader instance\n */\n public removeResources(removedResources: I18nResourceImpl[]): void {\n this.resources = this.resources.filter((res) => !removedResources.some((removedResource) => removedResource.equals(res)));\n }\n\n /**\n * Loads an array of resources, by language\n *\n * @param resources the definition of the resources\n * @param lang the resource language to load\n * @returns Observable<any>\n */\n public loadResources(resources: I18nResourceImpl[], lang: string): Observable<{ hasError: boolean; translations: TranslationObject; errors?: LoadedResourcesError[] }> {\n // if there are resources to load\n if (Array.isArray(resources) && resources.length > 0) {\n // load all the resources in an array of Observable\n const requests = resources.map((resource) => this.loadResource(resource, lang));\n // group all the observables with forkJoin and deep merge them\n return forkJoin(requests).pipe(\n map((response) => {\n const successResp: TranslationKeys[] = [];\n const errResp: LoadedResourcesError[] = [];\n response.forEach((item) => {\n if ((item as ResourceError).isError) {\n errResp.push({ resource: (item as ResourceError).resource as I18nResourceImpl, error: (item as ResourceError).error as string });\n } else {\n successResp.push(item as TranslationKeys);\n }\n });\n if (successResp.length === response.length) {\n return { hasError: false, translations: mergeAll(successResp) };\n } else {\n return { hasError: true, translations: mergeAll(successResp), errors: errResp };\n }\n }),\n );\n } else {\n // no resources to load\n return of({ hasError: false, translations: {} });\n }\n }\n\n /**\n * Returns resources that failed\n */\n public getFailedResources(): LoadedResourcesError[] {\n return this.failedResources;\n }\n\n /**\n * Create resources from a config file\n *\n * @param config loader configuration\n * @returns I18nResourceImpl[] resources\n */\n protected createResources(config: I18nLoaderConfig): I18nResourceImpl[] {\n // use the default config as a reference base\n config = getI18nLoaderConfig(config);\n\n const resources: I18nResourceImpl[] = [];\n\n // extract the i18n folders from config\n const i18nFolders: string[] = Array.isArray(config.i18nFolders)\n ? config.i18nFolders\n : config.i18nFolders\n ? [config.i18nFolders]\n : [];\n if (i18nFolders) {\n // add the i18n folders to resources\n resources.push(...i18nFolders.map((folder) => new I18nResourceImpl(`assets/${folder}/`, '.json')));\n }\n\n // extract the i18n services from config\n const i18nServices: string[] = Array.isArray(config.i18nServices)\n ? config.i18nServices\n : config.i18nServices\n ? [config.i18nServices]\n : [];\n if (i18nServices) {\n // add the i18n services to resources\n resources.push(...i18nServices.map((service) => new I18nResourceImpl(service)));\n }\n\n // extract the i18n resources from config\n const i18nResources: I18nResource[] = Array.isArray(config.i18nResources)\n ? config.i18nResources\n : config.i18nResources\n ? [config.i18nResources]\n : [];\n if (i18nResources) {\n // add the i18n resources to resources\n resources.push(\n ...i18nResources.map(\n (resource) =>\n new I18nResourceImpl(\n resource.prefix,\n resource.suffix,\n this.getResourceCompileFunction(resource.compileTranslations as string),\n ),\n ),\n );\n }\n\n return resources;\n }\n\n /**\n * Loads a resource, by language\n *\n * @param resource the definition of the resource\n * @param lang the resource language to load\n * @returns Observable<any>\n */\n protected loadResource(resource: I18nResourceImpl, lang: string): Observable<TranslationKeys | ResourceError> {\n // the path to the resource\n const path = resource.getPath(lang);\n\n // load the translations from the path\n return this.http.get(path).pipe(\n // preprocess the translations using the resource compiler\n map((translations: unknown) => resource.compileTranslations(translations, lang) as TranslationKeys),\n map((translations: TranslationKeys) => {\n // resource loaded properly, send a info message\n this.logger?.info(`I18n resource loaded from path ${path}`);\n // return the translations\n return translations;\n }),\n catchError((err) => {\n // remove failed resource from loaded resource array\n // this.removeResources([resource]);\n // resource not loaded properly, send a warning message\n this.logger?.warn(`I18n resource NOT loaded from path ${path}`, err);\n const resourceError: ResourceError = { error: `I18n resource NOT loaded from path ${path}`, resource, isError: true };\n return of(resourceError);\n }),\n );\n }\n\n private getResourceCompileFunction(id: string): TranslationsCompiler | undefined {\n const customHandlers = this.euiAppConfig.customHandler;\n if (customHandlers && typeof customHandlers[id] === 'function') {\n return customHandlers[id];\n }\n return undefined;\n }\n}\n\nexport const translateConfig = {\n loader: provideTranslateLoader(I18nLoader),\n};\n",
|
|
11189
11097
|
"constructorObj": {
|
|
11190
11098
|
"name": "constructor",
|
|
11191
11099
|
"description": "",
|
|
11192
11100
|
"deprecated": false,
|
|
11193
11101
|
"deprecationMessage": "",
|
|
11194
11102
|
"args": [],
|
|
11195
|
-
"line":
|
|
11103
|
+
"line": 50,
|
|
11196
11104
|
"rawdescription": "\n"
|
|
11197
11105
|
},
|
|
11198
11106
|
"extends": [],
|
|
@@ -11204,7 +11112,7 @@
|
|
|
11204
11112
|
},
|
|
11205
11113
|
{
|
|
11206
11114
|
"name": "I18nService",
|
|
11207
|
-
"id": "injectable-I18nService-
|
|
11115
|
+
"id": "injectable-I18nService-2ebba83f2a934dc788aa9e117b7bda050be69e26ecbdbdda1d9e6e9a378e46e78a069988f2e5db079668ca60e83b9a1ee5e67b4c9d146ffba19f3bc5de4783c7",
|
|
11208
11116
|
"file": "packages/core/src/lib/services/i18n/i18n.service.ts",
|
|
11209
11117
|
"coverageIgnore": false,
|
|
11210
11118
|
"properties": [
|
|
@@ -11218,7 +11126,7 @@
|
|
|
11218
11126
|
"indexKey": "",
|
|
11219
11127
|
"optional": false,
|
|
11220
11128
|
"description": "",
|
|
11221
|
-
"line":
|
|
11129
|
+
"line": 56,
|
|
11222
11130
|
"rawdescription": "\n",
|
|
11223
11131
|
"modifierKind": [
|
|
11224
11132
|
124
|
|
@@ -11249,7 +11157,7 @@
|
|
|
11249
11157
|
"indexKey": "",
|
|
11250
11158
|
"optional": false,
|
|
11251
11159
|
"description": "",
|
|
11252
|
-
"line":
|
|
11160
|
+
"line": 58,
|
|
11253
11161
|
"rawdescription": "\n",
|
|
11254
11162
|
"modifierKind": [
|
|
11255
11163
|
124
|
|
@@ -11280,7 +11188,7 @@
|
|
|
11280
11188
|
"indexKey": "",
|
|
11281
11189
|
"optional": false,
|
|
11282
11190
|
"description": "",
|
|
11283
|
-
"line":
|
|
11191
|
+
"line": 60,
|
|
11284
11192
|
"rawdescription": "\n",
|
|
11285
11193
|
"modifierKind": [
|
|
11286
11194
|
124
|
|
@@ -11296,7 +11204,7 @@
|
|
|
11296
11204
|
"indexKey": "",
|
|
11297
11205
|
"optional": false,
|
|
11298
11206
|
"description": "",
|
|
11299
|
-
"line":
|
|
11207
|
+
"line": 57,
|
|
11300
11208
|
"rawdescription": "\n",
|
|
11301
11209
|
"modifierKind": [
|
|
11302
11210
|
124
|
|
@@ -11339,8 +11247,8 @@
|
|
|
11339
11247
|
"jsdoctags": [
|
|
11340
11248
|
{
|
|
11341
11249
|
"name": {
|
|
11342
|
-
"pos":
|
|
11343
|
-
"end":
|
|
11250
|
+
"pos": 8150,
|
|
11251
|
+
"end": 8156,
|
|
11344
11252
|
"kind": 80,
|
|
11345
11253
|
"id": 0,
|
|
11346
11254
|
"flags": 16842752,
|
|
@@ -11353,8 +11261,8 @@
|
|
|
11353
11261
|
"deprecated": false,
|
|
11354
11262
|
"deprecationMessage": "",
|
|
11355
11263
|
"tagName": {
|
|
11356
|
-
"pos":
|
|
11357
|
-
"end":
|
|
11264
|
+
"pos": 8144,
|
|
11265
|
+
"end": 8149,
|
|
11358
11266
|
"kind": 80,
|
|
11359
11267
|
"id": 0,
|
|
11360
11268
|
"flags": 16842752,
|
|
@@ -11365,8 +11273,8 @@
|
|
|
11365
11273
|
},
|
|
11366
11274
|
{
|
|
11367
11275
|
"name": {
|
|
11368
|
-
"pos":
|
|
11369
|
-
"end":
|
|
11276
|
+
"pos": 8188,
|
|
11277
|
+
"end": 8198,
|
|
11370
11278
|
"kind": 80,
|
|
11371
11279
|
"id": 0,
|
|
11372
11280
|
"flags": 16842752,
|
|
@@ -11379,8 +11287,8 @@
|
|
|
11379
11287
|
"deprecated": false,
|
|
11380
11288
|
"deprecationMessage": "",
|
|
11381
11289
|
"tagName": {
|
|
11382
|
-
"pos":
|
|
11383
|
-
"end":
|
|
11290
|
+
"pos": 8182,
|
|
11291
|
+
"end": 8187,
|
|
11384
11292
|
"kind": 80,
|
|
11385
11293
|
"id": 0,
|
|
11386
11294
|
"flags": 16842752,
|
|
@@ -11391,8 +11299,8 @@
|
|
|
11391
11299
|
},
|
|
11392
11300
|
{
|
|
11393
11301
|
"tagName": {
|
|
11394
|
-
"pos":
|
|
11395
|
-
"end":
|
|
11302
|
+
"pos": 8207,
|
|
11303
|
+
"end": 8213,
|
|
11396
11304
|
"kind": 80,
|
|
11397
11305
|
"id": 0,
|
|
11398
11306
|
"flags": 16842752,
|
|
@@ -11465,8 +11373,8 @@
|
|
|
11465
11373
|
"jsdoctags": [
|
|
11466
11374
|
{
|
|
11467
11375
|
"name": {
|
|
11468
|
-
"pos":
|
|
11469
|
-
"end":
|
|
11376
|
+
"pos": 3562,
|
|
11377
|
+
"end": 3567,
|
|
11470
11378
|
"kind": 80,
|
|
11471
11379
|
"id": 0,
|
|
11472
11380
|
"flags": 16842752,
|
|
@@ -11489,8 +11397,8 @@
|
|
|
11489
11397
|
}
|
|
11490
11398
|
],
|
|
11491
11399
|
"tagName": {
|
|
11492
|
-
"pos":
|
|
11493
|
-
"end":
|
|
11400
|
+
"pos": 3556,
|
|
11401
|
+
"end": 3561,
|
|
11494
11402
|
"kind": 80,
|
|
11495
11403
|
"id": 0,
|
|
11496
11404
|
"flags": 16842752,
|
|
@@ -11739,8 +11647,8 @@
|
|
|
11739
11647
|
"jsdoctags": [
|
|
11740
11648
|
{
|
|
11741
11649
|
"name": {
|
|
11742
|
-
"pos":
|
|
11743
|
-
"end":
|
|
11650
|
+
"pos": 6767,
|
|
11651
|
+
"end": 6777,
|
|
11744
11652
|
"kind": 80,
|
|
11745
11653
|
"id": 0,
|
|
11746
11654
|
"flags": 16842752,
|
|
@@ -11753,8 +11661,8 @@
|
|
|
11753
11661
|
"deprecated": false,
|
|
11754
11662
|
"deprecationMessage": "",
|
|
11755
11663
|
"tagName": {
|
|
11756
|
-
"pos":
|
|
11757
|
-
"end":
|
|
11664
|
+
"pos": 6761,
|
|
11665
|
+
"end": 6766,
|
|
11758
11666
|
"kind": 80,
|
|
11759
11667
|
"id": 0,
|
|
11760
11668
|
"flags": 16842752,
|
|
@@ -11850,8 +11758,8 @@
|
|
|
11850
11758
|
"jsdoctags": [
|
|
11851
11759
|
{
|
|
11852
11760
|
"name": {
|
|
11853
|
-
"pos":
|
|
11854
|
-
"end":
|
|
11761
|
+
"pos": 5187,
|
|
11762
|
+
"end": 5192,
|
|
11855
11763
|
"kind": 80,
|
|
11856
11764
|
"id": 0,
|
|
11857
11765
|
"flags": 16842752,
|
|
@@ -11864,8 +11772,8 @@
|
|
|
11864
11772
|
"deprecated": false,
|
|
11865
11773
|
"deprecationMessage": "",
|
|
11866
11774
|
"tagName": {
|
|
11867
|
-
"pos":
|
|
11868
|
-
"end":
|
|
11775
|
+
"pos": 5181,
|
|
11776
|
+
"end": 5186,
|
|
11869
11777
|
"kind": 80,
|
|
11870
11778
|
"id": 0,
|
|
11871
11779
|
"flags": 16842752,
|
|
@@ -11876,8 +11784,8 @@
|
|
|
11876
11784
|
},
|
|
11877
11785
|
{
|
|
11878
11786
|
"name": {
|
|
11879
|
-
"pos":
|
|
11880
|
-
"end":
|
|
11787
|
+
"pos": 5207,
|
|
11788
|
+
"end": 5214,
|
|
11881
11789
|
"kind": 80,
|
|
11882
11790
|
"id": 0,
|
|
11883
11791
|
"flags": 16842752,
|
|
@@ -11908,8 +11816,8 @@
|
|
|
11908
11816
|
}
|
|
11909
11817
|
],
|
|
11910
11818
|
"tagName": {
|
|
11911
|
-
"pos":
|
|
11912
|
-
"end":
|
|
11819
|
+
"pos": 5201,
|
|
11820
|
+
"end": 5206,
|
|
11913
11821
|
"kind": 80,
|
|
11914
11822
|
"id": 0,
|
|
11915
11823
|
"flags": 16842752,
|
|
@@ -12017,7 +11925,7 @@
|
|
|
12017
11925
|
"deprecationMessage": "",
|
|
12018
11926
|
"description": "",
|
|
12019
11927
|
"rawdescription": "\n",
|
|
12020
|
-
"sourceCode": "import { DOCUMENT } from '@angular/common';\nimport { Injectable, OnDestroy, Signal, inject } from '@angular/core';\nimport { LangChangeEvent, TranslateLoader, TranslateService } from '@ngx-translate/core';\nimport { BehaviorSubject, forkJoin, Observable, of, Subject } from 'rxjs';\nimport {\n catchError,\n filter,\n map,\n take,\n tap,\n switchMap,\n takeUntil,\n distinctUntilChanged,\n} from 'rxjs/operators';\nimport {\n GlobalConfig,\n EuiLazyService,\n EuiServiceStatus,\n getI18nServiceConfigFromBase,\n I18nLoaderConfig,\n I18nServiceConfig,\n I18nState,\n ModuleConfig,\n getBrowserDefaultLanguage,\n EuiEuLanguages,\n CoreState,\n DeepPartial,\n} from '@eui/base';\n\nimport { I18nLoader, LoadedResources } from './i18n.loader';\nimport { GLOBAL_CONFIG_TOKEN } from '../config/tokens';\nimport { LogService } from '../log';\nimport { StoreService } from '../store';\nimport { DEFAULT_I18N_SERVICE_CONFIG } from '../config/defaults';\nimport { isEqual } from 'lodash-es';\nimport { Selector } from 'reselect';\nimport { toSignal } from '@angular/core/rxjs-interop';\n\nexport interface ModuleLoadEvent {\n ready: boolean;\n name: string | null | undefined;\n // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n error?: any;\n}\n\nconst getLastAddedModule: Selector<CoreState, string> = (state: CoreState) => state.app?.loadedConfigModules?.lastAddedModule as string;\n\n@Injectable({\n providedIn: 'root',\n})\nexport class I18nService<T extends I18nState = I18nState> extends EuiLazyService<T | I18nState> implements OnDestroy {\n protected config: I18nServiceConfig;\n protected onModuleLoad: BehaviorSubject<ModuleLoadEvent>;\n protected baseGlobalConfig = inject<GlobalConfig>(GLOBAL_CONFIG_TOKEN);\n protected translateService = inject(TranslateService);\n protected logService = inject(LogService, { optional: true });\n private translateLoader = inject(TranslateLoader);\n protected store = inject<StoreService<T>>(StoreService);\n private static readonly DEFAULT_STATE: I18nState = { activeLang: 'en' };\n private document = inject<Document>(DOCUMENT);\n /**\n * a single signal holding the state - initial state is null\n */\n private state: Signal<T>;\n /**\n * a BehaviorSubject holding the state - initial state is null\n * This is the main source of truth for the state\n */\n private stateSubject: BehaviorSubject<T>;\n private subNotifier: Subject<void> = new Subject();\n\n constructor() {\n super(I18nService.DEFAULT_STATE as T);\n // Create a BehaviorSubject with the initial state\n this.stateSubject = new BehaviorSubject<T>(this.stateInstance as T);\n\n // Initialize signal with base state\n this.state = toSignal(this.stateSubject, { equal: isEqual, requireSync: true });\n\n // Subscribe to base class state changes\n this.onStateChange.subscribe((newState) => {\n // const clonedState = structuredClone(newState as T);\n this.stateSubject.next(newState as T);\n });\n\n this.config = getI18nServiceConfigFromBase(this.baseGlobalConfig);\n this.onModuleLoad = new BehaviorSubject<ModuleLoadEvent>({ ready: false, name: null });\n }\n\n ngOnDestroy(): void {\n this.subNotifier.next(void 0);\n this.subNotifier.complete();\n }\n\n getState(): Observable<T>;\n /**\n * @deprecated this will be removed in a future version\n * @param mapFn\n */\n getState<K = T>(mapFn?: (state: T) => K): Observable<K>;\n getState<a extends keyof DeepPartial<T>>(key?: a): Observable<DeepPartial<a>>;\n getState<K = T>(keyOrMapFn?: ((state: T) => K) | string): Observable<DeepPartial<K>> {\n if (!keyOrMapFn) {\n return this.stateSubject.asObservable().pipe(\n takeUntil(this.subNotifier),\n distinctUntilChanged((x, y) => isEqual(x, y)),\n ) as Observable<DeepPartial<K>>;\n }\n\n if (typeof keyOrMapFn === 'function') {\n return this.stateSubject.asObservable().pipe(\n takeUntil(this.subNotifier),\n map(state => keyOrMapFn(state)),\n distinctUntilChanged((x, y) => isEqual(x, y)),\n );\n }\n\n return this.stateSubject.asObservable().pipe(\n takeUntil(this.subNotifier),\n map(state => {\n const keys = (keyOrMapFn as string).split('.');\n\n // Traverse the object based on the dot notation\n return keys.reduce<unknown>((acc, currKey) => {\n const record = acc as Record<string, unknown> | null | undefined;\n return record && record[currKey] !== undefined ? record[currKey] : undefined;\n }, state);\n }),\n distinctUntilChanged((x, y) => isEqual(x, y)),\n ) as unknown as Observable<DeepPartial<K>>;\n }\n\n updateState(state: DeepPartial<T>): void;\n /**\n * @deprecated it will be removed in next version. Use updateState(partialState: DeepPartial<T>) instead\n * @param slice\n * @param reducer\n */\n updateState(slice: DeepPartial<T>, reducer: (state: T, action: DeepPartial<T>) => T): void;\n updateState<K extends T>(state: DeepPartial<K>, reducer?: (state: T, action: DeepPartial<K>) => T): void {\n if(state.activeLang) {\n this.updateHTMLDOMLang(state.activeLang as string);\n }\n this.stateInstance = super.deepMerge(this.stateInstance as T, { ...state });\n // Emit state change\n this.onStateChange.next(this.stateInstance);\n }\n\n /**\n * This method is used to get the state as readonly signal.\n */\n getSignal(): Signal<T> {\n return this.state;\n }\n\n init(langState?: T): Observable<EuiServiceStatus> {\n const initLang = langState && langState.activeLang ? langState.activeLang : this.preparedDefaultLanguage();\n const initState = {\n ...langState,\n activeLang: initLang,\n };\n if (typeof initLang === 'string') {\n super.initEuiService(this.store);\n this.updateState(initState as DeepPartial<T>);\n return this.setup(initLang);\n }\n return of({ success: false, error: 'Initial active lang should be string' });\n }\n\n /**\n * A pipe function that could serve as a wrapper of another observable\n * e.g. ngx-translate i18n.onReady('my_module').pipe(switchMap(()=>translate.get('eui.KEY')));\n * WARNING: onReady will emit only once for a loaded Module, going to another and then going back will not result\n * into another emission.\n *\n * @param moduleName the name of the module that has been given through the eUI globalConfig. In case non provided\n * fetch module name from the state.\n */\n onReady(moduleName?: string): Observable<ModuleLoadEvent> {\n return this.onModuleLoad.pipe(\n switchMap((evt: ModuleLoadEvent) =>\n moduleName\n ? of(evt)\n : this.store.select(getLastAddedModule).pipe(\n tap((m) => (moduleName = m)),\n map(() => evt),\n ),\n ),\n // emit only if event emitted matches the module name and is ready\n filter((evt: ModuleLoadEvent) => evt.ready === true && evt.name === moduleName),\n // make sure that observable completes\n take(1),\n );\n }\n\n public lazyLoad(config: I18nLoaderConfig): Observable<EuiServiceStatus> {\n const moduleId = Math.floor(Math.random() * 100000 + 1).toLocaleString();\n return this.addResources(config, moduleId);\n }\n\n lazyLoadInit(moduleConfig: ModuleConfig, moduleName?: string): Observable<EuiServiceStatus> {\n const i18nLoaderConfig = moduleConfig as I18nLoaderConfig;\n // add resources\n return this.addResources(i18nLoaderConfig, moduleName);\n }\n\n /**\n * Add resources based of a config loader\n *\n * @param config I18nLoaderConfig\n * @param moduleName\n * @return Promise<EuiServiceStatus> an EuiServiceStatus when translation has fully loaded\n */\n public addResources(config: I18nLoaderConfig, moduleName?: string): Observable<EuiServiceStatus> {\n // emit that module is loading\n this.onModuleLoad.next({ ready: false, name: moduleName });\n\n const loader = this.translateLoader;\n if (loader instanceof I18nLoader) {\n // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const langSubscription: Observable<any>[] = [];\n const i18nLoader = <I18nLoader>loader;\n\n // add the resources to the loader\n const resources = i18nLoader.addResources(config);\n\n // manually load the resources for the CURRENT language and add them to the translate service\n langSubscription.push(\n i18nLoader.loadResources(resources, this.translateService.currentLang() as string).pipe(\n take(1),\n tap((loadedResources: LoadedResources) => {\n // add the new set of translations to the current language\n this.translateService.setTranslation(this.translateService.currentLang() as string, loadedResources.translations, true);\n }),\n ),\n );\n\n // if the current language is different from the DEFAULT language\n const defaultLang = (this.config.defaultLanguage || this.translateService.fallbackLang()) as string;\n if (this.translateService.currentLang() !== defaultLang) {\n // manually load the resources for the default language and add them to the translation service\n langSubscription.push(\n i18nLoader.loadResources(resources, defaultLang).pipe(\n take(1),\n tap((loadedResources: LoadedResources) => {\n this.translateService.setTranslation(defaultLang, loadedResources.translations, true);\n }),\n ),\n );\n }\n\n return forkJoin(langSubscription).pipe(\n map((loadedResourcesArr: LoadedResources[]) =>\n !loadedResourcesArr[0].hasError ? { success: true } : { success: false, error: loadedResourcesArr[0].errors },\n ),\n tap(() => {\n // emit status of module loading progress\n this.onModuleLoad.next({ ready: true, name: moduleName });\n }),\n catchError((error) => {\n // emit status of module loading progress\n this.onModuleLoad.next({ ready: true, name: moduleName, error });\n return of({ success: false, error });\n }),\n );\n } else {\n return of({ success: false, error: 'currentLoader is not an I18nLoader.' });\n }\n }\n\n /**\n * Prepares the default language\n */\n private preparedDefaultLanguage(): string {\n const browserPref = getBrowserDefaultLanguage();\n // If user has browser preferred lang, and that language is part of the languages array\n if (browserPref && this.config.languages && EuiEuLanguages.getLanguageCodes(this.config.languages).includes(browserPref)) {\n return browserPref;\n }\n return this.config.defaultLanguage as string;\n }\n\n /**\n * @param initLanguage if given default language to override default language coming from the\n * configuration token.\n */\n private setup(initLanguage: string): Observable<EuiServiceStatus> {\n // use the default config as a reference base\n this.config = Object.assign({}, DEFAULT_I18N_SERVICE_CONFIG, this.config);\n // configure the translation config service\n if (this.config.languages) {\n this.translateService.addLangs(EuiEuLanguages.getLanguageCodes(this.config.languages));\n if (this.logService) {\n this.logService.info(`I18n accepted languages set to ${EuiEuLanguages.getLanguageCodes(this.config.languages)}`);\n }\n }\n // set the current language, causing to load translations\n return this.translateService.use(initLanguage).pipe(\n tap(() => {\n this.bindActiveLangStateToTranslateService();\n this.bindTranslateServiceLangChangeToState();\n if (this.config.defaultLanguage) {\n this.setDefaultLanguage(this.config.defaultLanguage);\n }\n }),\n map(() => {\n if (this.translateLoader instanceof I18nLoader) {\n const failedResources = this.translateLoader.getFailedResources();\n if (failedResources.length > 0) {\n return { success: false, error: failedResources };\n }\n }\n return { success: true };\n }),\n catchError((error) => of({ success: false, error })),\n );\n }\n\n private bindActiveLangStateToTranslateService(): void {\n this.getState((s) => s.activeLang)\n .pipe(takeUntil(this.subNotifier))\n .subscribe((lang) => {\n if (lang !== null && this.translateService.currentLang() !== lang) {\n this.use(lang);\n }\n });\n }\n\n private bindTranslateServiceLangChangeToState(): void {\n this.translateService.onLangChange.subscribe((event: LangChangeEvent) => {\n if (this.stateInstance.activeLang !== event.lang) {\n this.updateState({ activeLang: event.lang } as Partial<T>);\n }\n if (this.logService) {\n this.logService.info(`I18n current language set to ${event.lang}`);\n }\n });\n }\n\n private setDefaultLanguage(defaultLanguage: string): void {\n // removed, current language is already calculated in init, setup function fill use it directly, not default\n // this.translateService.currentLang = default_language || this.config.defaultLanguage;\n this.translateService.setFallbackLang(defaultLanguage);\n if (this.logService) {\n this.logService.info(`I18n default language set to ${defaultLanguage}`);\n }\n }\n\n /**\n * change the currently used language\n *\n * @param lang is the language code based on the convention you used e.g. (en or en-EN)\n * @returns Observable that returns an object contain the object translation for given language after language\n * fully loaded.\n */\n // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private use(lang: string): Observable<any> {\n return this.translateService.use(lang);\n }\n\n /**\n * updates the HTML element lang attribute\n *\n * @private\n */\n private updateHTMLDOMLang(lang: string): void {\n this.document.documentElement.lang = lang;\n }\n}\n",
|
|
11928
|
+
"sourceCode": "import { DOCUMENT } from '@angular/common';\nimport { Injectable, OnDestroy, Signal, inject } from '@angular/core';\nimport { LangChangeEvent, TranslateLoader, TranslateService } from '@ngx-translate/core';\nimport { BehaviorSubject, forkJoin, Observable, of, Subject } from 'rxjs';\nimport {\n catchError,\n filter,\n map,\n take,\n tap,\n switchMap,\n takeUntil,\n distinctUntilChanged,\n} from 'rxjs/operators';\nimport {\n GlobalConfig,\n EuiLazyService,\n EuiServiceStatus,\n getI18nServiceConfigFromBase,\n I18nLoaderConfig,\n I18nServiceConfig,\n I18nState,\n ModuleConfig,\n getBrowserDefaultLanguage,\n EuiEuLanguages,\n CoreState,\n DeepPartial,\n} from '@eui/base';\n\nimport { I18nLoader, LoadedResources } from './i18n.loader';\nimport { GLOBAL_CONFIG_TOKEN } from '../config/tokens';\nimport { LogService } from '../log';\nimport { StoreService } from '../store';\nimport { DEFAULT_I18N_SERVICE_CONFIG } from '../config/defaults';\nimport { isEqual } from 'lodash-es';\nimport { Selector } from 'reselect';\nimport { toSignal } from '@angular/core/rxjs-interop';\n\nexport interface ModuleLoadEvent {\n ready: boolean;\n name: string | null | undefined;\n // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n error?: any;\n}\n\nconst getLastAddedModule: Selector<CoreState, string> = (state: CoreState) => state.app?.loadedConfigModules?.lastAddedModule as string;\n\n@Injectable({\n providedIn: 'root',\n})\nexport class I18nService<T extends I18nState = I18nState> extends EuiLazyService<T | I18nState> implements OnDestroy {\n protected config: I18nServiceConfig;\n protected onModuleLoad: BehaviorSubject<ModuleLoadEvent>;\n private static readonly DEFAULT_STATE: I18nState = { activeLang: 'en' };\n protected baseGlobalConfig = inject<GlobalConfig>(GLOBAL_CONFIG_TOKEN);\n protected translateService = inject(TranslateService);\n protected logService = inject(LogService, { optional: true });\n private translateLoader = inject(TranslateLoader);\n protected store = inject<StoreService<T>>(StoreService);\n private document = inject<Document>(DOCUMENT);\n /**\n * a single signal holding the state - initial state is null\n */\n private state: Signal<T>;\n /**\n * a BehaviorSubject holding the state - initial state is null\n * This is the main source of truth for the state\n */\n private stateSubject: BehaviorSubject<T>;\n private subNotifier = new Subject<void>();\n\n constructor() {\n super(I18nService.DEFAULT_STATE as T);\n // Create a BehaviorSubject with the initial state\n this.stateSubject = new BehaviorSubject<T>(this.stateInstance as T);\n\n // Initialize signal with base state\n this.state = toSignal(this.stateSubject, { equal: isEqual, requireSync: true });\n\n // Subscribe to base class state changes\n this.onStateChange.subscribe((newState) => {\n // const clonedState = structuredClone(newState as T);\n this.stateSubject.next(newState as T);\n });\n\n this.config = getI18nServiceConfigFromBase(this.baseGlobalConfig);\n this.onModuleLoad = new BehaviorSubject<ModuleLoadEvent>({ ready: false, name: null });\n }\n\n ngOnDestroy(): void {\n this.subNotifier.next(void 0);\n this.subNotifier.complete();\n }\n\n getState(): Observable<T>;\n /**\n * @deprecated this will be removed in a future version\n * @param mapFn\n */\n getState<K = T>(mapFn?: (state: T) => K): Observable<K>;\n getState<a extends keyof DeepPartial<T>>(key?: a): Observable<DeepPartial<a>>;\n getState<K = T>(keyOrMapFn?: ((state: T) => K) | string): Observable<DeepPartial<K>> {\n if (!keyOrMapFn) {\n return this.stateSubject.asObservable().pipe(\n takeUntil(this.subNotifier),\n distinctUntilChanged((x, y) => isEqual(x, y)),\n ) as Observable<DeepPartial<K>>;\n }\n\n if (typeof keyOrMapFn === 'function') {\n return this.stateSubject.asObservable().pipe(\n takeUntil(this.subNotifier),\n map(state => keyOrMapFn(state)),\n distinctUntilChanged((x, y) => isEqual(x, y)),\n );\n }\n\n return this.stateSubject.asObservable().pipe(\n takeUntil(this.subNotifier),\n map(state => {\n const keys = (keyOrMapFn as string).split('.');\n\n // Traverse the object based on the dot notation\n return keys.reduce<unknown>((acc, currKey) => {\n const record = acc as Record<string, unknown> | null | undefined;\n return record && record[currKey] !== undefined ? record[currKey] : undefined;\n }, state);\n }),\n distinctUntilChanged((x, y) => isEqual(x, y)),\n ) as unknown as Observable<DeepPartial<K>>;\n }\n\n updateState(state: DeepPartial<T>): void;\n /**\n * @deprecated it will be removed in next version. Use updateState(partialState: DeepPartial<T>) instead\n * @param slice\n * @param reducer\n */\n updateState(slice: DeepPartial<T>, reducer: (state: T, action: DeepPartial<T>) => T): void;\n updateState<K extends T>(state: DeepPartial<K>, reducer?: (state: T, action: DeepPartial<K>) => T): void {\n if(state.activeLang) {\n this.updateHTMLDOMLang(state.activeLang as string);\n }\n this.stateInstance = super.deepMerge(this.stateInstance as T, { ...state });\n // Emit state change\n this.onStateChange.next(this.stateInstance);\n }\n\n /**\n * This method is used to get the state as readonly signal.\n */\n getSignal(): Signal<T> {\n return this.state;\n }\n\n init(langState?: T): Observable<EuiServiceStatus> {\n const initLang = langState && langState.activeLang ? langState.activeLang : this.preparedDefaultLanguage();\n const initState = {\n ...langState,\n activeLang: initLang,\n };\n if (typeof initLang === 'string') {\n super.initEuiService(this.store);\n this.updateState(initState as DeepPartial<T>);\n return this.setup(initLang);\n }\n return of({ success: false, error: 'Initial active lang should be string' });\n }\n\n /**\n * A pipe function that could serve as a wrapper of another observable\n * e.g. ngx-translate i18n.onReady('my_module').pipe(switchMap(()=>translate.get('eui.KEY')));\n * WARNING: onReady will emit only once for a loaded Module, going to another and then going back will not result\n * into another emission.\n *\n * @param moduleName the name of the module that has been given through the eUI globalConfig. In case non provided\n * fetch module name from the state.\n */\n onReady(moduleName?: string): Observable<ModuleLoadEvent> {\n return this.onModuleLoad.pipe(\n switchMap((evt: ModuleLoadEvent) =>\n moduleName\n ? of(evt)\n : this.store.select(getLastAddedModule).pipe(\n tap((m) => (moduleName = m)),\n map(() => evt),\n ),\n ),\n // emit only if event emitted matches the module name and is ready\n filter((evt: ModuleLoadEvent) => evt.ready === true && evt.name === moduleName),\n // make sure that observable completes\n take(1),\n );\n }\n\n public lazyLoad(config: I18nLoaderConfig): Observable<EuiServiceStatus> {\n const moduleId = Math.floor(Math.random() * 100000 + 1).toLocaleString();\n return this.addResources(config, moduleId);\n }\n\n lazyLoadInit(moduleConfig: ModuleConfig, moduleName?: string): Observable<EuiServiceStatus> {\n const i18nLoaderConfig = moduleConfig as I18nLoaderConfig;\n // add resources\n return this.addResources(i18nLoaderConfig, moduleName);\n }\n\n /**\n * Add resources based of a config loader\n *\n * @param config I18nLoaderConfig\n * @param moduleName\n * @return Promise<EuiServiceStatus> an EuiServiceStatus when translation has fully loaded\n */\n public addResources(config: I18nLoaderConfig, moduleName?: string): Observable<EuiServiceStatus> {\n // emit that module is loading\n this.onModuleLoad.next({ ready: false, name: moduleName });\n\n const loader = this.translateLoader;\n if (loader instanceof I18nLoader) {\n // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const langSubscription: Observable<any>[] = [];\n const i18nLoader = loader as I18nLoader;\n\n // add the resources to the loader\n const resources = i18nLoader.addResources(config);\n\n // manually load the resources for the CURRENT language and add them to the translate service\n langSubscription.push(\n i18nLoader.loadResources(resources, this.translateService.currentLang() as string).pipe(\n take(1),\n tap((loadedResources: LoadedResources) => {\n // add the new set of translations to the current language\n this.translateService.setTranslation(this.translateService.currentLang() as string, loadedResources.translations, true);\n }),\n ),\n );\n\n // if the current language is different from the DEFAULT language\n const defaultLang = (this.config.defaultLanguage || this.translateService.fallbackLang()) as string;\n if (this.translateService.currentLang() !== defaultLang) {\n // manually load the resources for the default language and add them to the translation service\n langSubscription.push(\n i18nLoader.loadResources(resources, defaultLang).pipe(\n take(1),\n tap((loadedResources: LoadedResources) => {\n this.translateService.setTranslation(defaultLang, loadedResources.translations, true);\n }),\n ),\n );\n }\n\n return forkJoin(langSubscription).pipe(\n map((loadedResourcesArr: LoadedResources[]) =>\n !loadedResourcesArr[0].hasError ? { success: true } : { success: false, error: loadedResourcesArr[0].errors },\n ),\n tap(() => {\n // emit status of module loading progress\n this.onModuleLoad.next({ ready: true, name: moduleName });\n }),\n catchError((error) => {\n // emit status of module loading progress\n this.onModuleLoad.next({ ready: true, name: moduleName, error });\n return of({ success: false, error });\n }),\n );\n } else {\n return of({ success: false, error: 'currentLoader is not an I18nLoader.' });\n }\n }\n\n /**\n * Prepares the default language\n */\n private preparedDefaultLanguage(): string {\n const browserPref = getBrowserDefaultLanguage();\n // If user has browser preferred lang, and that language is part of the languages array\n if (browserPref && this.config.languages && EuiEuLanguages.getLanguageCodes(this.config.languages).includes(browserPref)) {\n return browserPref;\n }\n return this.config.defaultLanguage as string;\n }\n\n /**\n * @param initLanguage if given default language to override default language coming from the\n * configuration token.\n */\n private setup(initLanguage: string): Observable<EuiServiceStatus> {\n // use the default config as a reference base\n this.config = Object.assign({}, DEFAULT_I18N_SERVICE_CONFIG, this.config);\n // configure the translation config service\n if (this.config.languages) {\n this.translateService.addLangs(EuiEuLanguages.getLanguageCodes(this.config.languages));\n if (this.logService) {\n this.logService.info(`I18n accepted languages set to ${EuiEuLanguages.getLanguageCodes(this.config.languages)}`);\n }\n }\n // set the current language, causing to load translations\n return this.translateService.use(initLanguage).pipe(\n tap(() => {\n this.bindActiveLangStateToTranslateService();\n this.bindTranslateServiceLangChangeToState();\n if (this.config.defaultLanguage) {\n this.setDefaultLanguage(this.config.defaultLanguage);\n }\n }),\n map(() => {\n if (this.translateLoader instanceof I18nLoader) {\n const failedResources = this.translateLoader.getFailedResources();\n if (failedResources.length > 0) {\n return { success: false, error: failedResources };\n }\n }\n return { success: true };\n }),\n catchError((error) => of({ success: false, error })),\n );\n }\n\n private bindActiveLangStateToTranslateService(): void {\n this.getState((s) => s.activeLang)\n .pipe(takeUntil(this.subNotifier))\n .subscribe((lang) => {\n if (lang !== null && this.translateService.currentLang() !== lang) {\n this.use(lang);\n }\n });\n }\n\n private bindTranslateServiceLangChangeToState(): void {\n this.translateService.onLangChange.subscribe((event: LangChangeEvent) => {\n if (this.stateInstance.activeLang !== event.lang) {\n this.updateState({ activeLang: event.lang } as Partial<T>);\n }\n if (this.logService) {\n this.logService.info(`I18n current language set to ${event.lang}`);\n }\n });\n }\n\n private setDefaultLanguage(defaultLanguage: string): void {\n // removed, current language is already calculated in init, setup function fill use it directly, not default\n // this.translateService.currentLang = default_language || this.config.defaultLanguage;\n this.translateService.setFallbackLang(defaultLanguage);\n if (this.logService) {\n this.logService.info(`I18n default language set to ${defaultLanguage}`);\n }\n }\n\n /**\n * change the currently used language\n *\n * @param lang is the language code based on the convention you used e.g. (en or en-EN)\n * @returns Observable that returns an object contain the object translation for given language after language\n * fully loaded.\n */\n // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private use(lang: string): Observable<any> {\n return this.translateService.use(lang);\n }\n\n /**\n * updates the HTML element lang attribute\n *\n * @private\n */\n private updateHTMLDOMLang(lang: string): void {\n this.document.documentElement.lang = lang;\n }\n}\n",
|
|
12021
11929
|
"constructorObj": {
|
|
12022
11930
|
"name": "constructor",
|
|
12023
11931
|
"description": "",
|
|
@@ -12063,7 +11971,7 @@
|
|
|
12063
11971
|
"indexKey": "",
|
|
12064
11972
|
"optional": false,
|
|
12065
11973
|
"description": "",
|
|
12066
|
-
"line":
|
|
11974
|
+
"line": 56,
|
|
12067
11975
|
"rawdescription": "\n",
|
|
12068
11976
|
"modifierKind": [
|
|
12069
11977
|
124
|
|
@@ -12100,7 +12008,7 @@
|
|
|
12100
12008
|
"indexKey": "",
|
|
12101
12009
|
"optional": false,
|
|
12102
12010
|
"description": "",
|
|
12103
|
-
"line":
|
|
12011
|
+
"line": 58,
|
|
12104
12012
|
"rawdescription": "\n",
|
|
12105
12013
|
"modifierKind": [
|
|
12106
12014
|
124
|
|
@@ -12137,7 +12045,7 @@
|
|
|
12137
12045
|
"indexKey": "",
|
|
12138
12046
|
"optional": false,
|
|
12139
12047
|
"description": "",
|
|
12140
|
-
"line":
|
|
12048
|
+
"line": 60,
|
|
12141
12049
|
"rawdescription": "\n",
|
|
12142
12050
|
"modifierKind": [
|
|
12143
12051
|
124
|
|
@@ -12156,7 +12064,7 @@
|
|
|
12156
12064
|
"indexKey": "",
|
|
12157
12065
|
"optional": false,
|
|
12158
12066
|
"description": "",
|
|
12159
|
-
"line":
|
|
12067
|
+
"line": 57,
|
|
12160
12068
|
"rawdescription": "\n",
|
|
12161
12069
|
"modifierKind": [
|
|
12162
12070
|
124
|
|
@@ -12403,8 +12311,8 @@
|
|
|
12403
12311
|
"jsdoctags": [
|
|
12404
12312
|
{
|
|
12405
12313
|
"name": {
|
|
12406
|
-
"pos":
|
|
12407
|
-
"end":
|
|
12314
|
+
"pos": 6767,
|
|
12315
|
+
"end": 6777,
|
|
12408
12316
|
"kind": 80,
|
|
12409
12317
|
"id": 0,
|
|
12410
12318
|
"flags": 16842752,
|
|
@@ -12417,8 +12325,8 @@
|
|
|
12417
12325
|
"deprecated": false,
|
|
12418
12326
|
"deprecationMessage": "",
|
|
12419
12327
|
"tagName": {
|
|
12420
|
-
"pos":
|
|
12421
|
-
"end":
|
|
12328
|
+
"pos": 6761,
|
|
12329
|
+
"end": 6766,
|
|
12422
12330
|
"kind": 80,
|
|
12423
12331
|
"id": 0,
|
|
12424
12332
|
"flags": 16842752,
|
|
@@ -12487,7 +12395,7 @@
|
|
|
12487
12395
|
},
|
|
12488
12396
|
{
|
|
12489
12397
|
"name": "LocaleService",
|
|
12490
|
-
"id": "injectable-LocaleService-
|
|
12398
|
+
"id": "injectable-LocaleService-b27f810c078879367d41a6d430bfe29e8e7ef7c00f5c690a3e0307603f8630ac89d7ff89f20a2e9e368946c75df7c732385dda79239b2676686b604ca9a14a34",
|
|
12491
12399
|
"file": "packages/core/src/lib/services/locale/locale.service.ts",
|
|
12492
12400
|
"coverageIgnore": false,
|
|
12493
12401
|
"properties": [
|
|
@@ -12617,8 +12525,8 @@
|
|
|
12617
12525
|
"jsdoctags": [
|
|
12618
12526
|
{
|
|
12619
12527
|
"name": {
|
|
12620
|
-
"pos":
|
|
12621
|
-
"end":
|
|
12528
|
+
"pos": 4265,
|
|
12529
|
+
"end": 4270,
|
|
12622
12530
|
"kind": 80,
|
|
12623
12531
|
"id": 0,
|
|
12624
12532
|
"flags": 16842752,
|
|
@@ -12641,8 +12549,8 @@
|
|
|
12641
12549
|
}
|
|
12642
12550
|
],
|
|
12643
12551
|
"tagName": {
|
|
12644
|
-
"pos":
|
|
12645
|
-
"end":
|
|
12552
|
+
"pos": 4238,
|
|
12553
|
+
"end": 4243,
|
|
12646
12554
|
"kind": 80,
|
|
12647
12555
|
"id": 0,
|
|
12648
12556
|
"flags": 16842752,
|
|
@@ -12651,24 +12559,24 @@
|
|
|
12651
12559
|
},
|
|
12652
12560
|
"comment": "<ul>\n<li>A function that maps the state to a specific form.\n Takes the current state as an argument and returns the transformed state.</li>\n</ul>\n",
|
|
12653
12561
|
"typeExpression": {
|
|
12654
|
-
"pos":
|
|
12655
|
-
"end":
|
|
12562
|
+
"pos": 4244,
|
|
12563
|
+
"end": 4263,
|
|
12656
12564
|
"kind": 310,
|
|
12657
12565
|
"id": 0,
|
|
12658
12566
|
"flags": 16842752,
|
|
12659
12567
|
"modifierFlagsCache": 0,
|
|
12660
12568
|
"transformFlags": 0,
|
|
12661
12569
|
"type": {
|
|
12662
|
-
"pos":
|
|
12663
|
-
"end":
|
|
12570
|
+
"pos": 4245,
|
|
12571
|
+
"end": 4262,
|
|
12664
12572
|
"kind": 197,
|
|
12665
12573
|
"id": 0,
|
|
12666
12574
|
"flags": 16777216,
|
|
12667
12575
|
"modifierFlagsCache": 0,
|
|
12668
12576
|
"transformFlags": 1,
|
|
12669
12577
|
"type": {
|
|
12670
|
-
"pos":
|
|
12671
|
-
"end":
|
|
12578
|
+
"pos": 4246,
|
|
12579
|
+
"end": 4261,
|
|
12672
12580
|
"kind": 185,
|
|
12673
12581
|
"id": 0,
|
|
12674
12582
|
"flags": 16777216,
|
|
@@ -12676,16 +12584,16 @@
|
|
|
12676
12584
|
"transformFlags": 1,
|
|
12677
12585
|
"parameters": [
|
|
12678
12586
|
{
|
|
12679
|
-
"pos":
|
|
12680
|
-
"end":
|
|
12587
|
+
"pos": 4247,
|
|
12588
|
+
"end": 4255,
|
|
12681
12589
|
"kind": 170,
|
|
12682
12590
|
"id": 0,
|
|
12683
12591
|
"flags": 16777216,
|
|
12684
12592
|
"modifierFlagsCache": 0,
|
|
12685
12593
|
"transformFlags": 1,
|
|
12686
12594
|
"name": {
|
|
12687
|
-
"pos":
|
|
12688
|
-
"end":
|
|
12595
|
+
"pos": 4247,
|
|
12596
|
+
"end": 4252,
|
|
12689
12597
|
"kind": 80,
|
|
12690
12598
|
"id": 0,
|
|
12691
12599
|
"flags": 16777216,
|
|
@@ -12693,16 +12601,16 @@
|
|
|
12693
12601
|
"escapedText": "state"
|
|
12694
12602
|
},
|
|
12695
12603
|
"type": {
|
|
12696
|
-
"pos":
|
|
12697
|
-
"end":
|
|
12604
|
+
"pos": 4253,
|
|
12605
|
+
"end": 4255,
|
|
12698
12606
|
"kind": 184,
|
|
12699
12607
|
"id": 0,
|
|
12700
12608
|
"flags": 16777216,
|
|
12701
12609
|
"modifierFlagsCache": 0,
|
|
12702
12610
|
"transformFlags": 1,
|
|
12703
12611
|
"typeName": {
|
|
12704
|
-
"pos":
|
|
12705
|
-
"end":
|
|
12612
|
+
"pos": 4253,
|
|
12613
|
+
"end": 4255,
|
|
12706
12614
|
"kind": 80,
|
|
12707
12615
|
"id": 0,
|
|
12708
12616
|
"flags": 16777216,
|
|
@@ -12713,16 +12621,16 @@
|
|
|
12713
12621
|
}
|
|
12714
12622
|
],
|
|
12715
12623
|
"type": {
|
|
12716
|
-
"pos":
|
|
12717
|
-
"end":
|
|
12624
|
+
"pos": 4259,
|
|
12625
|
+
"end": 4261,
|
|
12718
12626
|
"kind": 184,
|
|
12719
12627
|
"id": 0,
|
|
12720
12628
|
"flags": 16777216,
|
|
12721
12629
|
"modifierFlagsCache": 0,
|
|
12722
12630
|
"transformFlags": 1,
|
|
12723
12631
|
"typeName": {
|
|
12724
|
-
"pos":
|
|
12725
|
-
"end":
|
|
12632
|
+
"pos": 4259,
|
|
12633
|
+
"end": 4261,
|
|
12726
12634
|
"kind": 80,
|
|
12727
12635
|
"id": 0,
|
|
12728
12636
|
"flags": 16777216,
|
|
@@ -12736,8 +12644,8 @@
|
|
|
12736
12644
|
},
|
|
12737
12645
|
{
|
|
12738
12646
|
"tagName": {
|
|
12739
|
-
"pos":
|
|
12740
|
-
"end":
|
|
12647
|
+
"pos": 4451,
|
|
12648
|
+
"end": 4458,
|
|
12741
12649
|
"kind": 80,
|
|
12742
12650
|
"id": 0,
|
|
12743
12651
|
"flags": 16842752,
|
|
@@ -12775,8 +12683,8 @@
|
|
|
12775
12683
|
"jsdoctags": [
|
|
12776
12684
|
{
|
|
12777
12685
|
"name": {
|
|
12778
|
-
"pos":
|
|
12779
|
-
"end":
|
|
12686
|
+
"pos": 4691,
|
|
12687
|
+
"end": 4694,
|
|
12780
12688
|
"kind": 80,
|
|
12781
12689
|
"id": 0,
|
|
12782
12690
|
"flags": 16842752,
|
|
@@ -12789,8 +12697,8 @@
|
|
|
12789
12697
|
"deprecated": false,
|
|
12790
12698
|
"deprecationMessage": "",
|
|
12791
12699
|
"tagName": {
|
|
12792
|
-
"pos":
|
|
12793
|
-
"end":
|
|
12700
|
+
"pos": 4680,
|
|
12701
|
+
"end": 4685,
|
|
12794
12702
|
"kind": 80,
|
|
12795
12703
|
"id": 0,
|
|
12796
12704
|
"flags": 16842752,
|
|
@@ -12799,24 +12707,24 @@
|
|
|
12799
12707
|
},
|
|
12800
12708
|
"comment": "<ul>\n<li>A specific key to access a part of the state.\n The key should be a property name of the state object.</li>\n</ul>\n",
|
|
12801
12709
|
"typeExpression": {
|
|
12802
|
-
"pos":
|
|
12803
|
-
"end":
|
|
12710
|
+
"pos": 4686,
|
|
12711
|
+
"end": 4689,
|
|
12804
12712
|
"kind": 310,
|
|
12805
12713
|
"id": 0,
|
|
12806
12714
|
"flags": 16842752,
|
|
12807
12715
|
"modifierFlagsCache": 0,
|
|
12808
12716
|
"transformFlags": 0,
|
|
12809
12717
|
"type": {
|
|
12810
|
-
"pos":
|
|
12811
|
-
"end":
|
|
12718
|
+
"pos": 4687,
|
|
12719
|
+
"end": 4688,
|
|
12812
12720
|
"kind": 184,
|
|
12813
12721
|
"id": 0,
|
|
12814
12722
|
"flags": 16777216,
|
|
12815
12723
|
"modifierFlagsCache": 0,
|
|
12816
12724
|
"transformFlags": 1,
|
|
12817
12725
|
"typeName": {
|
|
12818
|
-
"pos":
|
|
12819
|
-
"end":
|
|
12726
|
+
"pos": 4687,
|
|
12727
|
+
"end": 4688,
|
|
12820
12728
|
"kind": 80,
|
|
12821
12729
|
"id": 0,
|
|
12822
12730
|
"flags": 16777216,
|
|
@@ -12828,8 +12736,8 @@
|
|
|
12828
12736
|
},
|
|
12829
12737
|
{
|
|
12830
12738
|
"tagName": {
|
|
12831
|
-
"pos":
|
|
12832
|
-
"end":
|
|
12739
|
+
"pos": 4833,
|
|
12740
|
+
"end": 4840,
|
|
12833
12741
|
"kind": 80,
|
|
12834
12742
|
"id": 0,
|
|
12835
12743
|
"flags": 16842752,
|
|
@@ -12867,8 +12775,8 @@
|
|
|
12867
12775
|
"jsdoctags": [
|
|
12868
12776
|
{
|
|
12869
12777
|
"name": {
|
|
12870
|
-
"pos":
|
|
12871
|
-
"end":
|
|
12778
|
+
"pos": 5099,
|
|
12779
|
+
"end": 5109,
|
|
12872
12780
|
"kind": 80,
|
|
12873
12781
|
"id": 0,
|
|
12874
12782
|
"flags": 16842752,
|
|
@@ -12881,8 +12789,8 @@
|
|
|
12881
12789
|
"deprecated": false,
|
|
12882
12790
|
"deprecationMessage": "",
|
|
12883
12791
|
"tagName": {
|
|
12884
|
-
"pos":
|
|
12885
|
-
"end":
|
|
12792
|
+
"pos": 5063,
|
|
12793
|
+
"end": 5068,
|
|
12886
12794
|
"kind": 80,
|
|
12887
12795
|
"id": 0,
|
|
12888
12796
|
"flags": 16842752,
|
|
@@ -12891,16 +12799,16 @@
|
|
|
12891
12799
|
},
|
|
12892
12800
|
"comment": "<ul>\n<li>Either a mapping function or a string key.\n If a string is provided, it uses dot notation to access nested properties.</li>\n</ul>\n",
|
|
12893
12801
|
"typeExpression": {
|
|
12894
|
-
"pos":
|
|
12895
|
-
"end":
|
|
12802
|
+
"pos": 5069,
|
|
12803
|
+
"end": 5097,
|
|
12896
12804
|
"kind": 310,
|
|
12897
12805
|
"id": 0,
|
|
12898
12806
|
"flags": 16842752,
|
|
12899
12807
|
"modifierFlagsCache": 0,
|
|
12900
12808
|
"transformFlags": 0,
|
|
12901
12809
|
"type": {
|
|
12902
|
-
"pos":
|
|
12903
|
-
"end":
|
|
12810
|
+
"pos": 5070,
|
|
12811
|
+
"end": 5096,
|
|
12904
12812
|
"kind": 193,
|
|
12905
12813
|
"id": 0,
|
|
12906
12814
|
"flags": 16777216,
|
|
@@ -12908,16 +12816,16 @@
|
|
|
12908
12816
|
"transformFlags": 1,
|
|
12909
12817
|
"types": [
|
|
12910
12818
|
{
|
|
12911
|
-
"pos":
|
|
12912
|
-
"end":
|
|
12819
|
+
"pos": 5070,
|
|
12820
|
+
"end": 5087,
|
|
12913
12821
|
"kind": 197,
|
|
12914
12822
|
"id": 0,
|
|
12915
12823
|
"flags": 16777216,
|
|
12916
12824
|
"modifierFlagsCache": 0,
|
|
12917
12825
|
"transformFlags": 1,
|
|
12918
12826
|
"type": {
|
|
12919
|
-
"pos":
|
|
12920
|
-
"end":
|
|
12827
|
+
"pos": 5071,
|
|
12828
|
+
"end": 5086,
|
|
12921
12829
|
"kind": 185,
|
|
12922
12830
|
"id": 0,
|
|
12923
12831
|
"flags": 16777216,
|
|
@@ -12925,16 +12833,16 @@
|
|
|
12925
12833
|
"transformFlags": 1,
|
|
12926
12834
|
"parameters": [
|
|
12927
12835
|
{
|
|
12928
|
-
"pos":
|
|
12929
|
-
"end":
|
|
12836
|
+
"pos": 5072,
|
|
12837
|
+
"end": 5080,
|
|
12930
12838
|
"kind": 170,
|
|
12931
12839
|
"id": 0,
|
|
12932
12840
|
"flags": 16777216,
|
|
12933
12841
|
"modifierFlagsCache": 0,
|
|
12934
12842
|
"transformFlags": 1,
|
|
12935
12843
|
"name": {
|
|
12936
|
-
"pos":
|
|
12937
|
-
"end":
|
|
12844
|
+
"pos": 5072,
|
|
12845
|
+
"end": 5077,
|
|
12938
12846
|
"kind": 80,
|
|
12939
12847
|
"id": 0,
|
|
12940
12848
|
"flags": 16777216,
|
|
@@ -12942,16 +12850,16 @@
|
|
|
12942
12850
|
"escapedText": "state"
|
|
12943
12851
|
},
|
|
12944
12852
|
"type": {
|
|
12945
|
-
"pos":
|
|
12946
|
-
"end":
|
|
12853
|
+
"pos": 5078,
|
|
12854
|
+
"end": 5080,
|
|
12947
12855
|
"kind": 184,
|
|
12948
12856
|
"id": 0,
|
|
12949
12857
|
"flags": 16777216,
|
|
12950
12858
|
"modifierFlagsCache": 0,
|
|
12951
12859
|
"transformFlags": 1,
|
|
12952
12860
|
"typeName": {
|
|
12953
|
-
"pos":
|
|
12954
|
-
"end":
|
|
12861
|
+
"pos": 5078,
|
|
12862
|
+
"end": 5080,
|
|
12955
12863
|
"kind": 80,
|
|
12956
12864
|
"id": 0,
|
|
12957
12865
|
"flags": 16777216,
|
|
@@ -12962,16 +12870,16 @@
|
|
|
12962
12870
|
}
|
|
12963
12871
|
],
|
|
12964
12872
|
"type": {
|
|
12965
|
-
"pos":
|
|
12966
|
-
"end":
|
|
12873
|
+
"pos": 5084,
|
|
12874
|
+
"end": 5086,
|
|
12967
12875
|
"kind": 184,
|
|
12968
12876
|
"id": 0,
|
|
12969
12877
|
"flags": 16777216,
|
|
12970
12878
|
"modifierFlagsCache": 0,
|
|
12971
12879
|
"transformFlags": 1,
|
|
12972
12880
|
"typeName": {
|
|
12973
|
-
"pos":
|
|
12974
|
-
"end":
|
|
12881
|
+
"pos": 5084,
|
|
12882
|
+
"end": 5086,
|
|
12975
12883
|
"kind": 80,
|
|
12976
12884
|
"id": 0,
|
|
12977
12885
|
"flags": 16777216,
|
|
@@ -12982,8 +12890,8 @@
|
|
|
12982
12890
|
}
|
|
12983
12891
|
},
|
|
12984
12892
|
{
|
|
12985
|
-
"pos":
|
|
12986
|
-
"end":
|
|
12893
|
+
"pos": 5089,
|
|
12894
|
+
"end": 5096,
|
|
12987
12895
|
"kind": 154,
|
|
12988
12896
|
"id": 0,
|
|
12989
12897
|
"flags": 16777216,
|
|
@@ -12995,8 +12903,8 @@
|
|
|
12995
12903
|
},
|
|
12996
12904
|
{
|
|
12997
12905
|
"tagName": {
|
|
12998
|
-
"pos":
|
|
12999
|
-
"end":
|
|
12906
|
+
"pos": 5297,
|
|
12907
|
+
"end": 5304,
|
|
13000
12908
|
"kind": 80,
|
|
13001
12909
|
"id": 0,
|
|
13002
12910
|
"flags": 16842752,
|
|
@@ -13032,8 +12940,8 @@
|
|
|
13032
12940
|
"jsdoctags": [
|
|
13033
12941
|
{
|
|
13034
12942
|
"name": {
|
|
13035
|
-
"pos":
|
|
13036
|
-
"end":
|
|
12943
|
+
"pos": 6876,
|
|
12944
|
+
"end": 6881,
|
|
13037
12945
|
"kind": 80,
|
|
13038
12946
|
"id": 0,
|
|
13039
12947
|
"flags": 16842752,
|
|
@@ -13046,8 +12954,8 @@
|
|
|
13046
12954
|
"deprecated": false,
|
|
13047
12955
|
"deprecationMessage": "",
|
|
13048
12956
|
"tagName": {
|
|
13049
|
-
"pos":
|
|
13050
|
-
"end":
|
|
12957
|
+
"pos": 6855,
|
|
12958
|
+
"end": 6860,
|
|
13051
12959
|
"kind": 80,
|
|
13052
12960
|
"id": 0,
|
|
13053
12961
|
"flags": 16842752,
|
|
@@ -13056,24 +12964,24 @@
|
|
|
13056
12964
|
},
|
|
13057
12965
|
"comment": "<ul>\n<li>Optional initial state for the locale service.</li>\n</ul>\n",
|
|
13058
12966
|
"typeExpression": {
|
|
13059
|
-
"pos":
|
|
13060
|
-
"end":
|
|
12967
|
+
"pos": 6861,
|
|
12968
|
+
"end": 6874,
|
|
13061
12969
|
"kind": 310,
|
|
13062
12970
|
"id": 0,
|
|
13063
12971
|
"flags": 16842752,
|
|
13064
12972
|
"modifierFlagsCache": 0,
|
|
13065
12973
|
"transformFlags": 0,
|
|
13066
12974
|
"type": {
|
|
13067
|
-
"pos":
|
|
13068
|
-
"end":
|
|
12975
|
+
"pos": 6862,
|
|
12976
|
+
"end": 6873,
|
|
13069
12977
|
"kind": 184,
|
|
13070
12978
|
"id": 0,
|
|
13071
12979
|
"flags": 16777216,
|
|
13072
12980
|
"modifierFlagsCache": 0,
|
|
13073
12981
|
"transformFlags": 1,
|
|
13074
12982
|
"typeName": {
|
|
13075
|
-
"pos":
|
|
13076
|
-
"end":
|
|
12983
|
+
"pos": 6862,
|
|
12984
|
+
"end": 6873,
|
|
13077
12985
|
"kind": 80,
|
|
13078
12986
|
"id": 0,
|
|
13079
12987
|
"flags": 16777216,
|
|
@@ -13085,8 +12993,8 @@
|
|
|
13085
12993
|
},
|
|
13086
12994
|
{
|
|
13087
12995
|
"tagName": {
|
|
13088
|
-
"pos":
|
|
13089
|
-
"end":
|
|
12996
|
+
"pos": 6940,
|
|
12997
|
+
"end": 6947,
|
|
13090
12998
|
"kind": 80,
|
|
13091
12999
|
"id": 0,
|
|
13092
13000
|
"flags": 16842752,
|
|
@@ -13135,8 +13043,8 @@
|
|
|
13135
13043
|
"jsdoctags": [
|
|
13136
13044
|
{
|
|
13137
13045
|
"name": {
|
|
13138
|
-
"pos":
|
|
13139
|
-
"end":
|
|
13046
|
+
"pos": 7859,
|
|
13047
|
+
"end": 7864,
|
|
13140
13048
|
"kind": 80,
|
|
13141
13049
|
"id": 0,
|
|
13142
13050
|
"flags": 16842752,
|
|
@@ -13149,8 +13057,8 @@
|
|
|
13149
13057
|
"deprecated": false,
|
|
13150
13058
|
"deprecationMessage": "",
|
|
13151
13059
|
"tagName": {
|
|
13152
|
-
"pos":
|
|
13153
|
-
"end":
|
|
13060
|
+
"pos": 7853,
|
|
13061
|
+
"end": 7858,
|
|
13154
13062
|
"kind": 80,
|
|
13155
13063
|
"id": 0,
|
|
13156
13064
|
"flags": 16842752,
|
|
@@ -13187,8 +13095,8 @@
|
|
|
13187
13095
|
"jsdoctags": [
|
|
13188
13096
|
{
|
|
13189
13097
|
"name": {
|
|
13190
|
-
"pos":
|
|
13191
|
-
"end":
|
|
13098
|
+
"pos": 8144,
|
|
13099
|
+
"end": 8149,
|
|
13192
13100
|
"kind": 80,
|
|
13193
13101
|
"id": 0,
|
|
13194
13102
|
"flags": 16842752,
|
|
@@ -13201,8 +13109,8 @@
|
|
|
13201
13109
|
"deprecated": false,
|
|
13202
13110
|
"deprecationMessage": "",
|
|
13203
13111
|
"tagName": {
|
|
13204
|
-
"pos":
|
|
13205
|
-
"end":
|
|
13112
|
+
"pos": 8124,
|
|
13113
|
+
"end": 8129,
|
|
13206
13114
|
"kind": 80,
|
|
13207
13115
|
"id": 0,
|
|
13208
13116
|
"flags": 16842752,
|
|
@@ -13211,24 +13119,24 @@
|
|
|
13211
13119
|
},
|
|
13212
13120
|
"comment": "<ul>\n<li>The new state to be set for the locale.</li>\n</ul>\n",
|
|
13213
13121
|
"typeExpression": {
|
|
13214
|
-
"pos":
|
|
13215
|
-
"end":
|
|
13122
|
+
"pos": 8130,
|
|
13123
|
+
"end": 8143,
|
|
13216
13124
|
"kind": 310,
|
|
13217
13125
|
"id": 0,
|
|
13218
13126
|
"flags": 16842752,
|
|
13219
13127
|
"modifierFlagsCache": 0,
|
|
13220
13128
|
"transformFlags": 0,
|
|
13221
13129
|
"type": {
|
|
13222
|
-
"pos":
|
|
13223
|
-
"end":
|
|
13130
|
+
"pos": 8131,
|
|
13131
|
+
"end": 8142,
|
|
13224
13132
|
"kind": 184,
|
|
13225
13133
|
"id": 0,
|
|
13226
13134
|
"flags": 16777216,
|
|
13227
13135
|
"modifierFlagsCache": 0,
|
|
13228
13136
|
"transformFlags": 1,
|
|
13229
13137
|
"typeName": {
|
|
13230
|
-
"pos":
|
|
13231
|
-
"end":
|
|
13138
|
+
"pos": 8131,
|
|
13139
|
+
"end": 8142,
|
|
13232
13140
|
"kind": 80,
|
|
13233
13141
|
"id": 0,
|
|
13234
13142
|
"flags": 16777216,
|
|
@@ -13240,8 +13148,8 @@
|
|
|
13240
13148
|
},
|
|
13241
13149
|
{
|
|
13242
13150
|
"tagName": {
|
|
13243
|
-
"pos":
|
|
13244
|
-
"end":
|
|
13151
|
+
"pos": 8200,
|
|
13152
|
+
"end": 8206,
|
|
13245
13153
|
"kind": 80,
|
|
13246
13154
|
"id": 0,
|
|
13247
13155
|
"flags": 16842752,
|
|
@@ -13257,7 +13165,7 @@
|
|
|
13257
13165
|
"deprecationMessage": "",
|
|
13258
13166
|
"description": "<p>LocaleService is responsible for managing locale states and configurations in an Angular application.\nIt utilizes the CLDR library to load and construct the locale for each region. This service allows\nfor dynamic loading of locales upon request and updates the state of the EUI app accordingly.</p>\n<p>Key functionalities include:</p>\n<ul>\n<li>Binding to a translation service for locale changes.</li>\n<li>Updating the Angular LOCALE_ID token.</li>\n</ul>\n<p>EuiService<T | LocaleState></p>\n",
|
|
13259
13167
|
"rawdescription": "\n\nLocaleService is responsible for managing locale states and configurations in an Angular application.\nIt utilizes the CLDR library to load and construct the locale for each region. This service allows\nfor dynamic loading of locales upon request and updates the state of the EUI app accordingly.\n\nKey functionalities include:\n - Binding to a translation service for locale changes.\n - Updating the Angular LOCALE_ID token.\n\nEuiService<T | LocaleState>\n",
|
|
13260
|
-
"sourceCode": "import { Injectable, InjectionToken, LOCALE_ID, OnDestroy, Signal, inject } from '@angular/core';\nimport { getLocaleId } from '@angular/common';\nimport {\n DeepPartial,\n EuiService,\n EuiServiceStatus,\n getLocaleServiceConfigFromBase,\n GlobalConfig,\n I18nState,\n LocaleServiceConfig,\n LocaleState,\n Logger,\n} from '@eui/base';\nimport { BehaviorSubject, Observable, of, Subject } from 'rxjs';\nimport { distinctUntilChanged, filter, map, switchMap, take, takeUntil, tap } from 'rxjs/operators';\nimport { StoreService } from '../store';\nimport { LogService } from '../log';\nimport { I18nService } from '../i18n';\nimport { GLOBAL_CONFIG_TOKEN } from '../config/tokens';\nimport { isEqual } from 'lodash-es';\nimport { toSignal } from '@angular/core/rxjs-interop';\n\nexport type LocaleMapper = (locale: string) => string;\nexport const LOCALE_ID_MAPPER = new InjectionToken<LocaleMapper>('localeIdMapper');\n\n/**\n * LocaleService is responsible for managing locale states and configurations in an Angular application.\n * It utilizes the CLDR library to load and construct the locale for each region. This service allows\n * for dynamic loading of locales upon request and updates the state of the EUI app accordingly.\n *\n * Key functionalities include:\n * - Binding to a translation service for locale changes.\n * - Updating the Angular LOCALE_ID token.\n *\n * @template T - Extends LocaleState, representing the state structure for locales.\n * @template L - The type of the locale data.\n * @extends EuiService<T | LocaleState>\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class LocaleService<T extends LocaleState = LocaleState> extends EuiService<T | LocaleState> implements OnDestroy {\n protected store = inject(StoreService);\n protected baseGlobalConfig = inject<GlobalConfig>(GLOBAL_CONFIG_TOKEN);\n protected locale_id: string;\n private static readonly DEFAULT_STATE: LocaleState = { id: 'en-US' };\n private localeMapper = inject<LocaleMapper>(LOCALE_ID_MAPPER, { optional: true });\n private i18n = inject(I18nService, { optional: true });\n private log = inject(LogService, { optional: true });\n\n private readonly logger: Logger | undefined;\n private subNotifier: Subject<void> = new Subject();\n protected config: LocaleServiceConfig;\n\n /**\n * a single signal holding the state - initial state is null\n */\n private state: Signal<T>;\n /**\n * a BehaviorSubject holding the state - initial state is null\n * This is the main source of truth for the state\n */\n private stateSubject: BehaviorSubject<T>;\n\n constructor() {\n const locale_id = inject(LOCALE_ID);\n\n super({ id: locale_id || Intl.DateTimeFormat().resolvedOptions().locale || LocaleService.DEFAULT_STATE.id } as T);\n this.locale_id = locale_id;\n const log = this.log;\n\n if (log) {\n this.logger = log.getLogger('core.LocaleService');\n }\n\n // Create a BehaviorSubject with the initial state\n this.stateSubject = new BehaviorSubject<T>(this.stateInstance as T);\n\n // Initialize signal with base state\n this.state = toSignal(this.stateSubject, { equal: isEqual, requireSync: true });\n\n // Subscribe to base class state changes\n this.onStateChange.subscribe((newState) => {\n // const clonedState = structuredClone(newState as T);\n this.stateSubject.next(newState as T);\n });\n\n this.config = getLocaleServiceConfigFromBase(this.baseGlobalConfig);\n // in case no localeMapper provided, set the angular getLocaleId as default\n if (!this.localeMapper) {\n this.localeMapper = getLocaleId;\n // TODO: replace deprecated method with new one\n // this.localeMapper = (locale: string) => new Intl.Locale(locale).baseName;\n }\n }\n\n ngOnDestroy(): void {\n this.subNotifier.next(void 0);\n this.subNotifier.complete();\n }\n\n getState(): Observable<T>;\n /**\n * Retrieves the state of the locale service. This method is overloaded to allow different ways of accessing the state.\n *\n * @template K - The type of the value to be returned. Defaults to the type of the locale state (T).\n *\n * @param {((state: T) => K)} [mapFn] - A function that maps the state to a specific form.\n * Takes the current state as an argument and returns the transformed state.\n * @returns {Observable<K>} - An observable that emits the transformed state.\n */\n getState<K = T>(mapFn?: (state: T) => K): Observable<K>;\n /**\n * @template a - A key that extends the keys of the state type T.\n * @param {a} [key] - A specific key to access a part of the state.\n * The key should be a property name of the state object.\n * @returns {Observable<Partial<a>>} - An observable that emits the value of the specified key in the state.\n * @param key\n */\n getState<a extends keyof DeepPartial<T>>(key?: a): Observable<DeepPartial<a>>;\n /**\n * @param {((state: T) => K) | string} [keyOrMapFn] - Either a mapping function or a string key.\n * If a string is provided, it uses dot notation to access nested properties.\n * @returns {Observable<Partial<K>>} - An observable that emits the selected or transformed state.\n *\n * If no parameter is provided, the method returns the entire state.\n * @param keyOrMapFn\n */\n getState<K = T>(keyOrMapFn?: ((state: T) => K) | string): Observable<DeepPartial<K>> {\n if (!keyOrMapFn) {\n return this.stateSubject.asObservable().pipe(\n distinctUntilChanged((x, y) => isEqual(x, y)),\n ) as Observable<DeepPartial<K>>;\n }\n\n if (typeof keyOrMapFn === 'function') {\n return this.stateSubject.asObservable().pipe(\n map(state => keyOrMapFn(state)),\n distinctUntilChanged((x, y) => isEqual(x, y)),\n );\n }\n\n return this.stateSubject.asObservable().pipe(\n map(state => {\n const keys = (keyOrMapFn as string).split('.');\n\n // Traverse the object based on the dot notation\n return keys.reduce<unknown>((acc, currKey) => {\n const record = acc as Record<string, unknown> | null | undefined;\n return record && record[currKey] !== undefined ? record[currKey] : undefined;\n }, state);\n }),\n distinctUntilChanged((x, y) => isEqual(x, y)),\n ) as unknown as Observable<DeepPartial<K>>;\n }\n\n /**\n * Initializes the LocaleService with necessary configurations and state.\n * Binds language changes to the state and dynamically loads the appropriate locales.\n *\n * @param {LocaleState} [state] - Optional initial state for the locale service.\n * @returns {Observable<EuiServiceStatus>} - Observable emitting the status of the initialization.\n */\n init(state?: LocaleState): Observable<EuiServiceStatus> {\n super.initEuiService();\n\n state = state || { id: this.currentLocale };\n\n\t\tif (state?.id && !this.isValidLocale(state.id)) {\n\t\t\tconst message = `Locale '${state.id}' is not a valid locale string. Please provide a valid locale.`;\n\t\t\tif (this.log) {\n\t\t\t\tthis.logger?.error(message);\n\t\t\t}\n\t\t\treturn of({ success: false, error: new Error(message) });\n\t\t}\n\n // bind language changes to locale changes\n if (this.config?.bindWithTranslate) {\n this.bindTranslateServiceLangChangeToState();\n }\n\n return of({ success: true })\n .pipe(tap(() => this.updateState(state as Partial<T>)));\n }\n\n /**\n * This method is used to update the state of the service with a new state.\n *\n * @param state\n */\n updateState(state: DeepPartial<T>): void;\n /**\n * Updates the locale state within the application. If the new state is not available,\n * it throws an error. Also updates the global LOCALE_ID token if configured to do so.\n *\n * @param {LocaleState} state - The new state to be set for the locale.\n * @throws Will throw an error if the locale for the given state id is not available.\n */\n updateState<K extends T>(state: DeepPartial<K>): void {\n const prevState = structuredClone(this.stateInstance);\n if(state?.id) {\n // check if locale is available otherwise throw error\n try {\n const id = (this.localeMapper as LocaleMapper)(state.id as string);\n this.stateInstance = super.deepMerge(this.stateInstance as T, { ...state, id });\n } catch (e) {\n const message = `Locale for '${state.id}' is not available.\\n` +\n `Please use addLocale('${state.id}') first`;\n if (this.log) {\n this.logger?.info(message, e);\n }\n throw new Error(message);\n }\n } else {\n this.stateInstance = super.deepMerge(this.stateInstance as T, { ...state });\n }\n // Emit state change\n this.onStateChange.next(this.stateInstance);\n // set previous state of service\n this.prevStateInstance = prevState;\n }\n\n /**\n * This method is used to get the state as readonly signal.\n */\n getSignal(): Signal<T> {\n return this.state;\n }\n\n /**\n * Retrieves the previous locale used in the application.\n *\n * @returns {string} - The previous locale identifier.\n */\n get previousLocale(): string {\n return this.prevStateInstance?.id || this.currentLocale;\n }\n\n /**\n * Retrieves the current locale used in the application.\n *\n * @returns {string} - The current locale identifier.\n */\n get currentLocale(): string {\n return this.stateInstance?.id;\n }\n\n /**\n * Listens for language changes and dynamically sets the locale accordingly.\n *\n * @private\n */\n private bindTranslateServiceLangChangeToState(): void {\n if (this.i18n) {\n this.i18n.onStateChange\n .pipe(\n takeUntil(this.subNotifier),\n // Only processes state changes when the language actually changes\n // Example: With activeLang='en', ignores changes between 'en-US' and 'en-GB'\n // Checks: activeLang exists, has 2+ chars, and differs from current locale's primary language\n filter((state: I18nState) => state?.activeLang !== null &&\n state?.activeLang !== undefined &&\n state?.activeLang.length > 1 &&\n state.activeLang.toLowerCase() !== this.stateInstance?.id.slice(0, 2).toLowerCase()),\n // to check if registration of locale otherwise register it\n map((state: I18nState) => (this.localeMapper as LocaleMapper)(state.activeLang)),\n // update the \"available\" array attribute with newly registered\n switchMap((id: string) =>\n this.getState().pipe(\n take(1),\n map((state: LocaleState) => {\n const available = (state as unknown as Record<string, unknown>)['available'] as string[] | undefined ?? [];\n return { ...state, id, available: Array.from(new Set([...available, id])) };\n }),\n ),\n ),\n )\n .subscribe((state: LocaleState) => {\n return this.updateState(state as Partial<T>);\n });\n }\n }\n\n\t/**\n\t * Checks if a given locale string is valid according to the Intl.Locale API. (based on BCP 47)\n\t * A valid locale string can be used to create a new Intl.Locale object without throwing an error.\n\t *\n\t * @param localeString - The locale string to be validated.\n\t * @returns {boolean} - Returns true if the locale string is valid, false otherwise.\n\t */\n\tprivate isValidLocale(localeString: string): boolean {\n\t\ttry {\n\t\t\t// Normalize: replace underscores with hyphens (support for Angular locale ids)\n\t\t\t// e.g., 'en_US' -> 'en-US'\n\t\t\t// Note: Intl.Locale only accepts hyphens as separators\n\t\t\t// Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale\n\t\t\tconst normalizedString = localeString.replace(/_/g, '-');\n\t\t\tnew Intl.Locale(normalizedString);\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\treturn false;\n\t\t}\n\t}\n}\n",
|
|
13168
|
+
"sourceCode": "import { Injectable, InjectionToken, LOCALE_ID, OnDestroy, Signal, inject } from '@angular/core';\nimport { getLocaleId } from '@angular/common';\nimport {\n DeepPartial,\n EuiService,\n EuiServiceStatus,\n getLocaleServiceConfigFromBase,\n GlobalConfig,\n I18nState,\n LocaleServiceConfig,\n LocaleState,\n Logger,\n} from '@eui/base';\nimport { BehaviorSubject, Observable, of, Subject } from 'rxjs';\nimport { distinctUntilChanged, filter, map, switchMap, take, takeUntil, tap } from 'rxjs/operators';\nimport { StoreService } from '../store';\nimport { LogService } from '../log';\nimport { I18nService } from '../i18n';\nimport { GLOBAL_CONFIG_TOKEN } from '../config/tokens';\nimport { isEqual } from 'lodash-es';\nimport { toSignal } from '@angular/core/rxjs-interop';\n\nexport type LocaleMapper = (locale: string) => string;\nexport const LOCALE_ID_MAPPER = new InjectionToken<LocaleMapper>('localeIdMapper');\n\n/**\n * LocaleService is responsible for managing locale states and configurations in an Angular application.\n * It utilizes the CLDR library to load and construct the locale for each region. This service allows\n * for dynamic loading of locales upon request and updates the state of the EUI app accordingly.\n *\n * Key functionalities include:\n * - Binding to a translation service for locale changes.\n * - Updating the Angular LOCALE_ID token.\n *\n * @template T - Extends LocaleState, representing the state structure for locales.\n * @template L - The type of the locale data.\n * @extends EuiService<T | LocaleState>\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class LocaleService<T extends LocaleState = LocaleState> extends EuiService<T | LocaleState> implements OnDestroy {\n protected store = inject(StoreService);\n protected baseGlobalConfig = inject<GlobalConfig>(GLOBAL_CONFIG_TOKEN);\n protected locale_id: string;\n private static readonly DEFAULT_STATE: LocaleState = { id: 'en-US' };\n private localeMapper = inject<LocaleMapper>(LOCALE_ID_MAPPER, { optional: true });\n private i18n = inject(I18nService, { optional: true });\n private log = inject(LogService, { optional: true });\n\n private readonly logger: Logger | undefined;\n private subNotifier = new Subject<void>();\n protected config: LocaleServiceConfig;\n\n /**\n * a single signal holding the state - initial state is null\n */\n private state: Signal<T>;\n /**\n * a BehaviorSubject holding the state - initial state is null\n * This is the main source of truth for the state\n */\n private stateSubject: BehaviorSubject<T>;\n\n constructor() {\n const locale_id = inject(LOCALE_ID);\n\n super({ id: locale_id || Intl.DateTimeFormat().resolvedOptions().locale || LocaleService.DEFAULT_STATE.id } as T);\n this.locale_id = locale_id;\n const log = this.log;\n\n if (log) {\n this.logger = log.getLogger('core.LocaleService');\n }\n\n // Create a BehaviorSubject with the initial state\n this.stateSubject = new BehaviorSubject<T>(this.stateInstance as T);\n\n // Initialize signal with base state\n this.state = toSignal(this.stateSubject, { equal: isEqual, requireSync: true });\n\n // Subscribe to base class state changes\n this.onStateChange.subscribe((newState) => {\n // const clonedState = structuredClone(newState as T);\n this.stateSubject.next(newState as T);\n });\n\n this.config = getLocaleServiceConfigFromBase(this.baseGlobalConfig);\n // in case no localeMapper provided, set the angular getLocaleId as default\n if (!this.localeMapper) {\n this.localeMapper = getLocaleId;\n // TODO: replace deprecated method with new one\n // this.localeMapper = (locale: string) => new Intl.Locale(locale).baseName;\n }\n }\n\n ngOnDestroy(): void {\n this.subNotifier.next(void 0);\n this.subNotifier.complete();\n }\n\n getState(): Observable<T>;\n /**\n * Retrieves the state of the locale service. This method is overloaded to allow different ways of accessing the state.\n *\n * @template K - The type of the value to be returned. Defaults to the type of the locale state (T).\n *\n * @param {((state: T) => K)} [mapFn] - A function that maps the state to a specific form.\n * Takes the current state as an argument and returns the transformed state.\n * @returns {Observable<K>} - An observable that emits the transformed state.\n */\n getState<K = T>(mapFn?: (state: T) => K): Observable<K>;\n /**\n * @template a - A key that extends the keys of the state type T.\n * @param {a} [key] - A specific key to access a part of the state.\n * The key should be a property name of the state object.\n * @returns {Observable<Partial<a>>} - An observable that emits the value of the specified key in the state.\n * @param key\n */\n getState<a extends keyof DeepPartial<T>>(key?: a): Observable<DeepPartial<a>>;\n /**\n * @param {((state: T) => K) | string} [keyOrMapFn] - Either a mapping function or a string key.\n * If a string is provided, it uses dot notation to access nested properties.\n * @returns {Observable<Partial<K>>} - An observable that emits the selected or transformed state.\n *\n * If no parameter is provided, the method returns the entire state.\n * @param keyOrMapFn\n */\n getState<K = T>(keyOrMapFn?: ((state: T) => K) | string): Observable<DeepPartial<K>> {\n if (!keyOrMapFn) {\n return this.stateSubject.asObservable().pipe(\n distinctUntilChanged((x, y) => isEqual(x, y)),\n ) as Observable<DeepPartial<K>>;\n }\n\n if (typeof keyOrMapFn === 'function') {\n return this.stateSubject.asObservable().pipe(\n map(state => keyOrMapFn(state)),\n distinctUntilChanged((x, y) => isEqual(x, y)),\n );\n }\n\n return this.stateSubject.asObservable().pipe(\n map(state => {\n const keys = (keyOrMapFn as string).split('.');\n\n // Traverse the object based on the dot notation\n return keys.reduce<unknown>((acc, currKey) => {\n const record = acc as Record<string, unknown> | null | undefined;\n return record && record[currKey] !== undefined ? record[currKey] : undefined;\n }, state);\n }),\n distinctUntilChanged((x, y) => isEqual(x, y)),\n ) as unknown as Observable<DeepPartial<K>>;\n }\n\n /**\n * Initializes the LocaleService with necessary configurations and state.\n * Binds language changes to the state and dynamically loads the appropriate locales.\n *\n * @param {LocaleState} [state] - Optional initial state for the locale service.\n * @returns {Observable<EuiServiceStatus>} - Observable emitting the status of the initialization.\n */\n init(state?: LocaleState): Observable<EuiServiceStatus> {\n super.initEuiService();\n\n state = state || { id: this.currentLocale };\n\n\t\tif (state?.id && !this.isValidLocale(state.id)) {\n\t\t\tconst message = `Locale '${state.id}' is not a valid locale string. Please provide a valid locale.`;\n\t\t\tif (this.log) {\n\t\t\t\tthis.logger?.error(message);\n\t\t\t}\n\t\t\treturn of({ success: false, error: new Error(message) });\n\t\t}\n\n // bind language changes to locale changes\n if (this.config?.bindWithTranslate) {\n this.bindTranslateServiceLangChangeToState();\n }\n\n return of({ success: true })\n .pipe(tap(() => this.updateState(state as Partial<T>)));\n }\n\n /**\n * This method is used to update the state of the service with a new state.\n *\n * @param state\n */\n updateState(state: DeepPartial<T>): void;\n /**\n * Updates the locale state within the application. If the new state is not available,\n * it throws an error. Also updates the global LOCALE_ID token if configured to do so.\n *\n * @param {LocaleState} state - The new state to be set for the locale.\n * @throws Will throw an error if the locale for the given state id is not available.\n */\n updateState<K extends T>(state: DeepPartial<K>): void {\n const prevState = structuredClone(this.stateInstance);\n if(state?.id) {\n // check if locale is available otherwise throw error\n try {\n const id = (this.localeMapper as LocaleMapper)(state.id as string);\n this.stateInstance = super.deepMerge(this.stateInstance as T, { ...state, id });\n } catch (e) {\n const message = `Locale for '${state.id}' is not available.\\n` +\n `Please use addLocale('${state.id}') first`;\n if (this.log) {\n this.logger?.info(message, e);\n }\n throw new Error(message);\n }\n } else {\n this.stateInstance = super.deepMerge(this.stateInstance as T, { ...state });\n }\n // Emit state change\n this.onStateChange.next(this.stateInstance);\n // set previous state of service\n this.prevStateInstance = prevState;\n }\n\n /**\n * This method is used to get the state as readonly signal.\n */\n getSignal(): Signal<T> {\n return this.state;\n }\n\n /**\n * Retrieves the previous locale used in the application.\n *\n * @returns {string} - The previous locale identifier.\n */\n get previousLocale(): string {\n return this.prevStateInstance?.id || this.currentLocale;\n }\n\n /**\n * Retrieves the current locale used in the application.\n *\n * @returns {string} - The current locale identifier.\n */\n get currentLocale(): string {\n return this.stateInstance?.id;\n }\n\n /**\n * Listens for language changes and dynamically sets the locale accordingly.\n *\n * @private\n */\n private bindTranslateServiceLangChangeToState(): void {\n if (this.i18n) {\n this.i18n.onStateChange\n .pipe(\n takeUntil(this.subNotifier),\n // Only processes state changes when the language actually changes\n // Example: With activeLang='en', ignores changes between 'en-US' and 'en-GB'\n // Checks: activeLang exists, has 2+ chars, and differs from current locale's primary language\n filter((state: I18nState) => state?.activeLang !== null &&\n state?.activeLang !== undefined &&\n state?.activeLang.length > 1 &&\n state.activeLang.toLowerCase() !== this.stateInstance?.id.slice(0, 2).toLowerCase()),\n // to check if registration of locale otherwise register it\n map((state: I18nState) => (this.localeMapper as LocaleMapper)(state.activeLang)),\n // update the \"available\" array attribute with newly registered\n switchMap((id: string) =>\n this.getState().pipe(\n take(1),\n map((state: LocaleState) => {\n const available = (state as unknown as Record<string, unknown>)['available'] as string[] | undefined ?? [];\n return { ...state, id, available: Array.from(new Set([...available, id])) };\n }),\n ),\n ),\n )\n .subscribe((state: LocaleState) => {\n return this.updateState(state as Partial<T>);\n });\n }\n }\n\n\t/**\n\t * Checks if a given locale string is valid according to the Intl.Locale API. (based on BCP 47)\n\t * A valid locale string can be used to create a new Intl.Locale object without throwing an error.\n\t *\n\t * @param localeString - The locale string to be validated.\n\t * @returns {boolean} - Returns true if the locale string is valid, false otherwise.\n\t */\n\tprivate isValidLocale(localeString: string): boolean {\n\t\ttry {\n\t\t\t// Normalize: replace underscores with hyphens (support for Angular locale ids)\n\t\t\t// e.g., 'en_US' -> 'en-US'\n\t\t\t// Note: Intl.Locale only accepts hyphens as separators\n\t\t\t// Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale\n\t\t\tconst normalizedString = localeString.replace(/_/g, '-');\n\t\t\tnew Intl.Locale(normalizedString);\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\treturn false;\n\t\t}\n\t}\n}\n",
|
|
13261
13169
|
"constructorObj": {
|
|
13262
13170
|
"name": "constructor",
|
|
13263
13171
|
"description": "",
|
|
@@ -13279,16 +13187,16 @@
|
|
|
13279
13187
|
"description": "<p>Retrieves the previous locale used in the application.</p>\n",
|
|
13280
13188
|
"jsdoctags": [
|
|
13281
13189
|
{
|
|
13282
|
-
"pos":
|
|
13283
|
-
"end":
|
|
13190
|
+
"pos": 9545,
|
|
13191
|
+
"end": 9602,
|
|
13284
13192
|
"kind": 343,
|
|
13285
13193
|
"id": 0,
|
|
13286
13194
|
"flags": 16842752,
|
|
13287
13195
|
"modifierFlagsCache": 0,
|
|
13288
13196
|
"transformFlags": 0,
|
|
13289
13197
|
"tagName": {
|
|
13290
|
-
"pos":
|
|
13291
|
-
"end":
|
|
13198
|
+
"pos": 9546,
|
|
13199
|
+
"end": 9553,
|
|
13292
13200
|
"kind": 80,
|
|
13293
13201
|
"id": 0,
|
|
13294
13202
|
"flags": 16842752,
|
|
@@ -13297,16 +13205,16 @@
|
|
|
13297
13205
|
},
|
|
13298
13206
|
"comment": "<ul>\n<li>The previous locale identifier.</li>\n</ul>\n",
|
|
13299
13207
|
"typeExpression": {
|
|
13300
|
-
"pos":
|
|
13301
|
-
"end":
|
|
13208
|
+
"pos": 9554,
|
|
13209
|
+
"end": 9562,
|
|
13302
13210
|
"kind": 310,
|
|
13303
13211
|
"id": 0,
|
|
13304
13212
|
"flags": 16842752,
|
|
13305
13213
|
"modifierFlagsCache": 0,
|
|
13306
13214
|
"transformFlags": 0,
|
|
13307
13215
|
"type": {
|
|
13308
|
-
"pos":
|
|
13309
|
-
"end":
|
|
13216
|
+
"pos": 9555,
|
|
13217
|
+
"end": 9561,
|
|
13310
13218
|
"kind": 154,
|
|
13311
13219
|
"id": 0,
|
|
13312
13220
|
"flags": 16777216,
|
|
@@ -13328,16 +13236,16 @@
|
|
|
13328
13236
|
"description": "<p>Retrieves the current locale used in the application.</p>\n",
|
|
13329
13237
|
"jsdoctags": [
|
|
13330
13238
|
{
|
|
13331
|
-
"pos":
|
|
13332
|
-
"end":
|
|
13239
|
+
"pos": 9795,
|
|
13240
|
+
"end": 9851,
|
|
13333
13241
|
"kind": 343,
|
|
13334
13242
|
"id": 0,
|
|
13335
13243
|
"flags": 16842752,
|
|
13336
13244
|
"modifierFlagsCache": 0,
|
|
13337
13245
|
"transformFlags": 0,
|
|
13338
13246
|
"tagName": {
|
|
13339
|
-
"pos":
|
|
13340
|
-
"end":
|
|
13247
|
+
"pos": 9796,
|
|
13248
|
+
"end": 9803,
|
|
13341
13249
|
"kind": 80,
|
|
13342
13250
|
"id": 0,
|
|
13343
13251
|
"flags": 16842752,
|
|
@@ -13346,16 +13254,16 @@
|
|
|
13346
13254
|
},
|
|
13347
13255
|
"comment": "<ul>\n<li>The current locale identifier.</li>\n</ul>\n",
|
|
13348
13256
|
"typeExpression": {
|
|
13349
|
-
"pos":
|
|
13350
|
-
"end":
|
|
13257
|
+
"pos": 9804,
|
|
13258
|
+
"end": 9812,
|
|
13351
13259
|
"kind": 310,
|
|
13352
13260
|
"id": 0,
|
|
13353
13261
|
"flags": 16842752,
|
|
13354
13262
|
"modifierFlagsCache": 0,
|
|
13355
13263
|
"transformFlags": 0,
|
|
13356
13264
|
"type": {
|
|
13357
|
-
"pos":
|
|
13358
|
-
"end":
|
|
13265
|
+
"pos": 9805,
|
|
13266
|
+
"end": 9811,
|
|
13359
13267
|
"kind": 154,
|
|
13360
13268
|
"id": 0,
|
|
13361
13269
|
"flags": 16777216,
|
|
@@ -14894,7 +14802,7 @@
|
|
|
14894
14802
|
},
|
|
14895
14803
|
{
|
|
14896
14804
|
"name": "StoreService",
|
|
14897
|
-
"id": "injectable-StoreService-
|
|
14805
|
+
"id": "injectable-StoreService-d9f5a5019bcfe41a8e69e23580e560db8ec12e91866775fcc0da5988ff0781969e6d52b524917a358514f1980d345b2339e52773b0a63648b40430615492b8e1",
|
|
14898
14806
|
"file": "packages/core/src/lib/services/store/store.service.ts",
|
|
14899
14807
|
"coverageIgnore": false,
|
|
14900
14808
|
"properties": [
|
|
@@ -14904,12 +14812,11 @@
|
|
|
14904
14812
|
"defaultValue": "{}",
|
|
14905
14813
|
"deprecated": false,
|
|
14906
14814
|
"deprecationMessage": "",
|
|
14907
|
-
"type": "
|
|
14815
|
+
"type": "Record<string, Handler<T>>",
|
|
14908
14816
|
"indexKey": "",
|
|
14909
14817
|
"optional": false,
|
|
14910
14818
|
"description": "<p>autoSave handlers to call before saving in local Storage</p>\n",
|
|
14911
14819
|
"line": 31,
|
|
14912
|
-
"subProperties": [],
|
|
14913
14820
|
"rawdescription": "\n\nautoSave handlers to call before saving in local Storage\n",
|
|
14914
14821
|
"modifierKind": [
|
|
14915
14822
|
124
|
|
@@ -14965,8 +14872,8 @@
|
|
|
14965
14872
|
"jsdoctags": [
|
|
14966
14873
|
{
|
|
14967
14874
|
"name": {
|
|
14968
|
-
"pos":
|
|
14969
|
-
"end":
|
|
14875
|
+
"pos": 3392,
|
|
14876
|
+
"end": 3402,
|
|
14970
14877
|
"kind": 80,
|
|
14971
14878
|
"id": 0,
|
|
14972
14879
|
"flags": 16842752,
|
|
@@ -14979,8 +14886,8 @@
|
|
|
14979
14886
|
"deprecated": false,
|
|
14980
14887
|
"deprecationMessage": "",
|
|
14981
14888
|
"tagName": {
|
|
14982
|
-
"pos":
|
|
14983
|
-
"end":
|
|
14889
|
+
"pos": 3386,
|
|
14890
|
+
"end": 3391,
|
|
14984
14891
|
"kind": 80,
|
|
14985
14892
|
"id": 0,
|
|
14986
14893
|
"flags": 16842752,
|
|
@@ -14991,8 +14898,8 @@
|
|
|
14991
14898
|
},
|
|
14992
14899
|
{
|
|
14993
14900
|
"name": {
|
|
14994
|
-
"pos":
|
|
14995
|
-
"end":
|
|
14901
|
+
"pos": 3417,
|
|
14902
|
+
"end": 3424,
|
|
14996
14903
|
"kind": 80,
|
|
14997
14904
|
"id": 0,
|
|
14998
14905
|
"flags": 16842752,
|
|
@@ -15005,8 +14912,8 @@
|
|
|
15005
14912
|
"deprecated": false,
|
|
15006
14913
|
"deprecationMessage": "",
|
|
15007
14914
|
"tagName": {
|
|
15008
|
-
"pos":
|
|
15009
|
-
"end":
|
|
14915
|
+
"pos": 3411,
|
|
14916
|
+
"end": 3416,
|
|
15010
14917
|
"kind": 80,
|
|
15011
14918
|
"id": 0,
|
|
15012
14919
|
"flags": 16842752,
|
|
@@ -15111,8 +15018,8 @@
|
|
|
15111
15018
|
"jsdoctags": [
|
|
15112
15019
|
{
|
|
15113
15020
|
"name": {
|
|
15114
|
-
"pos":
|
|
15115
|
-
"end":
|
|
15021
|
+
"pos": 5980,
|
|
15022
|
+
"end": 5985,
|
|
15116
15023
|
"kind": 80,
|
|
15117
15024
|
"id": 0,
|
|
15118
15025
|
"flags": 16842752,
|
|
@@ -15125,8 +15032,8 @@
|
|
|
15125
15032
|
"deprecated": false,
|
|
15126
15033
|
"deprecationMessage": "",
|
|
15127
15034
|
"tagName": {
|
|
15128
|
-
"pos":
|
|
15129
|
-
"end":
|
|
15035
|
+
"pos": 5974,
|
|
15036
|
+
"end": 5979,
|
|
15130
15037
|
"kind": 80,
|
|
15131
15038
|
"id": 0,
|
|
15132
15039
|
"flags": 16842752,
|
|
@@ -15233,8 +15140,8 @@
|
|
|
15233
15140
|
"jsdoctags": [
|
|
15234
15141
|
{
|
|
15235
15142
|
"name": {
|
|
15236
|
-
"pos":
|
|
15237
|
-
"end":
|
|
15143
|
+
"pos": 3815,
|
|
15144
|
+
"end": 3820,
|
|
15238
15145
|
"kind": 80,
|
|
15239
15146
|
"id": 0,
|
|
15240
15147
|
"flags": 16842752,
|
|
@@ -15247,8 +15154,8 @@
|
|
|
15247
15154
|
"deprecated": false,
|
|
15248
15155
|
"deprecationMessage": "",
|
|
15249
15156
|
"tagName": {
|
|
15250
|
-
"pos":
|
|
15251
|
-
"end":
|
|
15157
|
+
"pos": 3809,
|
|
15158
|
+
"end": 3814,
|
|
15252
15159
|
"kind": 80,
|
|
15253
15160
|
"id": 0,
|
|
15254
15161
|
"flags": 16842752,
|
|
@@ -15309,8 +15216,8 @@
|
|
|
15309
15216
|
"jsdoctags": [
|
|
15310
15217
|
{
|
|
15311
15218
|
"name": {
|
|
15312
|
-
"pos":
|
|
15313
|
-
"end":
|
|
15219
|
+
"pos": 4006,
|
|
15220
|
+
"end": 4011,
|
|
15314
15221
|
"kind": 80,
|
|
15315
15222
|
"id": 0,
|
|
15316
15223
|
"flags": 16842752,
|
|
@@ -15323,8 +15230,8 @@
|
|
|
15323
15230
|
"deprecated": false,
|
|
15324
15231
|
"deprecationMessage": "",
|
|
15325
15232
|
"tagName": {
|
|
15326
|
-
"pos":
|
|
15327
|
-
"end":
|
|
15233
|
+
"pos": 4000,
|
|
15234
|
+
"end": 4005,
|
|
15328
15235
|
"kind": 80,
|
|
15329
15236
|
"id": 0,
|
|
15330
15237
|
"flags": 16842752,
|
|
@@ -15335,8 +15242,8 @@
|
|
|
15335
15242
|
},
|
|
15336
15243
|
{
|
|
15337
15244
|
"name": {
|
|
15338
|
-
"pos":
|
|
15339
|
-
"end":
|
|
15245
|
+
"pos": 4026,
|
|
15246
|
+
"end": 4033,
|
|
15340
15247
|
"kind": 80,
|
|
15341
15248
|
"id": 0,
|
|
15342
15249
|
"flags": 16842752,
|
|
@@ -15367,8 +15274,8 @@
|
|
|
15367
15274
|
}
|
|
15368
15275
|
],
|
|
15369
15276
|
"tagName": {
|
|
15370
|
-
"pos":
|
|
15371
|
-
"end":
|
|
15277
|
+
"pos": 4020,
|
|
15278
|
+
"end": 4025,
|
|
15372
15279
|
"kind": 80,
|
|
15373
15280
|
"id": 0,
|
|
15374
15281
|
"flags": 16842752,
|
|
@@ -15476,7 +15383,7 @@
|
|
|
15476
15383
|
"deprecationMessage": "",
|
|
15477
15384
|
"description": "",
|
|
15478
15385
|
"rawdescription": "\n",
|
|
15479
|
-
"sourceCode": "import { Injectable, PLATFORM_ID, inject } from '@angular/core';\nimport { isPlatformBrowser } from '@angular/common';\nimport { Observable, BehaviorSubject } from 'rxjs';\nimport { debounceTime, distinctUntilChanged, filter, map } from 'rxjs/operators';\n\nimport { LogService } from '../log';\nimport { CoreState, DeepPartial, initialCoreState } from '@eui/base';\nimport { isEqual } from 'lodash-es';\nimport { loadState } from './reducers';\n\nexport enum BrowserStorageType {\n local,\n session,\n}\n\nexport type Handler<T> = (state: T[keyof T]) => Partial<T[keyof T]>\n\n// todo should stay here but all the store directory should be moved upper level\n@Injectable({\n providedIn: 'root',\n})\n// TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class StoreService<T = any> {\n protected logService = inject(LogService, { optional: true });\n private platformId = inject(PLATFORM_ID);\n\n /**\n * autoSave handlers to call before saving in local Storage\n */\n protected _autoSaveHandlers:
|
|
15386
|
+
"sourceCode": "import { Injectable, PLATFORM_ID, inject } from '@angular/core';\nimport { isPlatformBrowser } from '@angular/common';\nimport { Observable, BehaviorSubject } from 'rxjs';\nimport { debounceTime, distinctUntilChanged, filter, map } from 'rxjs/operators';\n\nimport { LogService } from '../log';\nimport { CoreState, DeepPartial, initialCoreState } from '@eui/base';\nimport { isEqual } from 'lodash-es';\nimport { loadState } from './reducers';\n\nexport enum BrowserStorageType {\n local,\n session,\n}\n\nexport type Handler<T> = (state: T[keyof T]) => Partial<T[keyof T]>\n\n// todo should stay here but all the store directory should be moved upper level\n@Injectable({\n providedIn: 'root',\n})\n// TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class StoreService<T = any> {\n protected logService = inject(LogService, { optional: true });\n private platformId = inject(PLATFORM_ID);\n\n /**\n * autoSave handlers to call before saving in local Storage\n */\n protected _autoSaveHandlers: Record<string, Handler<T>> = {};\n /** storage instance e.g. localStorage, sessionStorage */\n private _storage: Storage | null = null;\n private state: BehaviorSubject<T>;\n private isHandlingAutoSave = false;\n\n constructor() {\n if (isPlatformBrowser(this.platformId)) {\n try {\n this._storage = localStorage;\n } catch (e) {\n // Storage access blocked (e.g. Firefox Enhanced Tracking Protection)\n this._storage = null;\n }\n }\n\n const initialState = {} as T;\n this.state = new BehaviorSubject<T>(initialState);\n\n // Subscribe to signal changes for auto-save\n this.state.asObservable()\n .pipe(\n filter(() => this.isHandlingAutoSave),\n debounceTime(1000),\n distinctUntilChanged((prev, curr) => isEqual(prev, curr)),\n )\n .subscribe((state) => {\n this.saveState(state as CoreState);\n });\n\n }\n\n init(version?: string, storageType?: BrowserStorageType): void {\n if (isPlatformBrowser(this.platformId)) {\n // This action must be dispatched from an app initializer\n // We load the state from a storage and compare the version and userId with the provided ones.\n // If they are the same, we merge the local state into the initial state.\n // If there is a mismatch, we don't merge the local state, but update only the initial state.\n\n try {\n this._storage = storageType === BrowserStorageType.session ? sessionStorage : localStorage;\n } catch (e) {\n // Storage access blocked (e.g. Firefox Enhanced Tracking Protection)\n this._storage = null;\n }\n\n // load the state from the localStorage\n let localState: CoreState = loadState<CoreState>(this._storage) as CoreState;\n localState = { ...localState, app: { ...localState?.app, version } };\n\n const mergedState = this.deepMerge(localState, { ...initialCoreState }) as T;\n this.updateState(mergedState);\n }\n }\n\n /**\n * Add an autoSave handler for a specific state slice\n * @param stateSlice\n * @param handler\n * @deprecated it will be removed in the next major version\n */\n addAutoSaveHandler(stateSlice: string, handler: Handler<T>): void {\n this._autoSaveHandlers[stateSlice] = handler;\n }\n\n handleAutoSave(): void {\n this.isHandlingAutoSave = true;\n }\n\n /**\n * This method is used to update the state of the service with a new state.\n *\n * @param state\n */\n updateState(state: DeepPartial<T>): void;\n /**\n * @deprecated it will be removed in next version. Use updateState(partialState: DeepPartial<T>) instead\n * @param slice\n * @param reducer\n */\n updateState(slice: DeepPartial<T>, reducer: (state: T, action: DeepPartial<T>) => T): void;\n updateState<K extends T>(state: DeepPartial<K>, reducer?: (state: T, action: DeepPartial<K>) => T): void {\n const currentState = this.state.getValue();\n let newState: T;\n\n if (reducer) {\n newState = reducer(currentState, { ...state });\n } else {\n newState = this.deepMerge<T>(currentState, { ...state });\n }\n this.state.next(newState);\n }\n\n // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n select(key?: any): Observable<T[any]>;\n select<K>(keyOrMapFn?: ((state: T) => K) | string): Observable<Partial<K> | K | undefined> {\n const baseObservable: Observable<T | K> = this.state.asObservable();\n\n if (!keyOrMapFn) {\n return baseObservable as Observable<K>;\n }\n\n if (typeof keyOrMapFn === 'function') {\n return baseObservable.pipe(\n map(state => keyOrMapFn(state as T)),\n distinctUntilChanged((x, y) => isEqual(x, y)),\n );\n }\n\n return baseObservable.pipe(\n map(state => {\n if (!keyOrMapFn) {\n return state;\n }\n\n const keys = keyOrMapFn.split('.');\n return keys.reduce<unknown>((acc, currKey) => {\n const record = acc as Record<string, unknown> | null | undefined;\n return record && record[currKey] !== undefined ? record[currKey] : undefined;\n }, state);\n }),\n distinctUntilChanged((x, y) => isEqual(x, y)),\n ) as unknown as Observable<Partial<K> | K | undefined>;\n }\n\n /**\n * filters and save the state with the Browser storage\n * @param state type of CoreState\n */\n protected saveState(state: CoreState): void {\n let stateToSave: CoreState = {\n app: state.app,\n };\n\n if (state.user) {\n const { userId, preferences } = state.user;\n stateToSave.user = { userId, preferences };\n }\n\n Object.keys(this._autoSaveHandlers).forEach((sliceState: string) => {\n const handler = this._autoSaveHandlers[sliceState];\n stateToSave = Object.assign(stateToSave, { [sliceState]: handler((state as Record<string, unknown>)[sliceState] as T[keyof T]) });\n });\n\n try {\n const serializedState = JSON.stringify(stateToSave);\n this._storage?.setItem('state', serializedState);\n } catch (err) {\n // Ignore write errors.\n }\n }\n\n /**\n * deep merge two objects\n * @param target the object that will be merged into\n * @param source the object that will be merged from\n */\n private deepMerge<T>(target: T, source: DeepPartial<T>): T {\n const output = Object.assign({}, target);\n if (this.isObject(target) && this.isObject(source)) {\n const src = source as Record<string, unknown>;\n const tgt = target as Record<string, unknown>;\n Object.keys(src).forEach(key => {\n if (this.isObject(src[key])) {\n if (!(key in tgt)) {\n Object.assign(output, { [key]: src[key] });\n } else {\n (output as Record<string, unknown>)[key] = this.deepMerge(tgt[key], src[key] as DeepPartial<unknown>);\n }\n } else {\n Object.assign(output, { [key]: src[key] });\n }\n });\n }\n return output;\n }\n\n /**\n * checks if the given item is an object\n * @param item the item that will be checked\n */\n private isObject(item: unknown): item is object {\n return !!item && typeof item === 'object' && !Array.isArray(item);\n }\n\n}\n",
|
|
15480
15387
|
"constructorObj": {
|
|
15481
15388
|
"name": "constructor",
|
|
15482
15389
|
"description": "",
|
|
@@ -15511,12 +15418,11 @@
|
|
|
15511
15418
|
"defaultValue": "{}",
|
|
15512
15419
|
"deprecated": false,
|
|
15513
15420
|
"deprecationMessage": "",
|
|
15514
|
-
"type": "
|
|
15421
|
+
"type": "Record<string, Handler<T>>",
|
|
15515
15422
|
"indexKey": "",
|
|
15516
15423
|
"optional": false,
|
|
15517
15424
|
"description": "<p>autoSave handlers to call before saving in local Storage</p>\n",
|
|
15518
15425
|
"line": 31,
|
|
15519
|
-
"subProperties": [],
|
|
15520
15426
|
"rawdescription": "\n\nautoSave handlers to call before saving in local Storage\n",
|
|
15521
15427
|
"modifierKind": [
|
|
15522
15428
|
124
|
|
@@ -15649,8 +15555,8 @@
|
|
|
15649
15555
|
"jsdoctags": [
|
|
15650
15556
|
{
|
|
15651
15557
|
"name": {
|
|
15652
|
-
"pos":
|
|
15653
|
-
"end":
|
|
15558
|
+
"pos": 5980,
|
|
15559
|
+
"end": 5985,
|
|
15654
15560
|
"kind": 80,
|
|
15655
15561
|
"id": 0,
|
|
15656
15562
|
"flags": 16842752,
|
|
@@ -15663,8 +15569,8 @@
|
|
|
15663
15569
|
"deprecated": false,
|
|
15664
15570
|
"deprecationMessage": "",
|
|
15665
15571
|
"tagName": {
|
|
15666
|
-
"pos":
|
|
15667
|
-
"end":
|
|
15572
|
+
"pos": 5974,
|
|
15573
|
+
"end": 5979,
|
|
15668
15574
|
"kind": 80,
|
|
15669
15575
|
"id": 0,
|
|
15670
15576
|
"flags": 16842752,
|
|
@@ -15702,8 +15608,8 @@
|
|
|
15702
15608
|
"jsdoctags": [
|
|
15703
15609
|
{
|
|
15704
15610
|
"name": {
|
|
15705
|
-
"pos":
|
|
15706
|
-
"end":
|
|
15611
|
+
"pos": 3815,
|
|
15612
|
+
"end": 3820,
|
|
15707
15613
|
"kind": 80,
|
|
15708
15614
|
"id": 0,
|
|
15709
15615
|
"flags": 16842752,
|
|
@@ -15716,8 +15622,8 @@
|
|
|
15716
15622
|
"deprecated": false,
|
|
15717
15623
|
"deprecationMessage": "",
|
|
15718
15624
|
"tagName": {
|
|
15719
|
-
"pos":
|
|
15720
|
-
"end":
|
|
15625
|
+
"pos": 3809,
|
|
15626
|
+
"end": 3814,
|
|
15721
15627
|
"kind": 80,
|
|
15722
15628
|
"id": 0,
|
|
15723
15629
|
"flags": 16842752,
|
|
@@ -17309,7 +17215,7 @@
|
|
|
17309
17215
|
},
|
|
17310
17216
|
{
|
|
17311
17217
|
"name": "EuLoginSessionTimeoutHandlingInterceptor",
|
|
17312
|
-
"id": "injectable-EuLoginSessionTimeoutHandlingInterceptor-
|
|
17218
|
+
"id": "injectable-EuLoginSessionTimeoutHandlingInterceptor-fccb761e8d5849baa5005029d5b63ce5da9abf59e665ab7d08910bd0b4b237bee688744c7650083b0c68eaaeec208267921e73ada3ebc977b8d4265ea729aacf",
|
|
17313
17219
|
"file": "packages/core/src/lib/interceptors/eu-login-session-timeout-handling.interceptor.ts",
|
|
17314
17220
|
"coverageIgnore": false,
|
|
17315
17221
|
"properties": [],
|
|
@@ -17548,7 +17454,7 @@
|
|
|
17548
17454
|
"deprecationMessage": "",
|
|
17549
17455
|
"description": "",
|
|
17550
17456
|
"rawdescription": "\n",
|
|
17551
|
-
"sourceCode": "import { Injectable } from '@angular/core';\nimport { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse, HttpResponseBase } from '@angular/common/http';\nimport { Observable } from 'rxjs';\nimport { tap } from 'rxjs/operators';\n\ninterface body {\n success: boolean;\n status: string;\n code: number;\n message: string;\n}\n\n// The EuLoginSessionTimeoutHandlingInterceptor assumes that the EU login client is configured with:\n// <redirectionInterceptor>eu.cec.digit.ecas.client.http.ajax.JsonAjaxRedirectionInterceptor</redirectionInterceptor>\n// WARNING: The default EU login client behaviour that provides the JSON-un-parsable login HTML page, is no longer supported!\n@Injectable()\nexport class EuLoginSessionTimeoutHandlingInterceptor implements HttpInterceptor {\n intercept<T extends body>(request: HttpRequest<T>, next: HttpHandler): Observable<HttpEvent<T>> {\n return next.handle(request).pipe(\n tap({\n next: (event) => {\n this.checkRequestSuccessForEULoginSessionTimeout(request, event);\n return event;\n },\n error: (error) => {\n this.checkRequestErrorForEULoginSessionTimeout(request, error);\n },\n }),\n );\n }\n\n protected checkRequestSuccessForEULoginSessionTimeout<T extends body, E>(request: HttpRequest<T>, event: HttpEvent<E>): void {\n if (event instanceof HttpResponse) {\n if (this.isSsoResponse((
|
|
17457
|
+
"sourceCode": "import { Injectable } from '@angular/core';\nimport { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse, HttpResponseBase } from '@angular/common/http';\nimport { Observable } from 'rxjs';\nimport { tap } from 'rxjs/operators';\n\ninterface body {\n success: boolean;\n status: string;\n code: number;\n message: string;\n}\n\n// The EuLoginSessionTimeoutHandlingInterceptor assumes that the EU login client is configured with:\n// <redirectionInterceptor>eu.cec.digit.ecas.client.http.ajax.JsonAjaxRedirectionInterceptor</redirectionInterceptor>\n// WARNING: The default EU login client behaviour that provides the JSON-un-parsable login HTML page, is no longer supported!\n@Injectable()\nexport class EuLoginSessionTimeoutHandlingInterceptor implements HttpInterceptor {\n intercept<T extends body>(request: HttpRequest<T>, next: HttpHandler): Observable<HttpEvent<T>> {\n return next.handle(request).pipe(\n tap({\n next: (event) => {\n this.checkRequestSuccessForEULoginSessionTimeout(request, event);\n return event;\n },\n error: (error) => {\n this.checkRequestErrorForEULoginSessionTimeout(request, error);\n },\n }),\n );\n }\n\n protected checkRequestSuccessForEULoginSessionTimeout<T extends body, E>(request: HttpRequest<T>, event: HttpEvent<E>): void {\n if (event instanceof HttpResponse) {\n if (this.isSsoResponse((event as HttpResponse<string | body>).body)) {\n this.reauthenticate();\n }\n }\n }\n\n protected checkRequestErrorForEULoginSessionTimeout<T = unknown>(request: HttpRequest<T>, response: HttpResponseBase): void {\n /* intentionally blank; meant for overriding */\n }\n\n protected isSsoResponse(body: string | body | null): boolean {\n if (body) {\n if (typeof body !== 'string') {\n return (\n body.success === false &&\n body.status === 'ECAS_AUTHENTICATION_REQUIRED' &&\n body.code === 303 &&\n body.message === 'session expired'\n );\n } else {\n const html = body;\n try {\n return (\n (html.indexOf('<meta name=\"Keywords\" content=\"EU Login, ECAS, Authentication, Security\" />') >= 0 &&\n html.indexOf('<meta name=\"Description\" content=\"EU Login\" />') >= 0) ||\n html.indexOf('<meta name=\"Description\" content=\"European Commission Authentication Service\" />') >= 0 ||\n html.indexOf('<title>Mock Login Form</title>') >= 0 ||\n html.indexOf('<title>Redirecting To ECAS</title>') >= 0 ||\n html === '{ success : false, status : \"ECAS_AUTHENTICATION_REQUIRED\", code : 303, message : \"session expired\" }' ||\n \n JSON.stringify(JSON.parse(html)) ===\n JSON.stringify({\n success: false,\n status: 'ECAS_AUTHENTICATION_REQUIRED',\n code: 303,\n message: 'session expired',\n })\n );\n } catch (e) {\n return false;\n }\n }\n } else {\n return false;\n }\n }\n\n protected reauthenticate(): void {\n document.location.reload();\n }\n}\n",
|
|
17552
17458
|
"extends": [],
|
|
17553
17459
|
"type": "interceptor",
|
|
17554
17460
|
"relationships": {
|
|
@@ -20215,13 +20121,13 @@
|
|
|
20215
20121
|
},
|
|
20216
20122
|
{
|
|
20217
20123
|
"name": "EuiAppShellServiceMock",
|
|
20218
|
-
"id": "class-EuiAppShellServiceMock-
|
|
20124
|
+
"id": "class-EuiAppShellServiceMock-f1cdd42c4b46f0a18b3ddb3aa4a4b22aebd7cab7b40ec2b406aa755788998027a191292b57f7041cd1f1f819e61fd8c550b47417e023c812ea2d5df377f76492",
|
|
20219
20125
|
"file": "packages/core/src/lib/mocks/ux-app-shell-service.mock.ts",
|
|
20220
20126
|
"coverageIgnore": false,
|
|
20221
20127
|
"deprecated": false,
|
|
20222
20128
|
"deprecationMessage": "",
|
|
20223
20129
|
"type": "class",
|
|
20224
|
-
"sourceCode": "import { BehaviorSubject, Observable, of } from 'rxjs';\n\nexport class EuiAppShellServiceMock {\n breakpointSubject
|
|
20130
|
+
"sourceCode": "import { BehaviorSubject, Observable, of } from 'rxjs';\n\nexport class EuiAppShellServiceMock {\n breakpointSubject = new BehaviorSubject<string>('');\n\n breakpoints$: Observable<string> = this.breakpointSubject.asObservable();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n state$: Observable<any> = of({});\n\n appRouter = {\n navigate: (url: string): string => url,\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n getState(): Observable<any> {\n return of({});\n }\n\n consumeEvent(): void {\n /* empty */\n }\n}\n",
|
|
20225
20131
|
"displayName": "EuiAppShellServiceMock",
|
|
20226
20132
|
"inputsClass": [],
|
|
20227
20133
|
"outputsClass": [],
|
|
@@ -20255,10 +20161,10 @@
|
|
|
20255
20161
|
{
|
|
20256
20162
|
"name": "breakpointSubject",
|
|
20257
20163
|
"coverageIgnore": false,
|
|
20258
|
-
"defaultValue": "new BehaviorSubject('')",
|
|
20164
|
+
"defaultValue": "new BehaviorSubject<string>('')",
|
|
20259
20165
|
"deprecated": false,
|
|
20260
20166
|
"deprecationMessage": "",
|
|
20261
|
-
"type": "
|
|
20167
|
+
"type": "unknown",
|
|
20262
20168
|
"indexKey": "",
|
|
20263
20169
|
"optional": false,
|
|
20264
20170
|
"description": "",
|
|
@@ -21630,13 +21536,13 @@
|
|
|
21630
21536
|
},
|
|
21631
21537
|
{
|
|
21632
21538
|
"name": "TranslateLoaderMock",
|
|
21633
|
-
"id": "class-TranslateLoaderMock-
|
|
21539
|
+
"id": "class-TranslateLoaderMock-4e142e09c2fb49dd6e2aa331c22b84fb560efa570a17d82a10eff3c15c008e178bccf39722626a097b93a32b8810c81f1464430e56e7ad783b79a70b96300b1e",
|
|
21634
21540
|
"file": "packages/core/src/lib/mocks/translate.module.mock.ts",
|
|
21635
21541
|
"coverageIgnore": false,
|
|
21636
21542
|
"deprecated": false,
|
|
21637
21543
|
"deprecationMessage": "",
|
|
21638
21544
|
"type": "class",
|
|
21639
|
-
"sourceCode": "import {\n AfterViewChecked,\n Directive,\n ElementRef,\n Input,\n NgModule,\n Pipe,\n PipeTransform,\n inject,\n signal,\n input,\n} from '@angular/core';\nimport { LangChangeEvent, TranslateLoader, TranslateService } from '@ngx-translate/core';\nimport { BehaviorSubject, Observable, of, Subject } from 'rxjs';\n\nexport const TRANSLATED_STRING = 'i18n';\nexport const DEFAULT_LANGUAGE = 'en';\n\nexport class TranslateServiceMock {\n onLangChangeSubject
|
|
21545
|
+
"sourceCode": "import {\n AfterViewChecked,\n Directive,\n ElementRef,\n Input,\n NgModule,\n Pipe,\n PipeTransform,\n inject,\n signal,\n input,\n} from '@angular/core';\nimport { LangChangeEvent, TranslateLoader, TranslateService } from '@ngx-translate/core';\nimport { BehaviorSubject, Observable, of, Subject } from 'rxjs';\n\nexport const TRANSLATED_STRING = 'i18n';\nexport const DEFAULT_LANGUAGE = 'en';\n\nexport class TranslateServiceMock {\n onLangChangeSubject = new Subject<LangChangeEvent>();\n onTranslationChangeSubject = new Subject<string>();\n onFallbackLangChangeSubject = new Subject<string>();\n isLoadedSubject = new BehaviorSubject<boolean>(true);\n\n onLangChange: Observable<LangChangeEvent> = this.onLangChangeSubject.asObservable();\n onTranslationChange: Observable<string> = this.onTranslationChangeSubject.asObservable();\n onFallbackLangChange: Observable<string> = this.onFallbackLangChangeSubject.asObservable();\n isLoaded: Observable<boolean> = this.isLoadedSubject.asObservable();\n\n currentLang = signal<string | null>(null);\n\n languages: string[] = [DEFAULT_LANGUAGE];\n\n get(content: string): Observable<string> {\n return of(TRANSLATED_STRING + content);\n }\n\n use(lang: string): void {\n this.currentLang.set(lang);\n this.onLangChangeSubject.next({ lang } as LangChangeEvent);\n }\n\n addLangs(langs: string[]): void {\n this.languages = [...this.languages, ...langs];\n }\n\n getBrowserLang(): string {\n return DEFAULT_LANGUAGE;\n }\n\n getLangs(): string[] {\n return this.languages;\n }\n\n // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n getTranslation(): Observable<any> {\n return of({});\n }\n\n instant(key: string | string[]): string {\n return TRANSLATED_STRING + key.toString();\n }\n\n setFallbackLang(lang: string): void {\n this.onFallbackLangChangeSubject.next(lang);\n }\n}\n\n@Pipe({ name: 'translate' })\nexport class TranslateMockPipe implements PipeTransform {\n transform(text: string): string {\n return !text ? TRANSLATED_STRING : `${text}-${TRANSLATED_STRING}`;\n }\n}\n\n@Directive({\n // eslint-disable-next-line @angular-eslint/directive-selector\n selector: '[translate]',\n})\n \nexport class TranslateMockDirective implements AfterViewChecked {\n readonly translateParams = input();\n\n private readonly _element = inject(ElementRef);\n\n ngAfterViewChecked(): void {\n this._element.nativeElement.innerText += TRANSLATED_STRING;\n }\n}\n\nexport class TranslateLoaderMock implements TranslateLoader {\n getTranslation(): Observable<Record<string, string>> {\n return of({});\n }\n}\n\n@NgModule({\n imports: [TranslateMockPipe, TranslateMockDirective],\n exports: [TranslateMockPipe, TranslateMockDirective],\n providers: [\n { provide: TranslateService, useClass: TranslateServiceMock },\n { provide: TranslateLoader, useClass: TranslateLoaderMock },\n ],\n})\nexport class TranslateMockModule {}\n",
|
|
21640
21546
|
"displayName": "TranslateLoaderMock",
|
|
21641
21547
|
"inputsClass": [],
|
|
21642
21548
|
"outputsClass": [],
|
|
@@ -21675,13 +21581,13 @@
|
|
|
21675
21581
|
},
|
|
21676
21582
|
{
|
|
21677
21583
|
"name": "TranslateServiceMock",
|
|
21678
|
-
"id": "class-TranslateServiceMock-
|
|
21584
|
+
"id": "class-TranslateServiceMock-4e142e09c2fb49dd6e2aa331c22b84fb560efa570a17d82a10eff3c15c008e178bccf39722626a097b93a32b8810c81f1464430e56e7ad783b79a70b96300b1e",
|
|
21679
21585
|
"file": "packages/core/src/lib/mocks/translate.module.mock.ts",
|
|
21680
21586
|
"coverageIgnore": false,
|
|
21681
21587
|
"deprecated": false,
|
|
21682
21588
|
"deprecationMessage": "",
|
|
21683
21589
|
"type": "class",
|
|
21684
|
-
"sourceCode": "import {\n AfterViewChecked,\n Directive,\n ElementRef,\n Input,\n NgModule,\n Pipe,\n PipeTransform,\n inject,\n signal,\n input,\n} from '@angular/core';\nimport { LangChangeEvent, TranslateLoader, TranslateService } from '@ngx-translate/core';\nimport { BehaviorSubject, Observable, of, Subject } from 'rxjs';\n\nexport const TRANSLATED_STRING = 'i18n';\nexport const DEFAULT_LANGUAGE = 'en';\n\nexport class TranslateServiceMock {\n onLangChangeSubject
|
|
21590
|
+
"sourceCode": "import {\n AfterViewChecked,\n Directive,\n ElementRef,\n Input,\n NgModule,\n Pipe,\n PipeTransform,\n inject,\n signal,\n input,\n} from '@angular/core';\nimport { LangChangeEvent, TranslateLoader, TranslateService } from '@ngx-translate/core';\nimport { BehaviorSubject, Observable, of, Subject } from 'rxjs';\n\nexport const TRANSLATED_STRING = 'i18n';\nexport const DEFAULT_LANGUAGE = 'en';\n\nexport class TranslateServiceMock {\n onLangChangeSubject = new Subject<LangChangeEvent>();\n onTranslationChangeSubject = new Subject<string>();\n onFallbackLangChangeSubject = new Subject<string>();\n isLoadedSubject = new BehaviorSubject<boolean>(true);\n\n onLangChange: Observable<LangChangeEvent> = this.onLangChangeSubject.asObservable();\n onTranslationChange: Observable<string> = this.onTranslationChangeSubject.asObservable();\n onFallbackLangChange: Observable<string> = this.onFallbackLangChangeSubject.asObservable();\n isLoaded: Observable<boolean> = this.isLoadedSubject.asObservable();\n\n currentLang = signal<string | null>(null);\n\n languages: string[] = [DEFAULT_LANGUAGE];\n\n get(content: string): Observable<string> {\n return of(TRANSLATED_STRING + content);\n }\n\n use(lang: string): void {\n this.currentLang.set(lang);\n this.onLangChangeSubject.next({ lang } as LangChangeEvent);\n }\n\n addLangs(langs: string[]): void {\n this.languages = [...this.languages, ...langs];\n }\n\n getBrowserLang(): string {\n return DEFAULT_LANGUAGE;\n }\n\n getLangs(): string[] {\n return this.languages;\n }\n\n // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n getTranslation(): Observable<any> {\n return of({});\n }\n\n instant(key: string | string[]): string {\n return TRANSLATED_STRING + key.toString();\n }\n\n setFallbackLang(lang: string): void {\n this.onFallbackLangChangeSubject.next(lang);\n }\n}\n\n@Pipe({ name: 'translate' })\nexport class TranslateMockPipe implements PipeTransform {\n transform(text: string): string {\n return !text ? TRANSLATED_STRING : `${text}-${TRANSLATED_STRING}`;\n }\n}\n\n@Directive({\n // eslint-disable-next-line @angular-eslint/directive-selector\n selector: '[translate]',\n})\n \nexport class TranslateMockDirective implements AfterViewChecked {\n readonly translateParams = input();\n\n private readonly _element = inject(ElementRef);\n\n ngAfterViewChecked(): void {\n this._element.nativeElement.innerText += TRANSLATED_STRING;\n }\n}\n\nexport class TranslateLoaderMock implements TranslateLoader {\n getTranslation(): Observable<Record<string, string>> {\n return of({});\n }\n}\n\n@NgModule({\n imports: [TranslateMockPipe, TranslateMockDirective],\n exports: [TranslateMockPipe, TranslateMockDirective],\n providers: [\n { provide: TranslateService, useClass: TranslateServiceMock },\n { provide: TranslateLoader, useClass: TranslateLoaderMock },\n ],\n})\nexport class TranslateMockModule {}\n",
|
|
21685
21591
|
"displayName": "TranslateServiceMock",
|
|
21686
21592
|
"inputsClass": [],
|
|
21687
21593
|
"outputsClass": [],
|
|
@@ -21715,10 +21621,10 @@
|
|
|
21715
21621
|
{
|
|
21716
21622
|
"name": "isLoadedSubject",
|
|
21717
21623
|
"coverageIgnore": false,
|
|
21718
|
-
"defaultValue": "new BehaviorSubject(true)",
|
|
21624
|
+
"defaultValue": "new BehaviorSubject<boolean>(true)",
|
|
21719
21625
|
"deprecated": false,
|
|
21720
21626
|
"deprecationMessage": "",
|
|
21721
|
-
"type": "
|
|
21627
|
+
"type": "unknown",
|
|
21722
21628
|
"indexKey": "",
|
|
21723
21629
|
"optional": false,
|
|
21724
21630
|
"description": "",
|
|
@@ -21754,10 +21660,10 @@
|
|
|
21754
21660
|
{
|
|
21755
21661
|
"name": "onFallbackLangChangeSubject",
|
|
21756
21662
|
"coverageIgnore": false,
|
|
21757
|
-
"defaultValue": "new Subject()",
|
|
21663
|
+
"defaultValue": "new Subject<string>()",
|
|
21758
21664
|
"deprecated": false,
|
|
21759
21665
|
"deprecationMessage": "",
|
|
21760
|
-
"type": "
|
|
21666
|
+
"type": "unknown",
|
|
21761
21667
|
"indexKey": "",
|
|
21762
21668
|
"optional": false,
|
|
21763
21669
|
"description": "",
|
|
@@ -21780,10 +21686,10 @@
|
|
|
21780
21686
|
{
|
|
21781
21687
|
"name": "onLangChangeSubject",
|
|
21782
21688
|
"coverageIgnore": false,
|
|
21783
|
-
"defaultValue": "new Subject()",
|
|
21689
|
+
"defaultValue": "new Subject<LangChangeEvent>()",
|
|
21784
21690
|
"deprecated": false,
|
|
21785
21691
|
"deprecationMessage": "",
|
|
21786
|
-
"type": "
|
|
21692
|
+
"type": "unknown",
|
|
21787
21693
|
"indexKey": "",
|
|
21788
21694
|
"optional": false,
|
|
21789
21695
|
"description": "",
|
|
@@ -21806,10 +21712,10 @@
|
|
|
21806
21712
|
{
|
|
21807
21713
|
"name": "onTranslationChangeSubject",
|
|
21808
21714
|
"coverageIgnore": false,
|
|
21809
|
-
"defaultValue": "new Subject()",
|
|
21715
|
+
"defaultValue": "new Subject<string>()",
|
|
21810
21716
|
"deprecated": false,
|
|
21811
21717
|
"deprecationMessage": "",
|
|
21812
|
-
"type": "
|
|
21718
|
+
"type": "unknown",
|
|
21813
21719
|
"indexKey": "",
|
|
21814
21720
|
"optional": false,
|
|
21815
21721
|
"description": "",
|
|
@@ -23138,12 +23044,12 @@
|
|
|
23138
23044
|
"directives": [
|
|
23139
23045
|
{
|
|
23140
23046
|
"name": "TranslateMockDirective",
|
|
23141
|
-
"id": "directive-TranslateMockDirective-
|
|
23047
|
+
"id": "directive-TranslateMockDirective-4e142e09c2fb49dd6e2aa331c22b84fb560efa570a17d82a10eff3c15c008e178bccf39722626a097b93a32b8810c81f1464430e56e7ad783b79a70b96300b1e",
|
|
23142
23048
|
"file": "packages/core/src/lib/mocks/translate.module.mock.ts",
|
|
23143
23049
|
"type": "directive",
|
|
23144
23050
|
"description": "",
|
|
23145
23051
|
"rawdescription": "\n",
|
|
23146
|
-
"sourceCode": "import {\n AfterViewChecked,\n Directive,\n ElementRef,\n Input,\n NgModule,\n Pipe,\n PipeTransform,\n inject,\n signal,\n input,\n} from '@angular/core';\nimport { LangChangeEvent, TranslateLoader, TranslateService } from '@ngx-translate/core';\nimport { BehaviorSubject, Observable, of, Subject } from 'rxjs';\n\nexport const TRANSLATED_STRING = 'i18n';\nexport const DEFAULT_LANGUAGE = 'en';\n\nexport class TranslateServiceMock {\n onLangChangeSubject
|
|
23052
|
+
"sourceCode": "import {\n AfterViewChecked,\n Directive,\n ElementRef,\n Input,\n NgModule,\n Pipe,\n PipeTransform,\n inject,\n signal,\n input,\n} from '@angular/core';\nimport { LangChangeEvent, TranslateLoader, TranslateService } from '@ngx-translate/core';\nimport { BehaviorSubject, Observable, of, Subject } from 'rxjs';\n\nexport const TRANSLATED_STRING = 'i18n';\nexport const DEFAULT_LANGUAGE = 'en';\n\nexport class TranslateServiceMock {\n onLangChangeSubject = new Subject<LangChangeEvent>();\n onTranslationChangeSubject = new Subject<string>();\n onFallbackLangChangeSubject = new Subject<string>();\n isLoadedSubject = new BehaviorSubject<boolean>(true);\n\n onLangChange: Observable<LangChangeEvent> = this.onLangChangeSubject.asObservable();\n onTranslationChange: Observable<string> = this.onTranslationChangeSubject.asObservable();\n onFallbackLangChange: Observable<string> = this.onFallbackLangChangeSubject.asObservable();\n isLoaded: Observable<boolean> = this.isLoadedSubject.asObservable();\n\n currentLang = signal<string | null>(null);\n\n languages: string[] = [DEFAULT_LANGUAGE];\n\n get(content: string): Observable<string> {\n return of(TRANSLATED_STRING + content);\n }\n\n use(lang: string): void {\n this.currentLang.set(lang);\n this.onLangChangeSubject.next({ lang } as LangChangeEvent);\n }\n\n addLangs(langs: string[]): void {\n this.languages = [...this.languages, ...langs];\n }\n\n getBrowserLang(): string {\n return DEFAULT_LANGUAGE;\n }\n\n getLangs(): string[] {\n return this.languages;\n }\n\n // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n getTranslation(): Observable<any> {\n return of({});\n }\n\n instant(key: string | string[]): string {\n return TRANSLATED_STRING + key.toString();\n }\n\n setFallbackLang(lang: string): void {\n this.onFallbackLangChangeSubject.next(lang);\n }\n}\n\n@Pipe({ name: 'translate' })\nexport class TranslateMockPipe implements PipeTransform {\n transform(text: string): string {\n return !text ? TRANSLATED_STRING : `${text}-${TRANSLATED_STRING}`;\n }\n}\n\n@Directive({\n // eslint-disable-next-line @angular-eslint/directive-selector\n selector: '[translate]',\n})\n \nexport class TranslateMockDirective implements AfterViewChecked {\n readonly translateParams = input();\n\n private readonly _element = inject(ElementRef);\n\n ngAfterViewChecked(): void {\n this._element.nativeElement.innerText += TRANSLATED_STRING;\n }\n}\n\nexport class TranslateLoaderMock implements TranslateLoader {\n getTranslation(): Observable<Record<string, string>> {\n return of({});\n }\n}\n\n@NgModule({\n imports: [TranslateMockPipe, TranslateMockDirective],\n exports: [TranslateMockPipe, TranslateMockDirective],\n providers: [\n { provide: TranslateService, useClass: TranslateServiceMock },\n { provide: TranslateLoader, useClass: TranslateLoaderMock },\n ],\n})\nexport class TranslateMockModule {}\n",
|
|
23147
23053
|
"selector": "[translate]",
|
|
23148
23054
|
"providers": [],
|
|
23149
23055
|
"hostDirectives": [],
|
|
@@ -24029,13 +23935,13 @@
|
|
|
24029
23935
|
},
|
|
24030
23936
|
{
|
|
24031
23937
|
"name": "TranslateMockModule",
|
|
24032
|
-
"id": "module-TranslateMockModule-
|
|
23938
|
+
"id": "module-TranslateMockModule-4e142e09c2fb49dd6e2aa331c22b84fb560efa570a17d82a10eff3c15c008e178bccf39722626a097b93a32b8810c81f1464430e56e7ad783b79a70b96300b1e",
|
|
24033
23939
|
"description": "",
|
|
24034
23940
|
"deprecationMessage": "",
|
|
24035
23941
|
"deprecated": false,
|
|
24036
23942
|
"file": "packages/core/src/lib/mocks/translate.module.mock.ts",
|
|
24037
23943
|
"methods": [],
|
|
24038
|
-
"sourceCode": "/* istanbul ignore file */\n\nimport {\n AfterViewChecked,\n Directive,\n ElementRef,\n Input,\n NgModule,\n Pipe,\n PipeTransform,\n inject,\n signal,\n input,\n} from '@angular/core';\nimport { LangChangeEvent, TranslateLoader, TranslateService } from '@ngx-translate/core';\nimport { BehaviorSubject, Observable, of, Subject } from 'rxjs';\n\nexport const TRANSLATED_STRING = 'i18n';\nexport const DEFAULT_LANGUAGE = 'en';\n\nexport class TranslateServiceMock {\n onLangChangeSubject
|
|
23944
|
+
"sourceCode": "/* istanbul ignore file */\n\nimport {\n AfterViewChecked,\n Directive,\n ElementRef,\n Input,\n NgModule,\n Pipe,\n PipeTransform,\n inject,\n signal,\n input,\n} from '@angular/core';\nimport { LangChangeEvent, TranslateLoader, TranslateService } from '@ngx-translate/core';\nimport { BehaviorSubject, Observable, of, Subject } from 'rxjs';\n\nexport const TRANSLATED_STRING = 'i18n';\nexport const DEFAULT_LANGUAGE = 'en';\n\nexport class TranslateServiceMock {\n onLangChangeSubject = new Subject<LangChangeEvent>();\n onTranslationChangeSubject = new Subject<string>();\n onFallbackLangChangeSubject = new Subject<string>();\n isLoadedSubject = new BehaviorSubject<boolean>(true);\n\n onLangChange: Observable<LangChangeEvent> = this.onLangChangeSubject.asObservable();\n onTranslationChange: Observable<string> = this.onTranslationChangeSubject.asObservable();\n onFallbackLangChange: Observable<string> = this.onFallbackLangChangeSubject.asObservable();\n isLoaded: Observable<boolean> = this.isLoadedSubject.asObservable();\n\n currentLang = signal<string | null>(null);\n\n languages: string[] = [DEFAULT_LANGUAGE];\n\n get(content: string): Observable<string> {\n return of(TRANSLATED_STRING + content);\n }\n\n use(lang: string): void {\n this.currentLang.set(lang);\n this.onLangChangeSubject.next({ lang } as LangChangeEvent);\n }\n\n addLangs(langs: string[]): void {\n this.languages = [...this.languages, ...langs];\n }\n\n getBrowserLang(): string {\n return DEFAULT_LANGUAGE;\n }\n\n getLangs(): string[] {\n return this.languages;\n }\n\n // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n getTranslation(): Observable<any> {\n return of({});\n }\n\n instant(key: string | string[]): string {\n return TRANSLATED_STRING + key.toString();\n }\n\n setFallbackLang(lang: string): void {\n this.onFallbackLangChangeSubject.next(lang);\n }\n}\n\n@Pipe({ name: 'translate' })\nexport class TranslateMockPipe implements PipeTransform {\n transform(text: string): string {\n return !text ? TRANSLATED_STRING : `${text}-${TRANSLATED_STRING}`;\n }\n}\n\n@Directive({\n // eslint-disable-next-line @angular-eslint/directive-selector\n selector: '[translate]',\n})\n \nexport class TranslateMockDirective implements AfterViewChecked {\n readonly translateParams = input();\n\n private readonly _element = inject(ElementRef);\n\n ngAfterViewChecked(): void {\n this._element.nativeElement.innerText += TRANSLATED_STRING;\n }\n}\n\nexport class TranslateLoaderMock implements TranslateLoader {\n getTranslation(): Observable<Record<string, string>> {\n return of({});\n }\n}\n\n@NgModule({\n imports: [TranslateMockPipe, TranslateMockDirective],\n exports: [TranslateMockPipe, TranslateMockDirective],\n providers: [\n { provide: TranslateService, useClass: TranslateServiceMock },\n { provide: TranslateLoader, useClass: TranslateLoaderMock },\n ],\n})\nexport class TranslateMockModule {}\n",
|
|
24039
23945
|
"children": [
|
|
24040
23946
|
{
|
|
24041
23947
|
"type": "providers",
|
|
@@ -24088,7 +23994,7 @@
|
|
|
24088
23994
|
"coverageIgnore": false,
|
|
24089
23995
|
"deprecated": false,
|
|
24090
23996
|
"deprecationMessage": "",
|
|
24091
|
-
"type": "
|
|
23997
|
+
"type": "Record<string, AppState>",
|
|
24092
23998
|
"defaultValue": "{\n [CoreAppActionTypes.UPDATE_APP_VERSION]: updateAppVersion,\n [CoreAppActionTypes.UPDATE_APP_CONNECTION]: updateAppConnection,\n [CoreAppActionTypes.UPDATE_APP_STATUS]: updateAppStatus,\n [CoreAppActionTypes.UPDATE_CURRENT_MODULE]: updateCurrentModule,\n [CoreAppActionTypes.ADD_API_QUEUE_ITEM]: addApiQueueItem,\n [CoreAppActionTypes.REMOVE_API_QUEUE_ITEM]: removeApiQueueItem,\n [CoreAppActionTypes.EMPTY_API_QUEUE]: emptyApiQueue,\n}"
|
|
24093
23999
|
},
|
|
24094
24000
|
{
|
|
@@ -24099,7 +24005,7 @@
|
|
|
24099
24005
|
"coverageIgnore": false,
|
|
24100
24006
|
"deprecated": true,
|
|
24101
24007
|
"deprecationMessage": "it will be removed in the next major version",
|
|
24102
|
-
"type": "
|
|
24008
|
+
"type": "Record<string, I18nState>",
|
|
24103
24009
|
"defaultValue": "{\n [CoreI18nActionTypes.UPDATE_I18N_STATE]: updateI18nState,\n}"
|
|
24104
24010
|
},
|
|
24105
24011
|
{
|
|
@@ -24110,7 +24016,7 @@
|
|
|
24110
24016
|
"coverageIgnore": false,
|
|
24111
24017
|
"deprecated": true,
|
|
24112
24018
|
"deprecationMessage": "it will be removed in the next major version",
|
|
24113
|
-
"type": "
|
|
24019
|
+
"type": "Record<string, LocaleState>",
|
|
24114
24020
|
"defaultValue": "{\n [CoreLocaleActionTypes.UPDATE_LOCALE_STATE]: updateLocaleState,\n}"
|
|
24115
24021
|
},
|
|
24116
24022
|
{
|
|
@@ -24121,7 +24027,7 @@
|
|
|
24121
24027
|
"coverageIgnore": false,
|
|
24122
24028
|
"deprecated": false,
|
|
24123
24029
|
"deprecationMessage": "",
|
|
24124
|
-
"type": "
|
|
24030
|
+
"type": "Record<string, NotificationsState>",
|
|
24125
24031
|
"defaultValue": "{\n [CoreNotificationsActionTypes.UPDATE_NOTIFICATIONS_LIST]: updateNotificationsList,\n}"
|
|
24126
24032
|
},
|
|
24127
24033
|
{
|
|
@@ -24132,7 +24038,7 @@
|
|
|
24132
24038
|
"coverageIgnore": false,
|
|
24133
24039
|
"deprecated": false,
|
|
24134
24040
|
"deprecationMessage": "",
|
|
24135
|
-
"type": "
|
|
24041
|
+
"type": "Record<string, UserState>",
|
|
24136
24042
|
"defaultValue": "{\n [CoreUserActionTypes.UPDATE_USER_DETAILS]: updateUserDetails,\n [CoreUserActionTypes.UPDATE_USER_PREFERENCES]: updateUserPreferences,\n [CoreUserActionTypes.UPDATE_USER_STATE]: updateUser,\n [CoreUserActionTypes.UPDATE_USER_RIGHTS]: updateUserRights,\n [CoreUserActionTypes.UPDATE_USER_DASHBOARD]: updateUserDashboard,\n}"
|
|
24137
24043
|
},
|
|
24138
24044
|
{
|
|
@@ -24941,7 +24847,7 @@
|
|
|
24941
24847
|
"deprecated": false,
|
|
24942
24848
|
"deprecationMessage": "",
|
|
24943
24849
|
"type": "unknown",
|
|
24944
|
-
"defaultValue": "(value: number | string, fractionSize = 2, inDecimalSeparator = ',', inThousandSeparator = ''): string | null => {\n // in case value is not a number throw an error\n if (typeof value === 'string' && isNaN(parseFloat(value))) {\n return null;\n }\n\n let decimalSeparator = '';\n let thousandsSeparator = '';\n\n if (value === null || value === undefined) {\n return null;\n }\n\n if (typeof value === 'string') {\n // get all non characters\n const nonChars: string[] = value.match(/\\D+/g) || [];\n\n // get all unique chars\n const uniqueChars = nonChars.reduce((acc, e) => acc.set(e, (acc.get(e) || 0) + 1), new Map());\n\n // get separators\n const separators = Array.from<string>(uniqueChars.keys());\n\n // sense where decimal separator and where a thousand separator is\n if (separators.length > 1) {\n // left detected separator will be a thousand and second will be decimal\n thousandsSeparator = separators[0];\n decimalSeparator = separators[1];\n } else if (separators.length > 0) {\n // in case there is only one separator you don't know exactly who this separator is.\n // in case there are more than two occurrences means we have a thousand otherwise we'll\n // agree by conventions that is decimal\n if (nonChars.length > 1) {\n return value\n .split(separators[0])\n .join('')\n .replace(/\\B(?=(\\d{3})+(?!\\d))/g, inThousandSeparator);\n } else {\n return value.replace(separators[0], inDecimalSeparator).replace(/\\B(?=(\\d{3})+(?!\\d))/g, inThousandSeparator);\n }\n } else {\n // in case there are no separators then only format based on thousand one\n return value.replace(/\\B(?=(\\d{3})+(?!\\d))/g, inThousandSeparator) + (fractionSize > 0 ? inDecimalSeparator + '0'.repeat(fractionSize) : '');\n }\n\n // do the replacement of separators and parseInt\n // Beware! Always replace a thousand separator first and then decimal\n value = value.split(thousandsSeparator).join('').replace(decimalSeparator, '.');\n }\n\n decimalSeparator = inDecimalSeparator;\n thousandsSeparator = inThousandSeparator;\n\n const maxFraction = '0'.repeat(fractionSize);\n\n
|
|
24850
|
+
"defaultValue": "(value: number | string, fractionSize = 2, inDecimalSeparator = ',', inThousandSeparator = ''): string | null => {\n // in case value is not a number throw an error\n if (typeof value === 'string' && isNaN(parseFloat(value))) {\n return null;\n }\n\n let decimalSeparator = '';\n let thousandsSeparator = '';\n\n if (value === null || value === undefined) {\n return null;\n }\n\n if (typeof value === 'string') {\n // get all non characters\n const nonChars: string[] = value.match(/\\D+/g) || [];\n\n // get all unique chars\n const uniqueChars = nonChars.reduce((acc, e) => acc.set(e, (acc.get(e) || 0) + 1), new Map());\n\n // get separators\n const separators = Array.from<string>(uniqueChars.keys());\n\n // sense where decimal separator and where a thousand separator is\n if (separators.length > 1) {\n // left detected separator will be a thousand and second will be decimal\n thousandsSeparator = separators[0];\n decimalSeparator = separators[1];\n } else if (separators.length > 0) {\n // in case there is only one separator you don't know exactly who this separator is.\n // in case there are more than two occurrences means we have a thousand otherwise we'll\n // agree by conventions that is decimal\n if (nonChars.length > 1) {\n return value\n .split(separators[0])\n .join('')\n .replace(/\\B(?=(\\d{3})+(?!\\d))/g, inThousandSeparator);\n } else {\n return value.replace(separators[0], inDecimalSeparator).replace(/\\B(?=(\\d{3})+(?!\\d))/g, inThousandSeparator);\n }\n } else {\n // in case there are no separators then only format based on thousand one\n return value.replace(/\\B(?=(\\d{3})+(?!\\d))/g, inThousandSeparator) + (fractionSize > 0 ? inDecimalSeparator + '0'.repeat(fractionSize) : '');\n }\n\n // do the replacement of separators and parseInt\n // Beware! Always replace a thousand separator first and then decimal\n value = value.split(thousandsSeparator).join('').replace(decimalSeparator, '.');\n }\n\n decimalSeparator = inDecimalSeparator;\n thousandsSeparator = inThousandSeparator;\n\n const maxFraction = '0'.repeat(fractionSize);\n \n let [integer, fraction = maxFraction] = (value || '0').toString().split('.');\n fraction = fractionSize > 0 ? roundUpNumber(fraction + maxFraction, fractionSize) : '';\n\n // this rule makes sense only in number in case fraction is all zero\n fraction = fraction.length > 0 ? decimalSeparator + fraction : '';\n\n // if fraction is all zero then round up the number\n if(fractionSize === 0) {\n integer = Math.round(parseFloat((value).toString())).toString();\n }\n\n return integer.replace(/\\B(?=(\\d{3})+(?!\\d))/g, thousandsSeparator) + fraction;\n}",
|
|
24945
24851
|
"rawdescription": "Its job is to parse number and format it based on given input.",
|
|
24946
24852
|
"description": "<p>Its job is to parse number and format it based on given input.</p>\n"
|
|
24947
24853
|
},
|
|
@@ -25179,7 +25085,7 @@
|
|
|
25179
25085
|
"deprecated": false,
|
|
25180
25086
|
"deprecationMessage": "",
|
|
25181
25087
|
"type": "unknown",
|
|
25182
|
-
"defaultValue": "<T>(value: T | undefined | null): value is T =>
|
|
25088
|
+
"defaultValue": "<T>(value: T | undefined | null): value is T => value as T !== undefined && value as T !== null",
|
|
25183
25089
|
"rawdescription": "check if a value is null or undefined. If it's not both returns true otherwise false",
|
|
25184
25090
|
"description": "<p>check if a value is null or undefined. If it's not both returns true otherwise false</p>\n"
|
|
25185
25091
|
},
|
|
@@ -25358,7 +25264,7 @@
|
|
|
25358
25264
|
"deprecated": false,
|
|
25359
25265
|
"deprecationMessage": "",
|
|
25360
25266
|
"type": "unknown",
|
|
25361
|
-
"defaultValue": "(FormControls:
|
|
25267
|
+
"defaultValue": "(FormControls: Record<string, AbstractControl> | AbstractControl[]): void => {\n const forOwn = (object: unknown, iteratee: (value: AbstractControl, key: string, object: Record<string, AbstractControl>) => void): void => {\n const obj = Object(object) as Record<string, AbstractControl>;\n Object.keys(obj).forEach((key) => iteratee(obj[key], key, obj));\n };\n\n const markFormGroupTouchedRecursive = (controls: Record<string, AbstractControl> | AbstractControl[]): void => {\n forOwn(controls, (c: AbstractControl) => {\n if (c instanceof FormGroup || c instanceof FormArray) {\n markFormGroupTouchedRecursive(c.controls);\n } else {\n c.markAsTouched();\n c.updateValueAndValidity();\n }\n });\n };\n markFormGroupTouchedRecursive(FormControls);\n}"
|
|
25362
25268
|
},
|
|
25363
25269
|
{
|
|
25364
25270
|
"name": "messages",
|
|
@@ -26605,7 +26511,7 @@
|
|
|
26605
26511
|
"deprecated": false,
|
|
26606
26512
|
"deprecationMessage": "",
|
|
26607
26513
|
"type": "unknown",
|
|
26608
|
-
"defaultValue": "(c: FormControl): { validateEmail: { valid: boolean } } | null => {\n const EMAIL_REGEXP =\n // eslint-disable-next-line
|
|
26514
|
+
"defaultValue": "(c: FormControl): { validateEmail: { valid: boolean } } | null => {\n const EMAIL_REGEXP =\n // eslint-disable-next-line no-useless-escape\n /^(([^<>()\\[\\]\\\\.,;:\\s@\"]+(\\.[^<>()\\[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/;\n\n const error = {\n validateEmail: {\n valid: false,\n },\n };\n return EMAIL_REGEXP.test(c.value) ? null : error;\n}"
|
|
26609
26515
|
},
|
|
26610
26516
|
{
|
|
26611
26517
|
"name": "VARIANT",
|
|
@@ -31332,8 +31238,8 @@
|
|
|
31332
31238
|
"jsdoctags": [
|
|
31333
31239
|
{
|
|
31334
31240
|
"name": {
|
|
31335
|
-
"pos":
|
|
31336
|
-
"end":
|
|
31241
|
+
"pos": 5131,
|
|
31242
|
+
"end": 5138,
|
|
31337
31243
|
"kind": 80,
|
|
31338
31244
|
"id": 0,
|
|
31339
31245
|
"flags": 16777216,
|
|
@@ -31344,8 +31250,8 @@
|
|
|
31344
31250
|
"deprecated": false,
|
|
31345
31251
|
"deprecationMessage": "",
|
|
31346
31252
|
"tagName": {
|
|
31347
|
-
"pos":
|
|
31348
|
-
"end":
|
|
31253
|
+
"pos": 5125,
|
|
31254
|
+
"end": 5130,
|
|
31349
31255
|
"kind": 80,
|
|
31350
31256
|
"id": 0,
|
|
31351
31257
|
"flags": 16777216,
|
|
@@ -31356,8 +31262,8 @@
|
|
|
31356
31262
|
},
|
|
31357
31263
|
{
|
|
31358
31264
|
"name": {
|
|
31359
|
-
"pos":
|
|
31360
|
-
"end":
|
|
31265
|
+
"pos": 5188,
|
|
31266
|
+
"end": 5195,
|
|
31361
31267
|
"kind": 80,
|
|
31362
31268
|
"id": 0,
|
|
31363
31269
|
"flags": 16777216,
|
|
@@ -31369,8 +31275,8 @@
|
|
|
31369
31275
|
"deprecationMessage": "",
|
|
31370
31276
|
"defaultValue": "{\n stateFn: defaultStateFn,\n }",
|
|
31371
31277
|
"tagName": {
|
|
31372
|
-
"pos":
|
|
31373
|
-
"end":
|
|
31278
|
+
"pos": 5182,
|
|
31279
|
+
"end": 5187,
|
|
31374
31280
|
"kind": 80,
|
|
31375
31281
|
"id": 0,
|
|
31376
31282
|
"flags": 16777216,
|
|
@@ -37560,7 +37466,6 @@
|
|
|
37560
37466
|
},
|
|
37561
37467
|
{
|
|
37562
37468
|
"name": "merge",
|
|
37563
|
-
"type": "Array",
|
|
37564
37469
|
"deprecated": false,
|
|
37565
37470
|
"deprecationMessage": ""
|
|
37566
37471
|
},
|
|
@@ -37592,7 +37497,6 @@
|
|
|
37592
37497
|
},
|
|
37593
37498
|
{
|
|
37594
37499
|
"name": "merge",
|
|
37595
|
-
"type": "Array",
|
|
37596
37500
|
"deprecated": false,
|
|
37597
37501
|
"deprecationMessage": "",
|
|
37598
37502
|
"tagName": {
|
|
@@ -48272,6 +48176,19 @@
|
|
|
48272
48176
|
}
|
|
48273
48177
|
],
|
|
48274
48178
|
"typealiases": [
|
|
48179
|
+
{
|
|
48180
|
+
"name": "ActionReducer",
|
|
48181
|
+
"ctype": "miscellaneous",
|
|
48182
|
+
"subtype": "typealias",
|
|
48183
|
+
"coverageIgnore": false,
|
|
48184
|
+
"rawtype": "function",
|
|
48185
|
+
"file": "packages/core/src/lib/services/store/ngrx_kit.ts",
|
|
48186
|
+
"deprecated": false,
|
|
48187
|
+
"deprecationMessage": "",
|
|
48188
|
+
"rawdescription": "A function that takes an `Action` and a `State`, and returns a `State`.\nSee `createReducer`.",
|
|
48189
|
+
"description": "<p>A function that takes an <code>Action</code> and a <code>State</code>, and returns a <code>State</code>.\nSee <code>createReducer</code>.</p>\n",
|
|
48190
|
+
"kind": 185
|
|
48191
|
+
},
|
|
48275
48192
|
{
|
|
48276
48193
|
"name": "ActionReducerMap",
|
|
48277
48194
|
"ctype": "miscellaneous",
|
|
@@ -48492,6 +48409,19 @@
|
|
|
48492
48409
|
"rawdescription": "",
|
|
48493
48410
|
"description": "",
|
|
48494
48411
|
"kind": 185
|
|
48412
|
+
},
|
|
48413
|
+
{
|
|
48414
|
+
"name": "TranslationKeys",
|
|
48415
|
+
"ctype": "miscellaneous",
|
|
48416
|
+
"subtype": "typealias",
|
|
48417
|
+
"coverageIgnore": false,
|
|
48418
|
+
"rawtype": "Record<string | string>",
|
|
48419
|
+
"file": "packages/core/src/lib/services/i18n/i18n.loader.ts",
|
|
48420
|
+
"deprecated": false,
|
|
48421
|
+
"deprecationMessage": "",
|
|
48422
|
+
"rawdescription": "",
|
|
48423
|
+
"description": "",
|
|
48424
|
+
"kind": 184
|
|
48495
48425
|
}
|
|
48496
48426
|
],
|
|
48497
48427
|
"enumerations": [
|
|
@@ -48786,7 +48716,7 @@
|
|
|
48786
48716
|
"coverageIgnore": false,
|
|
48787
48717
|
"deprecated": false,
|
|
48788
48718
|
"deprecationMessage": "",
|
|
48789
|
-
"type": "
|
|
48719
|
+
"type": "Record<string, AppState>",
|
|
48790
48720
|
"defaultValue": "{\n [CoreAppActionTypes.UPDATE_APP_VERSION]: updateAppVersion,\n [CoreAppActionTypes.UPDATE_APP_CONNECTION]: updateAppConnection,\n [CoreAppActionTypes.UPDATE_APP_STATUS]: updateAppStatus,\n [CoreAppActionTypes.UPDATE_CURRENT_MODULE]: updateCurrentModule,\n [CoreAppActionTypes.ADD_API_QUEUE_ITEM]: addApiQueueItem,\n [CoreAppActionTypes.REMOVE_API_QUEUE_ITEM]: removeApiQueueItem,\n [CoreAppActionTypes.EMPTY_API_QUEUE]: emptyApiQueue,\n}"
|
|
48791
48721
|
},
|
|
48792
48722
|
{
|
|
@@ -48887,7 +48817,7 @@
|
|
|
48887
48817
|
"coverageIgnore": false,
|
|
48888
48818
|
"deprecated": true,
|
|
48889
48819
|
"deprecationMessage": "it will be removed in the next major version",
|
|
48890
|
-
"type": "
|
|
48820
|
+
"type": "Record<string, I18nState>",
|
|
48891
48821
|
"defaultValue": "{\n [CoreI18nActionTypes.UPDATE_I18N_STATE]: updateI18nState,\n}"
|
|
48892
48822
|
},
|
|
48893
48823
|
{
|
|
@@ -48922,7 +48852,7 @@
|
|
|
48922
48852
|
"coverageIgnore": false,
|
|
48923
48853
|
"deprecated": true,
|
|
48924
48854
|
"deprecationMessage": "it will be removed in the next major version",
|
|
48925
|
-
"type": "
|
|
48855
|
+
"type": "Record<string, LocaleState>",
|
|
48926
48856
|
"defaultValue": "{\n [CoreLocaleActionTypes.UPDATE_LOCALE_STATE]: updateLocaleState,\n}"
|
|
48927
48857
|
},
|
|
48928
48858
|
{
|
|
@@ -48957,7 +48887,7 @@
|
|
|
48957
48887
|
"coverageIgnore": false,
|
|
48958
48888
|
"deprecated": false,
|
|
48959
48889
|
"deprecationMessage": "",
|
|
48960
|
-
"type": "
|
|
48890
|
+
"type": "Record<string, NotificationsState>",
|
|
48961
48891
|
"defaultValue": "{\n [CoreNotificationsActionTypes.UPDATE_NOTIFICATIONS_LIST]: updateNotificationsList,\n}"
|
|
48962
48892
|
},
|
|
48963
48893
|
{
|
|
@@ -48992,7 +48922,7 @@
|
|
|
48992
48922
|
"coverageIgnore": false,
|
|
48993
48923
|
"deprecated": false,
|
|
48994
48924
|
"deprecationMessage": "",
|
|
48995
|
-
"type": "
|
|
48925
|
+
"type": "Record<string, UserState>",
|
|
48996
48926
|
"defaultValue": "{\n [CoreUserActionTypes.UPDATE_USER_DETAILS]: updateUserDetails,\n [CoreUserActionTypes.UPDATE_USER_PREFERENCES]: updateUserPreferences,\n [CoreUserActionTypes.UPDATE_USER_STATE]: updateUser,\n [CoreUserActionTypes.UPDATE_USER_RIGHTS]: updateUserRights,\n [CoreUserActionTypes.UPDATE_USER_DASHBOARD]: updateUserDashboard,\n}"
|
|
48997
48927
|
},
|
|
48998
48928
|
{
|
|
@@ -50534,7 +50464,7 @@
|
|
|
50534
50464
|
"deprecated": false,
|
|
50535
50465
|
"deprecationMessage": "",
|
|
50536
50466
|
"type": "unknown",
|
|
50537
|
-
"defaultValue": "(value: number | string, fractionSize = 2, inDecimalSeparator = ',', inThousandSeparator = ''): string | null => {\n // in case value is not a number throw an error\n if (typeof value === 'string' && isNaN(parseFloat(value))) {\n return null;\n }\n\n let decimalSeparator = '';\n let thousandsSeparator = '';\n\n if (value === null || value === undefined) {\n return null;\n }\n\n if (typeof value === 'string') {\n // get all non characters\n const nonChars: string[] = value.match(/\\D+/g) || [];\n\n // get all unique chars\n const uniqueChars = nonChars.reduce((acc, e) => acc.set(e, (acc.get(e) || 0) + 1), new Map());\n\n // get separators\n const separators = Array.from<string>(uniqueChars.keys());\n\n // sense where decimal separator and where a thousand separator is\n if (separators.length > 1) {\n // left detected separator will be a thousand and second will be decimal\n thousandsSeparator = separators[0];\n decimalSeparator = separators[1];\n } else if (separators.length > 0) {\n // in case there is only one separator you don't know exactly who this separator is.\n // in case there are more than two occurrences means we have a thousand otherwise we'll\n // agree by conventions that is decimal\n if (nonChars.length > 1) {\n return value\n .split(separators[0])\n .join('')\n .replace(/\\B(?=(\\d{3})+(?!\\d))/g, inThousandSeparator);\n } else {\n return value.replace(separators[0], inDecimalSeparator).replace(/\\B(?=(\\d{3})+(?!\\d))/g, inThousandSeparator);\n }\n } else {\n // in case there are no separators then only format based on thousand one\n return value.replace(/\\B(?=(\\d{3})+(?!\\d))/g, inThousandSeparator) + (fractionSize > 0 ? inDecimalSeparator + '0'.repeat(fractionSize) : '');\n }\n\n // do the replacement of separators and parseInt\n // Beware! Always replace a thousand separator first and then decimal\n value = value.split(thousandsSeparator).join('').replace(decimalSeparator, '.');\n }\n\n decimalSeparator = inDecimalSeparator;\n thousandsSeparator = inThousandSeparator;\n\n const maxFraction = '0'.repeat(fractionSize);\n\n
|
|
50467
|
+
"defaultValue": "(value: number | string, fractionSize = 2, inDecimalSeparator = ',', inThousandSeparator = ''): string | null => {\n // in case value is not a number throw an error\n if (typeof value === 'string' && isNaN(parseFloat(value))) {\n return null;\n }\n\n let decimalSeparator = '';\n let thousandsSeparator = '';\n\n if (value === null || value === undefined) {\n return null;\n }\n\n if (typeof value === 'string') {\n // get all non characters\n const nonChars: string[] = value.match(/\\D+/g) || [];\n\n // get all unique chars\n const uniqueChars = nonChars.reduce((acc, e) => acc.set(e, (acc.get(e) || 0) + 1), new Map());\n\n // get separators\n const separators = Array.from<string>(uniqueChars.keys());\n\n // sense where decimal separator and where a thousand separator is\n if (separators.length > 1) {\n // left detected separator will be a thousand and second will be decimal\n thousandsSeparator = separators[0];\n decimalSeparator = separators[1];\n } else if (separators.length > 0) {\n // in case there is only one separator you don't know exactly who this separator is.\n // in case there are more than two occurrences means we have a thousand otherwise we'll\n // agree by conventions that is decimal\n if (nonChars.length > 1) {\n return value\n .split(separators[0])\n .join('')\n .replace(/\\B(?=(\\d{3})+(?!\\d))/g, inThousandSeparator);\n } else {\n return value.replace(separators[0], inDecimalSeparator).replace(/\\B(?=(\\d{3})+(?!\\d))/g, inThousandSeparator);\n }\n } else {\n // in case there are no separators then only format based on thousand one\n return value.replace(/\\B(?=(\\d{3})+(?!\\d))/g, inThousandSeparator) + (fractionSize > 0 ? inDecimalSeparator + '0'.repeat(fractionSize) : '');\n }\n\n // do the replacement of separators and parseInt\n // Beware! Always replace a thousand separator first and then decimal\n value = value.split(thousandsSeparator).join('').replace(decimalSeparator, '.');\n }\n\n decimalSeparator = inDecimalSeparator;\n thousandsSeparator = inThousandSeparator;\n\n const maxFraction = '0'.repeat(fractionSize);\n \n let [integer, fraction = maxFraction] = (value || '0').toString().split('.');\n fraction = fractionSize > 0 ? roundUpNumber(fraction + maxFraction, fractionSize) : '';\n\n // this rule makes sense only in number in case fraction is all zero\n fraction = fraction.length > 0 ? decimalSeparator + fraction : '';\n\n // if fraction is all zero then round up the number\n if(fractionSize === 0) {\n integer = Math.round(parseFloat((value).toString())).toString();\n }\n\n return integer.replace(/\\B(?=(\\d{3})+(?!\\d))/g, thousandsSeparator) + fraction;\n}",
|
|
50538
50468
|
"rawdescription": "Its job is to parse number and format it based on given input.",
|
|
50539
50469
|
"description": "<p>Its job is to parse number and format it based on given input.</p>\n"
|
|
50540
50470
|
},
|
|
@@ -50778,7 +50708,7 @@
|
|
|
50778
50708
|
"deprecated": false,
|
|
50779
50709
|
"deprecationMessage": "",
|
|
50780
50710
|
"type": "unknown",
|
|
50781
|
-
"defaultValue": "<T>(value: T | undefined | null): value is T =>
|
|
50711
|
+
"defaultValue": "<T>(value: T | undefined | null): value is T => value as T !== undefined && value as T !== null",
|
|
50782
50712
|
"rawdescription": "check if a value is null or undefined. If it's not both returns true otherwise false",
|
|
50783
50713
|
"description": "<p>check if a value is null or undefined. If it's not both returns true otherwise false</p>\n"
|
|
50784
50714
|
}
|
|
@@ -50881,7 +50811,7 @@
|
|
|
50881
50811
|
"deprecated": false,
|
|
50882
50812
|
"deprecationMessage": "",
|
|
50883
50813
|
"type": "unknown",
|
|
50884
|
-
"defaultValue": "(FormControls:
|
|
50814
|
+
"defaultValue": "(FormControls: Record<string, AbstractControl> | AbstractControl[]): void => {\n const forOwn = (object: unknown, iteratee: (value: AbstractControl, key: string, object: Record<string, AbstractControl>) => void): void => {\n const obj = Object(object) as Record<string, AbstractControl>;\n Object.keys(obj).forEach((key) => iteratee(obj[key], key, obj));\n };\n\n const markFormGroupTouchedRecursive = (controls: Record<string, AbstractControl> | AbstractControl[]): void => {\n forOwn(controls, (c: AbstractControl) => {\n if (c instanceof FormGroup || c instanceof FormArray) {\n markFormGroupTouchedRecursive(c.controls);\n } else {\n c.markAsTouched();\n c.updateValueAndValidity();\n }\n });\n };\n markFormGroupTouchedRecursive(FormControls);\n}"
|
|
50885
50815
|
},
|
|
50886
50816
|
{
|
|
50887
50817
|
"name": "validateEmail",
|
|
@@ -50892,7 +50822,7 @@
|
|
|
50892
50822
|
"deprecated": false,
|
|
50893
50823
|
"deprecationMessage": "",
|
|
50894
50824
|
"type": "unknown",
|
|
50895
|
-
"defaultValue": "(c: FormControl): { validateEmail: { valid: boolean } } | null => {\n const EMAIL_REGEXP =\n // eslint-disable-next-line
|
|
50825
|
+
"defaultValue": "(c: FormControl): { validateEmail: { valid: boolean } } | null => {\n const EMAIL_REGEXP =\n // eslint-disable-next-line no-useless-escape\n /^(([^<>()\\[\\]\\\\.,;:\\s@\"]+(\\.[^<>()\\[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/;\n\n const error = {\n validateEmail: {\n valid: false,\n },\n };\n return EMAIL_REGEXP.test(c.value) ? null : error;\n}"
|
|
50896
50826
|
}
|
|
50897
50827
|
],
|
|
50898
50828
|
"packages/core/schematics/migrate-to-standalone/index.ts": [
|
|
@@ -70651,8 +70581,8 @@
|
|
|
70651
70581
|
"jsdoctags": [
|
|
70652
70582
|
{
|
|
70653
70583
|
"name": {
|
|
70654
|
-
"pos":
|
|
70655
|
-
"end":
|
|
70584
|
+
"pos": 5131,
|
|
70585
|
+
"end": 5138,
|
|
70656
70586
|
"kind": 80,
|
|
70657
70587
|
"id": 0,
|
|
70658
70588
|
"flags": 16777216,
|
|
@@ -70663,8 +70593,8 @@
|
|
|
70663
70593
|
"deprecated": false,
|
|
70664
70594
|
"deprecationMessage": "",
|
|
70665
70595
|
"tagName": {
|
|
70666
|
-
"pos":
|
|
70667
|
-
"end":
|
|
70596
|
+
"pos": 5125,
|
|
70597
|
+
"end": 5130,
|
|
70668
70598
|
"kind": 80,
|
|
70669
70599
|
"id": 0,
|
|
70670
70600
|
"flags": 16777216,
|
|
@@ -70675,8 +70605,8 @@
|
|
|
70675
70605
|
},
|
|
70676
70606
|
{
|
|
70677
70607
|
"name": {
|
|
70678
|
-
"pos":
|
|
70679
|
-
"end":
|
|
70608
|
+
"pos": 5188,
|
|
70609
|
+
"end": 5195,
|
|
70680
70610
|
"kind": 80,
|
|
70681
70611
|
"id": 0,
|
|
70682
70612
|
"flags": 16777216,
|
|
@@ -70688,8 +70618,8 @@
|
|
|
70688
70618
|
"deprecationMessage": "",
|
|
70689
70619
|
"defaultValue": "{\n stateFn: defaultStateFn,\n }",
|
|
70690
70620
|
"tagName": {
|
|
70691
|
-
"pos":
|
|
70692
|
-
"end":
|
|
70621
|
+
"pos": 5182,
|
|
70622
|
+
"end": 5187,
|
|
70693
70623
|
"kind": 80,
|
|
70694
70624
|
"id": 0,
|
|
70695
70625
|
"flags": 16777216,
|
|
@@ -71930,7 +71860,6 @@
|
|
|
71930
71860
|
},
|
|
71931
71861
|
{
|
|
71932
71862
|
"name": "merge",
|
|
71933
|
-
"type": "Array",
|
|
71934
71863
|
"deprecated": false,
|
|
71935
71864
|
"deprecationMessage": ""
|
|
71936
71865
|
},
|
|
@@ -71962,7 +71891,6 @@
|
|
|
71962
71891
|
},
|
|
71963
71892
|
{
|
|
71964
71893
|
"name": "merge",
|
|
71965
|
-
"type": "Array",
|
|
71966
71894
|
"deprecated": false,
|
|
71967
71895
|
"deprecationMessage": "",
|
|
71968
71896
|
"tagName": {
|
|
@@ -73542,6 +73470,19 @@
|
|
|
73542
73470
|
},
|
|
73543
73471
|
"groupedTypeAliases": {
|
|
73544
73472
|
"packages/core/src/lib/services/store/ngrx_kit.ts": [
|
|
73473
|
+
{
|
|
73474
|
+
"name": "ActionReducer",
|
|
73475
|
+
"ctype": "miscellaneous",
|
|
73476
|
+
"subtype": "typealias",
|
|
73477
|
+
"coverageIgnore": false,
|
|
73478
|
+
"rawtype": "function",
|
|
73479
|
+
"file": "packages/core/src/lib/services/store/ngrx_kit.ts",
|
|
73480
|
+
"deprecated": false,
|
|
73481
|
+
"deprecationMessage": "",
|
|
73482
|
+
"rawdescription": "A function that takes an `Action` and a `State`, and returns a `State`.\nSee `createReducer`.",
|
|
73483
|
+
"description": "<p>A function that takes an <code>Action</code> and a <code>State</code>, and returns a <code>State</code>.\nSee <code>createReducer</code>.</p>\n",
|
|
73484
|
+
"kind": 185
|
|
73485
|
+
},
|
|
73545
73486
|
{
|
|
73546
73487
|
"name": "ActionReducerMap",
|
|
73547
73488
|
"ctype": "miscellaneous",
|
|
@@ -73779,6 +73720,21 @@
|
|
|
73779
73720
|
"description": "",
|
|
73780
73721
|
"kind": 185
|
|
73781
73722
|
}
|
|
73723
|
+
],
|
|
73724
|
+
"packages/core/src/lib/services/i18n/i18n.loader.ts": [
|
|
73725
|
+
{
|
|
73726
|
+
"name": "TranslationKeys",
|
|
73727
|
+
"ctype": "miscellaneous",
|
|
73728
|
+
"subtype": "typealias",
|
|
73729
|
+
"coverageIgnore": false,
|
|
73730
|
+
"rawtype": "Record<string | string>",
|
|
73731
|
+
"file": "packages/core/src/lib/services/i18n/i18n.loader.ts",
|
|
73732
|
+
"deprecated": false,
|
|
73733
|
+
"deprecationMessage": "",
|
|
73734
|
+
"rawdescription": "",
|
|
73735
|
+
"description": "",
|
|
73736
|
+
"kind": 184
|
|
73737
|
+
}
|
|
73782
73738
|
]
|
|
73783
73739
|
}
|
|
73784
73740
|
},
|