@ts-core/angular 19.0.10 → 19.0.11

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.
@@ -1,18 +1,13 @@
1
- import { ThemeService, LanguageService, SettingsServiceBase } from '@ts-core/frontend';
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<T extends SettingsServiceBase> extends ApplicationComponentBase {
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(item: Language): void;
12
- protected abstract languageLoadingError(item: Language, error: Error): void;
8
+ protected languageLoadingComplete(locale: string): void;
9
+ protected abstract languageLoadingError(locale: string, error: Error): void;
13
10
  protected viewReadyHandler(): void;
14
- protected setLocale(item: Language): void;
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
  }
@@ -4,20 +4,22 @@ import { ILanguageLoader, ILanguageProjectSettings, LanguageLoadFunction } from
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(router: RouterServiceBase, settings: SettingsServiceBase, platform: PlatformService, language: LanguageService, windows: WindowService, options?: O);
15
- initialize(): Promise<boolean>;
9
+ constructor(options?: O);
10
+ initialize(): Promise<void>;
11
+ protected initializeAssets(): Promise<void>;
12
+ protected initializeLanguage(): Promise<void>;
16
13
  protected getLanguageLoader<T = any>(): Promise<ILanguageLoader<T>>;
14
+ protected abstract getLanguageLoadSettings<T = any>(): ILanguageLoadSettings<T>;
17
15
  protected getConfig(): Promise<any>;
18
16
  protected getConfigLocal<T = any>(): Promise<T>;
19
- protected getConfigRemote<T = any>(): Promise<T>;
20
- protected abstract getLanguageLoadSettings<T = any>(): ILanguageLoadSettings<T>;
17
+ protected abstract getConfigRemote<T = any>(local: any): Promise<T>;
18
+ protected abstract get windows(): WindowService;
19
+ protected abstract get platform(): PlatformService;
20
+ protected abstract get language(): LanguageService;
21
+ protected abstract get router(): R;
22
+ protected abstract get settings(): S;
21
23
  }
22
24
  export interface ILanguageLoadSettings<T = any> {
23
25
  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 * as i1 from '@ts-core/frontend';
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(router, settings, platform, language, windows, options) {
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,30 @@ 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 false;
47
+ return;
58
48
  }
59
- this.language.loader = await this.getLanguageLoader();
60
- return true;
49
+ this.initializeAssets();
50
+ this.initializeLanguage();
61
51
  }
62
52
  //--------------------------------------------------------------------------
63
53
  //
64
- // Protected Methods
54
+ // Language Methods
65
55
  //
66
56
  //--------------------------------------------------------------------------
