valtech-components 2.0.277 → 2.0.279
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/README.md +149 -6
- package/esm2022/lib/components/_examples/global-content-example-content.mjs +23 -0
- package/esm2022/lib/components/_examples/global-content-example.component.mjs +504 -0
- package/esm2022/lib/components/_examples/reactive-content-example-content.mjs +43 -0
- package/esm2022/lib/components/_examples/reactive-content-example.component.mjs +347 -0
- package/esm2022/lib/components/atoms/text/text.component.mjs +143 -15
- package/esm2022/lib/components/atoms/text/types.mjs +1 -1
- package/esm2022/lib/services/content.service.mjs +327 -0
- package/esm2022/lib/services/icons.service.mjs +3 -2
- package/esm2022/lib/services/lang-provider/content.mjs +138 -1
- package/esm2022/lib/services/lang-provider/lang-provider.service.mjs +118 -8
- package/esm2022/lib/shared/utils/content.mjs +186 -0
- package/esm2022/public-api.mjs +12 -5
- package/fesm2022/valtech-components.mjs +3415 -1609
- package/fesm2022/valtech-components.mjs.map +1 -1
- package/lib/components/_examples/global-content-example-content.d.ts +9 -0
- package/lib/components/_examples/global-content-example.component.d.ts +73 -0
- package/lib/components/_examples/reactive-content-example-content.d.ts +32 -0
- package/lib/components/_examples/reactive-content-example.component.d.ts +47 -0
- package/lib/components/atoms/text/text.component.d.ts +57 -8
- package/lib/components/atoms/text/types.d.ts +26 -5
- package/lib/services/content.service.d.ts +296 -0
- package/lib/services/lang-provider/content.d.ts +8 -1
- package/lib/services/lang-provider/lang-provider.service.d.ts +87 -7
- package/lib/shared/utils/content.d.ts +199 -0
- package/package.json +1 -1
- package/public-api.d.ts +10 -4
|
@@ -1,15 +1,95 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Provider } from './content';
|
|
3
|
-
import { LangOption, LanguageText } from './types';
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
4
2
|
import { ValtechConfig } from '../types';
|
|
3
|
+
import { LangOption, LanguageText } from './types';
|
|
5
4
|
import * as i0 from "@angular/core";
|
|
5
|
+
/**
|
|
6
|
+
* LangService - Reactive language and content management service.
|
|
7
|
+
*
|
|
8
|
+
* This service provides reactive content management with Observable-based language switching.
|
|
9
|
+
* Components can subscribe to content changes and automatically update when the language changes.
|
|
10
|
+
*
|
|
11
|
+
* @example Basic usage:
|
|
12
|
+
* ```typescript
|
|
13
|
+
* constructor(private langService: LangService) {}
|
|
14
|
+
*
|
|
15
|
+
* // Get current language
|
|
16
|
+
* const currentLang = this.langService.currentLang;
|
|
17
|
+
*
|
|
18
|
+
* // Subscribe to language changes
|
|
19
|
+
* this.langService.currentLang$.subscribe(lang => console.log('Language changed:', lang));
|
|
20
|
+
*
|
|
21
|
+
* // Get static text
|
|
22
|
+
* const text = this.langService.getText('ComponentName', 'textKey');
|
|
23
|
+
*
|
|
24
|
+
* // Get reactive text
|
|
25
|
+
* const text$ = this.langService.getContent('ComponentName', 'textKey');
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
6
28
|
export declare class LangService {
|
|
7
|
-
content
|
|
8
|
-
default
|
|
9
|
-
selectedLang
|
|
10
|
-
config
|
|
29
|
+
private content;
|
|
30
|
+
private default;
|
|
31
|
+
private selectedLang;
|
|
32
|
+
private config;
|
|
11
33
|
constructor(config: ValtechConfig);
|
|
34
|
+
/**
|
|
35
|
+
* Observable that emits the current language whenever it changes.
|
|
36
|
+
* Use this to react to language changes in components.
|
|
37
|
+
*/
|
|
38
|
+
get currentLang$(): Observable<LangOption>;
|
|
39
|
+
/**
|
|
40
|
+
* Get the current language synchronously.
|
|
41
|
+
*/
|
|
42
|
+
get currentLang(): LangOption;
|
|
43
|
+
/**
|
|
44
|
+
* Set the current language and persist it to local storage.
|
|
45
|
+
* This will trigger updates in all components subscribed to reactive content.
|
|
46
|
+
*
|
|
47
|
+
* @param lang - The language to set
|
|
48
|
+
*/
|
|
49
|
+
setLang(lang: LangOption): void;
|
|
50
|
+
/**
|
|
51
|
+
* Get all text content for a component class (legacy method for compatibility).
|
|
52
|
+
*
|
|
53
|
+
* @param className - The component class name
|
|
54
|
+
* @returns The language text object for the current language
|
|
55
|
+
* @deprecated Use getText() or getContent() for better type safety
|
|
56
|
+
*/
|
|
12
57
|
Text(className: string): LanguageText;
|
|
58
|
+
/**
|
|
59
|
+
* Get a specific text value synchronously for the current language.
|
|
60
|
+
*
|
|
61
|
+
* @param className - The component class name
|
|
62
|
+
* @param key - The text key
|
|
63
|
+
* @param fallback - Optional fallback text if key is not found
|
|
64
|
+
* @returns The text string or fallback
|
|
65
|
+
*/
|
|
66
|
+
getText(className: string, key: string, fallback?: string): string;
|
|
67
|
+
/**
|
|
68
|
+
* Get a reactive Observable for a specific text key that updates when language changes.
|
|
69
|
+
* This is the recommended method for components that need reactive content.
|
|
70
|
+
*
|
|
71
|
+
* @param className - The component class name
|
|
72
|
+
* @param key - The text key
|
|
73
|
+
* @param fallback - Optional fallback text if key is not found
|
|
74
|
+
* @returns Observable that emits the text string whenever language changes
|
|
75
|
+
*/
|
|
76
|
+
getContent(className: string, key: string, fallback?: string): Observable<string>;
|
|
77
|
+
/**
|
|
78
|
+
* Get reactive content for multiple keys at once.
|
|
79
|
+
*
|
|
80
|
+
* @param className - The component class name
|
|
81
|
+
* @param keys - Array of text keys to retrieve
|
|
82
|
+
* @returns Observable that emits an object with all requested keys
|
|
83
|
+
*/
|
|
84
|
+
getMultipleContent(className: string, keys: string[]): Observable<Record<string, string>>;
|
|
85
|
+
/**
|
|
86
|
+
* Check if a content key exists for a component.
|
|
87
|
+
*
|
|
88
|
+
* @param className - The component class name
|
|
89
|
+
* @param key - The text key
|
|
90
|
+
* @returns True if the key exists in any language
|
|
91
|
+
*/
|
|
92
|
+
hasContent(className: string, key: string): boolean;
|
|
13
93
|
get Lang(): LangOption;
|
|
14
94
|
set Lang(lang: LangOption);
|
|
15
95
|
static ɵfac: i0.ɵɵFactoryDeclaration<LangService, never>;
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { LangService } from '../../services/lang-provider/lang-provider.service';
|
|
3
|
+
/**
|
|
4
|
+
* Content utilities for reactive text binding in components.
|
|
5
|
+
*
|
|
6
|
+
* These utilities provide a convenient way to bind component properties
|
|
7
|
+
* to language content that automatically updates when the language changes.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Unified configuration for content binding with optional interpolation.
|
|
11
|
+
* Supports both simple content retrieval and content with dynamic values.
|
|
12
|
+
*/
|
|
13
|
+
export interface ContentConfig {
|
|
14
|
+
/**
|
|
15
|
+
* The component class name (used for content lookup).
|
|
16
|
+
* If omitted, searches in global content (_global namespace).
|
|
17
|
+
*/
|
|
18
|
+
className?: string;
|
|
19
|
+
/** The content key to retrieve */
|
|
20
|
+
key: string;
|
|
21
|
+
/** Optional fallback text if content is not found */
|
|
22
|
+
fallback?: string;
|
|
23
|
+
/** Optional object with values to interpolate into the content string */
|
|
24
|
+
interpolation?: Record<string, string | number>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated Use ContentConfig with interpolation property instead.
|
|
28
|
+
* This interface is kept for backward compatibility.
|
|
29
|
+
*/
|
|
30
|
+
export interface InterpolatedContentConfig extends ContentConfig {
|
|
31
|
+
/** Object with values to interpolate into the content string */
|
|
32
|
+
interpolation?: Record<string, string | number>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create a reactive content observable from a content key.
|
|
36
|
+
* This is the primary utility for the `fromContent` pattern with unified support
|
|
37
|
+
* for both simple content and content with interpolation.
|
|
38
|
+
*
|
|
39
|
+
* @param langService - The language service instance
|
|
40
|
+
* @param config - Content configuration with optional interpolation
|
|
41
|
+
* @returns Observable that emits the content string and updates on language change
|
|
42
|
+
*
|
|
43
|
+
* @example Simple content:
|
|
44
|
+
* ```typescript
|
|
45
|
+
* // Component-specific content
|
|
46
|
+
* this.title$ = fromContent(this.langService, {
|
|
47
|
+
* className: 'HeaderComponent',
|
|
48
|
+
* key: 'title',
|
|
49
|
+
* fallback: 'Default Title'
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* // Global content (no className needed)
|
|
53
|
+
* this.saveButton$ = fromContent(this.langService, {
|
|
54
|
+
* key: 'save'
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @example Content with interpolation:
|
|
59
|
+
* ```typescript
|
|
60
|
+
* // Content: "Hello {name}, you have {count} messages"
|
|
61
|
+
* this.greeting$ = fromContent(this.langService, {
|
|
62
|
+
* className: 'WelcomeComponent',
|
|
63
|
+
* key: 'greeting',
|
|
64
|
+
* interpolation: { name: 'John', count: 5 }
|
|
65
|
+
* });
|
|
66
|
+
* // Results in: "Hello John, you have 5 messages"
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function fromContent(langService: LangService, config: ContentConfig): Observable<string>;
|
|
70
|
+
/**
|
|
71
|
+
* Create a reactive content observable with interpolation support.
|
|
72
|
+
*
|
|
73
|
+
* @deprecated Use fromContent() with interpolation property instead.
|
|
74
|
+
* This method is kept for backward compatibility.
|
|
75
|
+
*
|
|
76
|
+
* @param langService - The language service instance
|
|
77
|
+
* @param config - Interpolated content configuration
|
|
78
|
+
* @returns Observable that emits the interpolated content string
|
|
79
|
+
*
|
|
80
|
+
* @example Migration:
|
|
81
|
+
* ```typescript
|
|
82
|
+
* // OLD (deprecated):
|
|
83
|
+
* this.greeting$ = fromContentWithInterpolation(this.langService, {
|
|
84
|
+
* className: 'WelcomeComponent',
|
|
85
|
+
* key: 'greeting',
|
|
86
|
+
* interpolation: { name: 'John', count: 5 }
|
|
87
|
+
* });
|
|
88
|
+
*
|
|
89
|
+
* // NEW (recommended):
|
|
90
|
+
* this.greeting$ = fromContent(this.langService, {
|
|
91
|
+
* className: 'WelcomeComponent',
|
|
92
|
+
* key: 'greeting',
|
|
93
|
+
* interpolation: { name: 'John', count: 5 }
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare function fromContentWithInterpolation(langService: LangService, config: InterpolatedContentConfig): Observable<string>;
|
|
98
|
+
/**
|
|
99
|
+
* Create multiple reactive content observables at once.
|
|
100
|
+
* Useful when a component needs several content strings.
|
|
101
|
+
*
|
|
102
|
+
* @param langService - The language service instance
|
|
103
|
+
* @param className - The component class name
|
|
104
|
+
* @param keys - Array of content keys to retrieve
|
|
105
|
+
* @returns Observable that emits an object with all requested content
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* this.content$ = fromMultipleContent(this.langService, 'FormComponent', [
|
|
110
|
+
* 'title', 'submitButton', 'cancelButton'
|
|
111
|
+
* ]);
|
|
112
|
+
*
|
|
113
|
+
* // In template
|
|
114
|
+
* <ng-container *ngIf="content$ | async as content">
|
|
115
|
+
* <h2>{{ content.title }}</h2>
|
|
116
|
+
* <button>{{ content.submitButton }}</button>
|
|
117
|
+
* <button>{{ content.cancelButton }}</button>
|
|
118
|
+
* </ng-container>
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare function fromMultipleContent(langService: LangService, className: string, keys: string[]): Observable<Record<string, string>>;
|
|
122
|
+
/**
|
|
123
|
+
* Helper function to interpolate values into a content string.
|
|
124
|
+
* Replaces placeholders in the format {key} with corresponding values.
|
|
125
|
+
*
|
|
126
|
+
* @param content - The content string with placeholders
|
|
127
|
+
* @param values - Object with values to interpolate
|
|
128
|
+
* @returns The interpolated string
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const result = interpolateContent("Hello {name}!", { name: "World" });
|
|
133
|
+
* // Returns: "Hello World!"
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export declare function interpolateContent(content: string, values?: Record<string, string | number>): string;
|
|
137
|
+
/**
|
|
138
|
+
* Type-safe content key builder for better IDE support.
|
|
139
|
+
* This is a utility type that can be used to ensure content keys exist.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* // Define your component's content keys
|
|
144
|
+
* interface MyComponentContent {
|
|
145
|
+
* title: string;
|
|
146
|
+
* description: string;
|
|
147
|
+
* submitButton: string;
|
|
148
|
+
* }
|
|
149
|
+
*
|
|
150
|
+
* // Use with type safety
|
|
151
|
+
* const titleKey: ContentKey<MyComponentContent> = 'title'; // ✓ Valid
|
|
152
|
+
* const invalidKey: ContentKey<MyComponentContent> = 'invalid'; // ✗ Type error
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export type ContentKey<T> = keyof T & string;
|
|
156
|
+
/**
|
|
157
|
+
* Factory function to create a content helper bound to a specific component class.
|
|
158
|
+
* This creates a more convenient API for components that need multiple content strings.
|
|
159
|
+
*
|
|
160
|
+
* @param langService - The language service instance
|
|
161
|
+
* @param className - The component class name
|
|
162
|
+
* @returns Object with convenient methods for content retrieval
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* export class MyComponent {
|
|
167
|
+
* private content = createContentHelper(this.langService, 'MyComponent');
|
|
168
|
+
*
|
|
169
|
+
* constructor(private langService: LangService) {}
|
|
170
|
+
*
|
|
171
|
+
* ngOnInit() {
|
|
172
|
+
* this.title$ = this.content.get('title');
|
|
173
|
+
* this.allContent$ = this.content.getMultiple(['title', 'description']);
|
|
174
|
+
* }
|
|
175
|
+
* }
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
export declare function createContentHelper(langService: LangService, className: string): {
|
|
179
|
+
/**
|
|
180
|
+
* Get a single content string reactively.
|
|
181
|
+
*/
|
|
182
|
+
get(key: string, fallback?: string): Observable<string>;
|
|
183
|
+
/**
|
|
184
|
+
* Get multiple content strings reactively.
|
|
185
|
+
*/
|
|
186
|
+
getMultiple(keys: string[]): Observable<Record<string, string>>;
|
|
187
|
+
/**
|
|
188
|
+
* Get content with interpolation.
|
|
189
|
+
*/
|
|
190
|
+
getWithInterpolation(key: string, interpolation: Record<string, string | number>, fallback?: string): Observable<string>;
|
|
191
|
+
/**
|
|
192
|
+
* Get a single content string synchronously (current language only).
|
|
193
|
+
*/
|
|
194
|
+
getText(key: string, fallback?: string): string;
|
|
195
|
+
/**
|
|
196
|
+
* Check if a content key exists.
|
|
197
|
+
*/
|
|
198
|
+
hasContent(key: string): boolean;
|
|
199
|
+
};
|
package/package.json
CHANGED
package/public-api.d.ts
CHANGED
|
@@ -37,6 +37,8 @@ export * from './lib/components/molecules/expandable-text/types';
|
|
|
37
37
|
export * from './lib/components/molecules/file-input/file-input.component';
|
|
38
38
|
export * from './lib/components/molecules/hint/hint.component';
|
|
39
39
|
export * from './lib/components/molecules/hour-input/hour-input.component';
|
|
40
|
+
export * from './lib/components/molecules/layered-card/layered-card.component';
|
|
41
|
+
export * from './lib/components/molecules/layered-card/types';
|
|
40
42
|
export * from './lib/components/molecules/link/link.component';
|
|
41
43
|
export * from './lib/components/molecules/link/types';
|
|
42
44
|
export * from './lib/components/molecules/links-cake/links-cake.component';
|
|
@@ -51,14 +53,12 @@ export * from './lib/components/molecules/progress-status/types';
|
|
|
51
53
|
export * from './lib/components/molecules/prompter/prompter.component';
|
|
52
54
|
export * from './lib/components/molecules/prompter/types';
|
|
53
55
|
export * from './lib/components/molecules/radio-input/radio-input.component';
|
|
54
|
-
export * from './lib/components/molecules/select-search/select-search.component';
|
|
55
56
|
export * from './lib/components/molecules/searchbar/searchbar.component';
|
|
56
57
|
export * from './lib/components/molecules/select-input/select-input.component';
|
|
58
|
+
export * from './lib/components/molecules/select-search/select-search.component';
|
|
57
59
|
export * from './lib/components/molecules/text-input/text-input.component';
|
|
58
60
|
export * from './lib/components/molecules/title-block/title-block.component';
|
|
59
61
|
export * from './lib/components/molecules/title-block/types';
|
|
60
|
-
export * from './lib/components/molecules/layered-card/layered-card.component';
|
|
61
|
-
export * from './lib/components/molecules/layered-card/types';
|
|
62
62
|
export * from './lib/components/organisms/banner/banner.component';
|
|
63
63
|
export * from './lib/components/organisms/banner/types';
|
|
64
64
|
export * from './lib/components/organisms/footer/footer.component';
|
|
@@ -79,9 +79,13 @@ export * from './lib/components/organisms/wizard/wizard.component';
|
|
|
79
79
|
export * from './lib/components/templates/layout/layout.component';
|
|
80
80
|
export * from './lib/components/templates/simple/simple.component';
|
|
81
81
|
export * from './lib/components/templates/simple/types';
|
|
82
|
+
export * from './lib/components/_examples/global-content-example.component';
|
|
83
|
+
export * from './lib/components/_examples/reactive-content-example.component';
|
|
84
|
+
export * from './lib/services/content.service';
|
|
82
85
|
export * from './lib/services/download.service';
|
|
83
86
|
export * from './lib/services/icons.service';
|
|
84
87
|
export * from './lib/services/in-app-browser.service';
|
|
88
|
+
export * from './lib/services/lang-provider/content';
|
|
85
89
|
export * from './lib/services/lang-provider/lang-provider.service';
|
|
86
90
|
export * from './lib/services/lang-provider/types';
|
|
87
91
|
export * from './lib/services/local-storage.service';
|
|
@@ -90,6 +94,8 @@ export * from './lib/services/theme.service';
|
|
|
90
94
|
export * from './lib/services/toast.service';
|
|
91
95
|
export * from './lib/services/types';
|
|
92
96
|
export * from './lib/components/types';
|
|
97
|
+
export * from './lib/shared/utils/content';
|
|
93
98
|
export * from './lib/shared/utils/dom';
|
|
94
|
-
export * from './lib/shared/utils/
|
|
99
|
+
export * from './lib/shared/utils/form-defaults';
|
|
95
100
|
export * from './lib/shared/utils/styles';
|
|
101
|
+
export * from './lib/shared/utils/text';
|