@ts-core/angular 19.0.10 → 19.0.12
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/application/ApplicationComponent.d.ts +5 -10
- package/application/ApplicationComponentBase.d.ts +1 -2
- package/application/ApplicationInitializerBase.d.ts +16 -11
- package/fesm2022/ts-core-angular.mjs +62 -63
- package/fesm2022/ts-core-angular.mjs.map +1 -1
- package/language/LanguageToggleDirective.d.ts +3 -2
- package/package.json +1 -1
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Language } from '@ts-core/language';
|
|
1
|
+
import { LanguageService } from '@ts-core/frontend';
|
|
3
2
|
import { ApplicationComponentBase } from './ApplicationComponentBase';
|
|
4
|
-
export declare abstract class ApplicationComponent
|
|
3
|
+
export declare abstract class ApplicationComponent extends ApplicationComponentBase {
|
|
5
4
|
private isLanguageLoaded;
|
|
6
5
|
protected initialize(): void;
|
|
7
|
-
protected initializeAssets(): void;
|
|
8
|
-
protected initializeTheme(): void;
|
|
9
6
|
protected initializeLanguage(): void;
|
|
10
7
|
protected isReady(): boolean;
|
|
11
|
-
protected languageLoadingComplete(
|
|
12
|
-
protected abstract languageLoadingError(
|
|
8
|
+
protected languageLoadingComplete(locale: string): void;
|
|
9
|
+
protected abstract languageLoadingError(locale: string, error: Error): void;
|
|
13
10
|
protected viewReadyHandler(): void;
|
|
14
|
-
protected setLocale(item:
|
|
15
|
-
protected abstract get theme(): ThemeService;
|
|
16
|
-
protected abstract get settings(): T;
|
|
11
|
+
protected setLocale(item: string): void;
|
|
17
12
|
protected abstract get language(): LanguageService;
|
|
18
13
|
}
|
|
@@ -3,7 +3,6 @@ import { DestroyableContainer } from '@ts-core/common';
|
|
|
3
3
|
import { PromiseHandler } from '@ts-core/common';
|
|
4
4
|
import * as i0 from "@angular/core";
|
|
5
5
|
export declare abstract class ApplicationComponentBase extends DestroyableContainer implements AfterViewInit {
|
|
6
|
-
protected timeout: any;
|
|
7
6
|
protected isReadyAlreadyCalled: boolean;
|
|
8
7
|
protected viewReadyDelay: number;
|
|
9
8
|
protected viewReadyPromise: PromiseHandler<void, void>;
|
|
@@ -15,8 +14,8 @@ export declare abstract class ApplicationComponentBase extends DestroyableContai
|
|
|
15
14
|
protected abstract readyHandler(): void | Promise<void>;
|
|
16
15
|
ngAfterViewInit(): void;
|
|
17
16
|
destroy(): void;
|
|
18
|
-
get isViewReady(): boolean;
|
|
19
17
|
get viewReady(): Promise<void>;
|
|
18
|
+
get isViewReady(): boolean;
|
|
20
19
|
static ɵfac: i0.ɵɵFactoryDeclaration<ApplicationComponentBase, never>;
|
|
21
20
|
static ɵcmp: i0.ɵɵComponentDeclaration<ApplicationComponentBase, "ng-component", never, {}, {}, never, never, true, never>;
|
|
22
21
|
}
|
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
import { Destroyable } from '@ts-core/common';
|
|
2
|
-
import { LanguageService, SettingsServiceBase } from '@ts-core/frontend';
|
|
2
|
+
import { LanguageService, SettingsServiceBase, ThemeService } from '@ts-core/frontend';
|
|
3
3
|
import { ILanguageLoader, ILanguageProjectSettings, LanguageLoadFunction } from '@ts-core/language';
|
|
4
4
|
import { RouterServiceBase } from '../service/RouterServiceBase';
|
|
5
5
|
import { PlatformService } from '../service/PlatformService';
|
|
6
6
|
import { WindowService } from '../window/WindowService';
|
|
7
|
-
export declare abstract class ApplicationInitializerBase<T = any, O extends ServerInitializeOptions<T> = ServerInitializeOptions<T>> extends Destroyable {
|
|
8
|
-
protected router: RouterServiceBase;
|
|
9
|
-
protected settings: SettingsServiceBase;
|
|
10
|
-
protected platform: PlatformService;
|
|
11
|
-
protected language: LanguageService;
|
|
12
|
-
protected windows: WindowService;
|
|
7
|
+
export declare abstract class ApplicationInitializerBase<S extends SettingsServiceBase, R extends RouterServiceBase, T = any, O extends ServerInitializeOptions<T> = ServerInitializeOptions<T>> extends Destroyable {
|
|
13
8
|
protected options?: O;
|
|
14
|
-
constructor(
|
|
15
|
-
initialize(): Promise<
|
|
9
|
+
constructor(options?: O);
|
|
10
|
+
initialize(): Promise<void>;
|
|
11
|
+
protected initializeAsset(): Promise<void>;
|
|
12
|
+
protected initializeTheme(): Promise<void>;
|
|
13
|
+
protected initializeLanguage(): Promise<void>;
|
|
16
14
|
protected getLanguageLoader<T = any>(): Promise<ILanguageLoader<T>>;
|
|
15
|
+
protected abstract getLanguageLoadSettings<T = any>(): ILanguageLoadSettings<T>;
|
|
17
16
|
protected getConfig(): Promise<any>;
|
|
18
17
|
protected getConfigLocal<T = any>(): Promise<T>;
|
|
19
|
-
protected
|
|
20
|
-
protected abstract
|
|
18
|
+
protected loadConfig<T = any>(url: string): Promise<T>;
|
|
19
|
+
protected abstract getConfigRemote<T = any>(local: any): Promise<T>;
|
|
20
|
+
protected abstract get theme(): ThemeService;
|
|
21
|
+
protected abstract get windows(): WindowService;
|
|
22
|
+
protected abstract get platform(): PlatformService;
|
|
23
|
+
protected abstract get language(): LanguageService;
|
|
24
|
+
protected abstract get router(): R;
|
|
25
|
+
protected abstract get settings(): S;
|
|
21
26
|
}
|
|
22
27
|
export interface ILanguageLoadSettings<T = any> {
|
|
23
28
|
url: string;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as i2 from '@ts-core/common';
|
|
2
2
|
import { Destroyable, ExtendedError, DestroyableContainer, PromiseHandler, LoadableEvent, DateUtil, ArrayUtil, Loadable, LoadableStatus, ObservableData, TransportTimeoutError, TransportNoConnectionError, FilterableMapCollection, RemoveFilterableCondition, GetFilterableCondition, IDestroyable, MapCollection, TransportEvent, TransportLocal, Logger, LoggerLevel } from '@ts-core/common';
|
|
3
|
+
import * as i1 from '@ts-core/frontend';
|
|
4
|
+
import { AssetsCdnProvider, Assets, NativeWindowService, LanguageService, ThemeService, ThemeAssetService, LoadingService, ICookieOptions, DefaultLogger } from '@ts-core/frontend';
|
|
3
5
|
import { LanguagePreloadLoader, LanguageProxyLoader, LanguageFileLoader } from '@ts-core/language';
|
|
4
6
|
import axios from 'axios';
|
|
5
7
|
import * as _ from 'lodash';
|
|
6
8
|
import * as i0 from '@angular/core';
|
|
7
9
|
import { Component, ViewContainerRef, booleanAttribute, Input, Directive, Pipe, NgModule, PLATFORM_ID, Inject, Injectable, InjectionToken, numberAttribute, EventEmitter, HostListener, Output, RendererStyleFlags2, Optional, NgModuleFactory, RendererFactory2, APP_INITIALIZER } from '@angular/core';
|
|
8
|
-
import
|
|
9
|
-
import { AssetUrlProvider, Assets, NativeWindowService, LanguageService, ThemeService, ThemeAssetService, LoadingService, ICookieOptions, DefaultLogger } from '@ts-core/frontend';
|
|
10
|
-
import { takeUntil, BehaviorSubject, distinctUntilChanged, debounceTime, fromEvent, filter, map, Subject } from 'rxjs';
|
|
10
|
+
import { filter, takeUntil, BehaviorSubject, distinctUntilChanged, debounceTime, fromEvent, map, Subject } from 'rxjs';
|
|
11
11
|
import moment from 'moment';
|
|
12
12
|
import numeral from 'numeral';
|
|
13
13
|
import { CommonModule, isPlatformServer, isPlatformBrowser, DatePipe, DOCUMENT } from '@angular/common';
|
|
@@ -20,28 +20,15 @@ import * as i1$3 from '@angular/platform-browser';
|
|
|
20
20
|
import * as i1$4 from '@angular/service-worker';
|
|
21
21
|
|
|
22
22
|
class ApplicationInitializerBase extends Destroyable {
|
|
23
|
-
router;
|
|
24
|
-
settings;
|
|
25
|
-
platform;
|
|
26
|
-
language;
|
|
27
|
-
windows;
|
|
28
23
|
options;
|
|
29
24
|
//--------------------------------------------------------------------------
|
|
30
25
|
//
|
|
31
26
|
// Constructor
|
|
32
27
|
//
|
|
33
28
|
//--------------------------------------------------------------------------
|
|
34
|
-
constructor(
|
|
29
|
+
constructor(options) {
|
|
35
30
|
super();
|
|
36
|
-
this.router = router;
|
|
37
|
-
this.settings = settings;
|
|
38
|
-
this.platform = platform;
|
|
39
|
-
this.language = language;
|
|
40
|
-
this.windows = windows;
|
|
41
31
|
this.options = options;
|
|
42
|
-
if (platform.isPlatformServer && _.isNil(options)) {
|
|
43
|
-
throw new ExtendedError(`Unable to initialize server platform: options is nil`);
|
|
44
|
-
}
|
|
45
32
|
}
|
|
46
33
|
//--------------------------------------------------------------------------
|
|
47
34
|
//
|
|
@@ -49,21 +36,39 @@ class ApplicationInitializerBase extends Destroyable {
|
|
|
49
36
|
//
|
|
50
37
|
//--------------------------------------------------------------------------
|
|
51
38
|
async initialize() {
|
|
39
|
+
if (this.platform.isPlatformServer && _.isNil(this.options)) {
|
|
40
|
+
throw new ExtendedError(`Unable to initialize: server platform requires options`);
|
|
41
|
+
}
|
|
52
42
|
try {
|
|
53
43
|
this.settings.initialize(await this.getConfig(), this.router.getParams());
|
|
54
44
|
}
|
|
55
45
|
catch (error) {
|
|
56
46
|
this.windows.info(error.message, null, null, { isDisableClose: true, isModal: true });
|
|
57
|
-
return
|
|
47
|
+
return;
|
|
58
48
|
}
|
|
59
|
-
this.
|
|
60
|
-
|
|
49
|
+
this.initializeAsset();
|
|
50
|
+
this.initializeTheme();
|
|
51
|
+
this.initializeLanguage();
|
|
61
52
|
}
|
|
62
53
|
//--------------------------------------------------------------------------
|
|
63
54
|
//
|
|
64
55
|
// Protected Methods
|
|
65
56
|
//
|
|
66
57
|
//--------------------------------------------------------------------------
|
|
58
|
+
async initializeAsset() {
|
|
59
|
+
Assets.provider = new AssetsCdnProvider(this.settings.assetsUrl, this.settings.assetsCdnUrl);
|
|
60
|
+
}
|
|
61
|
+
async initializeTheme() {
|
|
62
|
+
this.theme.initialize(this.settings.themes);
|
|
63
|
+
}
|
|
64
|
+
//--------------------------------------------------------------------------
|
|
65
|
+
//
|
|
66
|
+
// Language Methods
|
|
67
|
+
//
|
|
68
|
+
//--------------------------------------------------------------------------
|
|
69
|
+
async initializeLanguage() {
|
|
70
|
+
this.language.loader = await this.getLanguageLoader();
|
|
71
|
+
}
|
|
67
72
|
async getLanguageLoader() {
|
|
68
73
|
if (this.platform.isPlatformServer) {
|
|
69
74
|
return new LanguagePreloadLoader(this.options.locales);
|
|
@@ -71,18 +76,29 @@ class ApplicationInitializerBase extends Destroyable {
|
|
|
71
76
|
let { url, project, proxy } = this.getLanguageLoadSettings();
|
|
72
77
|
return this.settings.isProduction ? new LanguageProxyLoader(proxy) : new LanguageFileLoader(url, project.prefixes);
|
|
73
78
|
}
|
|
79
|
+
//--------------------------------------------------------------------------
|
|
80
|
+
//
|
|
81
|
+
// Config Methods
|
|
82
|
+
//
|
|
83
|
+
//--------------------------------------------------------------------------
|
|
74
84
|
async getConfig() {
|
|
75
85
|
if (this.platform.isPlatformServer) {
|
|
76
86
|
return this.options.config;
|
|
77
87
|
}
|
|
78
|
-
|
|
88
|
+
let local = await this.getConfigLocal();
|
|
89
|
+
return Object.assign(local, await this.getConfigRemote(local));
|
|
79
90
|
}
|
|
80
91
|
async getConfigLocal() {
|
|
81
|
-
|
|
82
|
-
return data;
|
|
92
|
+
return this.loadConfig('config.json');
|
|
83
93
|
}
|
|
84
|
-
async
|
|
85
|
-
|
|
94
|
+
async loadConfig(url) {
|
|
95
|
+
try {
|
|
96
|
+
let { data } = await axios.get(url);
|
|
97
|
+
return data;
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
throw new ExtendedError(`Unable to load config from "${url}": ${error.message}`);
|
|
101
|
+
}
|
|
86
102
|
}
|
|
87
103
|
}
|
|
88
104
|
class ServerInitializeOptions {
|
|
@@ -96,7 +112,6 @@ class ApplicationComponentBase extends DestroyableContainer {
|
|
|
96
112
|
// Properties
|
|
97
113
|
//
|
|
98
114
|
// --------------------------------------------------------------------------
|
|
99
|
-
timeout;
|
|
100
115
|
isReadyAlreadyCalled;
|
|
101
116
|
viewReadyDelay = NaN;
|
|
102
117
|
viewReadyPromise;
|
|
@@ -157,22 +172,18 @@ class ApplicationComponentBase extends DestroyableContainer {
|
|
|
157
172
|
this.viewReadyPromise.reject();
|
|
158
173
|
this.viewReadyPromise = null;
|
|
159
174
|
}
|
|
160
|
-
if (!_.isNil(this.timeout)) {
|
|
161
|
-
clearTimeout(this.timeout);
|
|
162
|
-
this.timeout = null;
|
|
163
|
-
}
|
|
164
175
|
}
|
|
165
176
|
// --------------------------------------------------------------------------
|
|
166
177
|
//
|
|
167
178
|
// Public Properties
|
|
168
179
|
//
|
|
169
180
|
// --------------------------------------------------------------------------
|
|
170
|
-
get isViewReady() {
|
|
171
|
-
return !_.isNil(this.viewReadyPromise) ? this.viewReadyPromise.isResolved : false;
|
|
172
|
-
}
|
|
173
181
|
get viewReady() {
|
|
174
182
|
return !_.isNil(this.viewReadyPromise) ? this.viewReadyPromise.promise : null;
|
|
175
183
|
}
|
|
184
|
+
get isViewReady() {
|
|
185
|
+
return !_.isNil(this.viewReadyPromise) ? this.viewReadyPromise.isResolved : false;
|
|
186
|
+
}
|
|
176
187
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.10", ngImport: i0, type: ApplicationComponentBase, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
177
188
|
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.10", type: ApplicationComponentBase, isStandalone: true, selector: "ng-component", usesInheritance: true, ngImport: i0, template: '', isInline: true });
|
|
178
189
|
}
|
|
@@ -194,28 +205,13 @@ class ApplicationComponent extends ApplicationComponentBase {
|
|
|
194
205
|
//
|
|
195
206
|
// --------------------------------------------------------------------------
|
|
196
207
|
initialize() {
|
|
197
|
-
this.initializeAssets();
|
|
198
|
-
this.initializeTheme();
|
|
199
208
|
this.initializeLanguage();
|
|
200
209
|
}
|
|
201
|
-
initializeAssets() {
|
|
202
|
-
Assets.provider = new AssetUrlProvider(this.settings.assetsUrl);
|
|
203
|
-
}
|
|
204
|
-
initializeTheme() {
|
|
205
|
-
this.theme.initialize(this.settings.themes);
|
|
206
|
-
}
|
|
207
210
|
initializeLanguage() {
|
|
208
|
-
this.language.
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
this.languageLoadingComplete(data.data);
|
|
213
|
-
break;
|
|
214
|
-
case LoadableEvent.ERROR:
|
|
215
|
-
this.languageLoadingError(data.data, data.error);
|
|
216
|
-
break;
|
|
217
|
-
}
|
|
218
|
-
});
|
|
211
|
+
this.language.events
|
|
212
|
+
.pipe(filter(item => item.type === LoadableEvent.ERROR), takeUntil(this.destroyed))
|
|
213
|
+
.subscribe(item => this.languageLoadingError(item.data.toString(), item.error));
|
|
214
|
+
this.language.completed.pipe(takeUntil(this.destroyed)).subscribe(item => this.languageLoadingComplete(item));
|
|
219
215
|
}
|
|
220
216
|
isReady() {
|
|
221
217
|
return super.isReady() && this.isLanguageLoaded;
|
|
@@ -225,17 +221,17 @@ class ApplicationComponent extends ApplicationComponentBase {
|
|
|
225
221
|
// Event Handlers
|
|
226
222
|
//
|
|
227
223
|
// --------------------------------------------------------------------------
|
|
228
|
-
languageLoadingComplete(
|
|
224
|
+
languageLoadingComplete(locale) {
|
|
229
225
|
this.isLanguageLoaded = true;
|
|
230
|
-
this.setLocale(
|
|
226
|
+
this.setLocale(locale);
|
|
231
227
|
this.checkReady();
|
|
232
228
|
}
|
|
233
229
|
viewReadyHandler() {
|
|
234
230
|
this.initialize();
|
|
235
231
|
}
|
|
236
232
|
setLocale(item) {
|
|
237
|
-
moment.locale(item
|
|
238
|
-
numeral.locale(item
|
|
233
|
+
moment.locale(item);
|
|
234
|
+
numeral.locale(item);
|
|
239
235
|
}
|
|
240
236
|
}
|
|
241
237
|
|
|
@@ -2901,14 +2897,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.10", ngImpo
|
|
|
2901
2897
|
|
|
2902
2898
|
class LanguageToggleDirective extends Destroyable {
|
|
2903
2899
|
language;
|
|
2900
|
+
settings;
|
|
2904
2901
|
// --------------------------------------------------------------------------
|
|
2905
2902
|
//
|
|
2906
2903
|
// Constructor
|
|
2907
2904
|
//
|
|
2908
2905
|
// --------------------------------------------------------------------------
|
|
2909
|
-
constructor(language) {
|
|
2906
|
+
constructor(language, settings) {
|
|
2910
2907
|
super();
|
|
2911
2908
|
this.language = language;
|
|
2909
|
+
this.settings = settings;
|
|
2912
2910
|
}
|
|
2913
2911
|
// --------------------------------------------------------------------------
|
|
2914
2912
|
//
|
|
@@ -2916,9 +2914,10 @@ class LanguageToggleDirective extends Destroyable {
|
|
|
2916
2914
|
//
|
|
2917
2915
|
// --------------------------------------------------------------------------
|
|
2918
2916
|
clickHandler() {
|
|
2919
|
-
let items = this.
|
|
2920
|
-
|
|
2921
|
-
|
|
2917
|
+
let items = this.settings.languages.collection;
|
|
2918
|
+
let item = ArrayUtil.nextItem(_.find(items, { locale: this.language.locale }), items, true);
|
|
2919
|
+
if (!_.isNil(item)) {
|
|
2920
|
+
this.language.locale = item.locale;
|
|
2922
2921
|
}
|
|
2923
2922
|
}
|
|
2924
2923
|
// --------------------------------------------------------------------------
|
|
@@ -2933,7 +2932,7 @@ class LanguageToggleDirective extends Destroyable {
|
|
|
2933
2932
|
super.destroy();
|
|
2934
2933
|
this.language = null;
|
|
2935
2934
|
}
|
|
2936
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.10", ngImport: i0, type: LanguageToggleDirective, deps: [{ token: i1.LanguageService }], target: i0.ɵɵFactoryTarget.Directive });
|
|
2935
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.10", ngImport: i0, type: LanguageToggleDirective, deps: [{ token: i1.LanguageService }, { token: i1.SettingsServiceBase }], target: i0.ɵɵFactoryTarget.Directive });
|
|
2937
2936
|
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.10", type: LanguageToggleDirective, isStandalone: false, selector: "[vi-language-toggle]", host: { listeners: { "click": "clickHandler()" } }, usesInheritance: true, ngImport: i0 });
|
|
2938
2937
|
}
|
|
2939
2938
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.10", ngImport: i0, type: LanguageToggleDirective, decorators: [{
|
|
@@ -2942,7 +2941,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.10", ngImpo
|
|
|
2942
2941
|
selector: '[vi-language-toggle]',
|
|
2943
2942
|
standalone: false
|
|
2944
2943
|
}]
|
|
2945
|
-
}], ctorParameters: () => [{ type: i1.LanguageService }], propDecorators: { clickHandler: [{
|
|
2944
|
+
}], ctorParameters: () => [{ type: i1.LanguageService }, { type: i1.SettingsServiceBase }], propDecorators: { clickHandler: [{
|
|
2946
2945
|
type: HostListener,
|
|
2947
2946
|
args: ['click']
|
|
2948
2947
|
}] } });
|
|
@@ -4974,7 +4973,7 @@ class PipeServiceBase extends Destroyable {
|
|
|
4974
4973
|
//
|
|
4975
4974
|
// --------------------------------------------------------------------------
|
|
4976
4975
|
commitLanguageProperties() {
|
|
4977
|
-
let locale = this.language.locale ? this.language.
|
|
4976
|
+
let locale = this.language.locale ? this.language.locale : 'en';
|
|
4978
4977
|
this._locale = locale === 'en' ? 'en-US' : locale;
|
|
4979
4978
|
if (PipeServiceBase.DATE) {
|
|
4980
4979
|
PipeServiceBase.DATE = new DatePipe(this.locale);
|