57
+ async initializeAssets() {
58
+ Assets.provider = new AssetsCdnProvider(this.settings.assetsUrl, this.settings.assetsCdnUrl);
59
+ }
60
+ async initializeLanguage() {
61
+ this.language.loader = await this.getLanguageLoader();
62
+ }
67
63
  async getLanguageLoader() {
68
64
  if (this.platform.isPlatformServer) {
69
65
  return new LanguagePreloadLoader(this.options.locales);
@@ -71,19 +67,23 @@ class ApplicationInitializerBase extends Destroyable {
71
67
  let { url, project, proxy } = this.getLanguageLoadSettings();
72
68
  return this.settings.isProduction ? new LanguageProxyLoader(proxy) : new LanguageFileLoader(url, project.prefixes);
73
69
  }
70
+ //--------------------------------------------------------------------------
71
+ //
72
+ // Config Methods
73
+ //
74
+ //--------------------------------------------------------------------------
74
75
  async getConfig() {
75
76
  if (this.platform.isPlatformServer) {
76
77
  return this.options.config;
77
78
  }
78
- return Object.assign(await this.getConfigLocal(), await this.getConfigRemote());
79
+ let local = await this.getConfigLocal();
80
+ let remote = await this.getConfigRemote(local);
81
+ return Object.assign(local, remote);
79
82
  }
80
83
  async getConfigLocal() {
81
84
  let { data } = await axios.get('config.json');
82
85
  return data;
83
86
  }
84
- async getConfigRemote() {
85
- return null;
86
- }
87
87
  }
88
88
  class ServerInitializeOptions {
89
89
  config;
@@ -96,7 +96,6 @@ class ApplicationComponentBase extends DestroyableContainer {
96
96
  // Properties
97
97
  //
98
98
  // --------------------------------------------------------------------------
99
- timeout;
100
99
  isReadyAlreadyCalled;
101
100
  viewReadyDelay = NaN;
102
101
  viewReadyPromise;
@@ -157,22 +156,18 @@ class ApplicationComponentBase extends DestroyableContainer {
157
156
  this.viewReadyPromise.reject();
158
157
  this.viewReadyPromise = null;
159
158
  }
160
- if (!_.isNil(this.timeout)) {
161
- clearTimeout(this.timeout);
162
- this.timeout = null;
163
- }
164
159
  }
165
160
  // --------------------------------------------------------------------------
166
161
  //
167
162
  // Public Properties
168
163
  //
169
164
  // --------------------------------------------------------------------------
170
- get isViewReady() {
171
- return !_.isNil(this.viewReadyPromise) ? this.viewReadyPromise.isResolved : false;
172
- }
173
165
  get viewReady() {
174
166
  return !_.isNil(this.viewReadyPromise) ? this.viewReadyPromise.promise : null;
175
167
  }
168
+ get isViewReady() {
169
+ return !_.isNil(this.viewReadyPromise) ? this.viewReadyPromise.isResolved : false;
170
+ }
176
171
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.10", ngImport: i0, type: ApplicationComponentBase, deps: [], target: i0.ɵɵFactoryTarget.Component });
177
172
  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
173
  }
@@ -194,28 +189,13 @@ class ApplicationComponent extends ApplicationComponentBase {
194
189
  //
195
190
  // --------------------------------------------------------------------------
196
191
  initialize() {
197
- this.initializeAssets();
198
- this.initializeTheme();
199
192
  this.initializeLanguage();
200
193
  }
201
- initializeAssets() {
202
- Assets.provider = new AssetUrlProvider(this.settings.assetsUrl);
203
- }
204
- initializeTheme() {
205
- this.theme.initialize(this.settings.themes);
206
- }
207
194
  initializeLanguage() {
208
- this.language.initialize(`${this.settings.assetsUrl}language/`, this.settings.languages);
209
- this.language.events.pipe(takeUntil(this.destroyed)).subscribe(data => {
210
- switch (data.type) {
211
- case LoadableEvent.COMPLETE:
212
- this.languageLoadingComplete(data.data);
213
- break;
214
- case LoadableEvent.ERROR:
215
- this.languageLoadingError(data.data, data.error);
216
- break;
217
- }
218
- });
195
+ this.language.events
196
+ .pipe(filter(item => item.type === LoadableEvent.ERROR), takeUntil(this.destroyed))
197
+ .subscribe(item => this.languageLoadingError(item.data.toString(), item.error));
198
+ this.language.completed.pipe(takeUntil(this.destroyed)).subscribe(item => this.languageLoadingComplete(item));
219
199
  }
220
200
  isReady() {
221
201
  return super.isReady() && this.isLanguageLoaded;
@@ -225,17 +205,17 @@ class ApplicationComponent extends ApplicationComponentBase {
225
205
  // Event Handlers
226
206
  //
227
207
  // --------------------------------------------------------------------------
228
- languageLoadingComplete(item) {
208
+ languageLoadingComplete(locale) {
229
209
  this.isLanguageLoaded = true;
230
- this.setLocale(item);
210
+ this.setLocale(locale);
231
211
  this.checkReady();
232
212
  }
233
213
  viewReadyHandler() {
234
214
  this.initialize();
235
215
  }
236
216
  setLocale(item) {
237
- moment.locale(item.locale);
238
- numeral.locale(item.locale);
217
+ moment.locale(item);
218
+ numeral.locale(item);
239
219
  }
240
220
  }
241
221
 
@@ -2901,14 +2881,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.10", ngImpo
2901
2881
 
2902
2882
  class LanguageToggleDirective extends Destroyable {
2903
2883
  language;
2884
+ settings;
2904
2885
  // --------------------------------------------------------------------------
2905
2886
  //
2906
2887
  // Constructor
2907
2888
  //
2908
2889
  // --------------------------------------------------------------------------
2909
- constructor(language) {
2890
+ constructor(language, settings) {
2910
2891
  super();
2911
2892
  this.language = language;
2893
+ this.settings = settings;
2912
2894
  }
2913
2895
  // --------------------------------------------------------------------------
2914
2896
  //
@@ -2916,9 +2898,10 @@ class LanguageToggleDirective extends Destroyable {
2916
2898
  //
2917
2899
  // --------------------------------------------------------------------------
2918
2900
  clickHandler() {
2919
- let items = this.language.languages.collection;
2920
- if (items.length > 1) {
2921
- this.language.language = ArrayUtil.nextItem(this.language.language, items, true);
2901
+ let items = this.settings.languages.collection;
2902
+ let item = ArrayUtil.nextItem(_.find(items, { locale: this.language.locale }), items, true);
2903
+ if (!_.isNil(item)) {
2904
+ this.language.locale = item.locale;
2922
2905
  }
2923
2906
  }
2924
2907
  // --------------------------------------------------------------------------
@@ -2933,7 +2916,7 @@ class LanguageToggleDirective extends Destroyable {
2933
2916
  super.destroy();
2934
2917
  this.language = null;
2935
2918
  }
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 });
2919
+ 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
2920
  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
2921
  }
2939
2922
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.10", ngImport: i0, type: LanguageToggleDirective, decorators: [{
@@ -2942,7 +2925,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.10", ngImpo
2942
2925
  selector: '[vi-language-toggle]',
2943
2926
  standalone: false
2944
2927
  }]
2945
- }], ctorParameters: () => [{ type: i1.LanguageService }], propDecorators: { clickHandler: [{
2928
+ }], ctorParameters: () => [{ type: i1.LanguageService }, { type: i1.SettingsServiceBase }], propDecorators: { clickHandler: [{
2946
2929
  type: HostListener,
2947
2930
  args: ['click']
2948
2931
  }] } });
@@ -4974,7 +4957,7 @@ class PipeServiceBase extends Destroyable {
4974
4957
  //
4975
4958
  // --------------------------------------------------------------------------
4976
4959
  commitLanguageProperties() {
4977
- let locale = this.language.locale ? this.language.language.locale : 'en';
4960
+ let locale = this.language.locale ? this.language.locale : 'en';
4978
4961
  this._locale = locale === 'en' ? 'en-US' : locale;
4979
4962
  if (PipeServiceBase.DATE) {
4980
4963
  PipeServiceBase.DATE = new DatePipe(this.locale);