valtech-components 2.0.325 → 2.0.328

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.
Files changed (30) hide show
  1. package/esm2022/lib/components/atoms/button/button.component.mjs +18 -18
  2. package/esm2022/lib/components/atoms/display/display.component.mjs +13 -16
  3. package/esm2022/lib/components/atoms/text/text.component.mjs +19 -19
  4. package/esm2022/lib/components/atoms/title/title.component.mjs +7 -7
  5. package/esm2022/lib/components/atoms/title/types.mjs +6 -2
  6. package/esm2022/lib/components/molecules/alert-box/alert-box.component.mjs +6 -6
  7. package/esm2022/lib/components/molecules/language-selector/language-selector.component.mjs +6 -17
  8. package/esm2022/lib/components/organisms/form/form.component.mjs +1 -1
  9. package/esm2022/lib/services/lang-provider/lang-provider.service.mjs +198 -2
  10. package/esm2022/lib/shared/utils/simple-content.mjs +119 -0
  11. package/esm2022/public-api.mjs +3 -4
  12. package/fesm2022/valtech-components.mjs +520 -837
  13. package/fesm2022/valtech-components.mjs.map +1 -1
  14. package/lib/components/atoms/button/button.component.d.ts +3 -3
  15. package/lib/components/atoms/display/display.component.d.ts +2 -3
  16. package/lib/components/atoms/text/text.component.d.ts +3 -3
  17. package/lib/components/atoms/title/title.component.d.ts +1 -2
  18. package/lib/components/atoms/title/types.d.ts +10 -4
  19. package/lib/components/molecules/alert-box/alert-box.component.d.ts +3 -3
  20. package/lib/components/molecules/language-selector/language-selector.component.d.ts +1 -3
  21. package/lib/services/lang-provider/lang-provider.service.d.ts +108 -1
  22. package/lib/shared/utils/simple-content.d.ts +120 -0
  23. package/package.json +1 -1
  24. package/public-api.d.ts +1 -3
  25. package/esm2022/lib/services/content-loader.service.mjs +0 -185
  26. package/esm2022/lib/services/content.service.mjs +0 -327
  27. package/esm2022/lib/shared/utils/reactive-content.mjs +0 -117
  28. package/lib/services/content-loader.service.d.ts +0 -98
  29. package/lib/services/content.service.d.ts +0 -296
  30. package/lib/shared/utils/reactive-content.d.ts +0 -109
@@ -1,296 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- import { ContentConfig, InterpolatedContentConfig } from '../shared/utils/content';
3
- import { LangService } from './lang-provider/lang-provider.service';
4
- import { LangOption } from './lang-provider/types';
5
- import * as i0 from "@angular/core";
6
- /**
7
- * ContentService - High-level reactive content management service.
8
- *
9
- * This service provides a clean, convenient API for reactive content management
10
- * without requiring direct interaction with LangService. It acts as a facade
11
- * that simplifies the most common content operations.
12
- *
13
- * @example Basic usage:
14
- * ```typescript
15
- * @Component({})
16
- * export class MyComponent {
17
- * content = inject(ContentService);
18
- *
19
- * title$ = this.content.fromContent({
20
- * className: 'MyComponent',
21
- * key: 'title'
22
- * });
23
- *
24
- * constructor() {}
25
- * }
26
- * ```
27
- */
28
- export declare class ContentService {
29
- private langService;
30
- constructor(langService: LangService);
31
- /**
32
- * Get current language as an observable stream.
33
- * Emits whenever the language changes.
34
- */
35
- get currentLang$(): Observable<LangOption>;
36
- /**
37
- * Get current language synchronously.
38
- */
39
- get currentLang(): LangOption;
40
- /**
41
- * Set the current language.
42
- * This will trigger updates in all reactive content.
43
- *
44
- * @param lang - The language to set
45
- */
46
- setLang(lang: LangOption): void;
47
- /**
48
- * Create a reactive content observable from a content key.
49
- * This is the primary method for reactive content with unified support
50
- * for both simple content and content with interpolation.
51
- *
52
- * @param config - Content configuration with optional interpolation. If className is omitted, searches in global content.
53
- * @returns Observable that emits the content string and updates on language change
54
- *
55
- * @example Simple global content:
56
- * ```typescript
57
- * // Searches in global content (no className needed)
58
- * okButton$ = this.content.fromContent({
59
- * key: 'ok',
60
- * fallback: 'OK'
61
- * });
62
- * ```
63
- *
64
- * @example Component-specific content:
65
- * ```typescript
66
- * title$ = this.content.fromContent({
67
- * className: 'HeaderComponent',
68
- * key: 'title',
69
- * fallback: 'Default Title'
70
- * });
71
- * ```
72
- *
73
- * @example Content with interpolation:
74
- * ```typescript
75
- * // Global content with interpolation
76
- * confirmation$ = this.content.fromContent({
77
- * key: 'deleteConfirmation',
78
- * interpolation: { itemName: 'archivo' }
79
- * });
80
- *
81
- * // Component content with interpolation
82
- * greeting$ = this.content.fromContent({
83
- * className: 'WelcomeComponent',
84
- * key: 'greeting',
85
- * interpolation: { name: 'John', count: 5 }
86
- * });
87
- * ```
88
- */
89
- fromContent(config: ContentConfig): Observable<string>;
90
- /**
91
- * Create a reactive content observable with interpolation support.
92
- *
93
- * @deprecated Use fromContent() with interpolation property instead.
94
- * This method is kept for backward compatibility.
95
- *
96
- * @param config - Interpolated content configuration. If className is omitted, searches in global content.
97
- * @returns Observable that emits the interpolated content string
98
- *
99
- * @example Migration:
100
- * ```typescript
101
- * // OLD (deprecated):
102
- * greeting$ = this.content.fromContentWithInterpolation({
103
- * className: 'WelcomeComponent',
104
- * key: 'greeting',
105
- * interpolation: { name: 'John', count: 5 }
106
- * });
107
- *
108
- * // NEW (recommended):
109
- * greeting$ = this.content.fromContent({
110
- * className: 'WelcomeComponent',
111
- * key: 'greeting',
112
- * interpolation: { name: 'John', count: 5 }
113
- * });
114
- * ```
115
- */
116
- fromContentWithInterpolation(config: InterpolatedContentConfig | Omit<InterpolatedContentConfig, 'className'>): Observable<string>;
117
- /**
118
- * Create multiple reactive content observables at once.
119
- * Useful when a component needs several content strings.
120
- *
121
- * @param className - The component class name
122
- * @param keys - Array of content keys to retrieve
123
- * @returns Observable that emits an object with all requested content
124
- *
125
- * @example
126
- * ```typescript
127
- * content$ = this.content.fromMultipleContent('FormComponent', [
128
- * 'title', 'submitButton', 'cancelButton'
129
- * ]);
130
- *
131
- * // In template
132
- * <ng-container *ngIf="content$ | async as content">
133
- * <h2>{{ content['title'] }}</h2>
134
- * <button>{{ content['submitButton'] }}</button>
135
- * <button>{{ content['cancelButton'] }}</button>
136
- * </ng-container>
137
- * ```
138
- */
139
- fromMultipleContent(className: string, keys: string[]): Observable<Record<string, string>>;
140
- /**
141
- * Get a single content string synchronously for the current language.
142
- *
143
- * @param className - The component class name. If omitted, searches in global content.
144
- * @param key - The text key
145
- * @param fallback - Optional fallback text if key is not found
146
- * @returns The text string or fallback
147
- *
148
- * @example Component-specific:
149
- * ```typescript
150
- * const title = this.content.getText('MyComponent', 'title');
151
- * ```
152
- *
153
- * @example Global content:
154
- * ```typescript
155
- * const okText = this.content.getText('ok'); // First parameter is the key
156
- * // or more explicitly:
157
- * const okText = this.content.getGlobalText('ok');
158
- * ```
159
- */
160
- getText(className: string, key?: string, fallback?: string): string;
161
- getText(key: string, fallback?: string): string;
162
- /**
163
- * Get a single global content string synchronously.
164
- * This is a convenience method that's equivalent to getText(key, fallback).
165
- *
166
- * @param key - The text key
167
- * @param fallback - Optional fallback text if key is not found
168
- * @returns The text string or fallback
169
- *
170
- * @example
171
- * ```typescript
172
- * const okText = this.content.getGlobalText('ok');
173
- * const cancelText = this.content.getGlobalText('cancel', 'Cancel');
174
- * ```
175
- */
176
- getGlobalText(key: string, fallback?: string): string;
177
- /**
178
- * Check if a content key exists for a component.
179
- *
180
- * @param className - The component class name
181
- * @param key - The text key
182
- * @returns True if the key exists in any language
183
- *
184
- * @example
185
- * ```typescript
186
- * if (this.content.hasContent('MyComponent', 'optionalText')) {
187
- * // Show optional content
188
- * }
189
- * ```
190
- */
191
- hasContent(className: string, key: string): boolean;
192
- /**
193
- * Helper function to interpolate values into a content string.
194
- * Useful for processing content strings manually.
195
- *
196
- * @param content - The content string with placeholders
197
- * @param values - Object with values to interpolate
198
- * @returns The interpolated string
199
- *
200
- * @example
201
- * ```typescript
202
- * const result = this.content.interpolate("Hello {name}!", { name: "World" });
203
- * // Returns: "Hello World!"
204
- * ```
205
- */
206
- interpolate(content: string, values?: Record<string, string | number>): string;
207
- /**
208
- * Create a content helper bound to a specific component class.
209
- * This provides a scoped API for components that need multiple content strings.
210
- *
211
- * @param className - The component class name
212
- * @returns Content helper with methods scoped to the class
213
- *
214
- * @example
215
- * ```typescript
216
- * export class MyComponent {
217
- * private contentHelper = this.content.createHelper('MyComponent');
218
- *
219
- * ngOnInit() {
220
- * this.title$ = this.contentHelper.get('title');
221
- * this.allContent$ = this.contentHelper.getMultiple(['title', 'description']);
222
- * }
223
- *
224
- * constructor(private content: ContentService) {}
225
- * }
226
- * ```
227
- */
228
- createHelper(className: string): {
229
- get(key: string, fallback?: string): Observable<string>;
230
- getMultiple(keys: string[]): Observable<Record<string, string>>;
231
- getWithInterpolation(key: string, interpolation: Record<string, string | number>, fallback?: string): Observable<string>;
232
- getText(key: string, fallback?: string): string;
233
- hasContent(key: string): boolean;
234
- };
235
- /**
236
- * Create a scoped content service for a specific component class.
237
- * This provides an even more convenient API for components with many content needs.
238
- *
239
- * @param className - The component class name
240
- * @returns Scoped content service
241
- *
242
- * @example
243
- * ```typescript
244
- * export class MyComponent {
245
- * private content = inject(ContentService).forComponent('MyComponent');
246
- *
247
- * // Simple content
248
- * title$ = this.content.get('title');
249
- *
250
- * // Content with interpolation
251
- * greeting$ = this.content.get('greeting', {
252
- * interpolation: { name: 'John' }
253
- * });
254
- *
255
- * // Content with fallback
256
- * subtitle$ = this.content.get('subtitle', {
257
- * fallback: 'Default Subtitle'
258
- * });
259
- *
260
- * // Multiple texts
261
- * allTexts$ = this.content.getMultiple(['title', 'subtitle', 'description']);
262
- *
263
- * constructor() {}
264
- * }
265
- * ```
266
- */
267
- forComponent(className: string): {
268
- /**
269
- * Get a single content string reactively for this component.
270
- * Supports optional interpolation.
271
- */
272
- get: (key: string, options?: {
273
- fallback?: string;
274
- interpolation?: Record<string, string | number>;
275
- }) => Observable<string>;
276
- /**
277
- * Get content with interpolation for this component.
278
- * @deprecated Use get() with interpolation option instead.
279
- */
280
- getWithInterpolation: (key: string, interpolation: Record<string, string | number>, fallback?: string) => Observable<string>;
281
- /**
282
- * Get multiple content strings for this component.
283
- */
284
- getMultiple: (keys: string[]) => Observable<Record<string, string>>;
285
- /**
286
- * Get a single content string synchronously for this component.
287
- */
288
- getText: (key: string, fallback?: string) => string;
289
- /**
290
- * Check if a content key exists for this component.
291
- */
292
- hasContent: (key: string) => boolean;
293
- };
294
- static ɵfac: i0.ɵɵFactoryDeclaration<ContentService, never>;
295
- static ɵprov: i0.ɵɵInjectableDeclaration<ContentService>;
296
- }
@@ -1,109 +0,0 @@
1
- /**
2
- * Enhanced content utilities for multi-language component support.
3
- * Extends the base content utilities to provide specialized helpers for different component patterns.
4
- */
5
- import { Observable } from 'rxjs';
6
- import { ContentService } from '../../services/content.service';
7
- /**
8
- * Base configuration for reactive content.
9
- */
10
- export interface ReactiveContentConfig {
11
- /** Content class name - defaults to '_global' if not provided */
12
- className?: string;
13
- /** Content key */
14
- key: string;
15
- /** Fallback text if content is not found */
16
- fallback?: string;
17
- /** Interpolation data for parameterized content */
18
- interpolation?: Record<string, any>;
19
- }
20
- /**
21
- * Configuration for components that support both static and reactive content.
22
- */
23
- export interface HybridContentConfig {
24
- /** Static content - takes precedence over reactive content */
25
- content?: string;
26
- /** Reactive content configuration */
27
- contentConfig?: ReactiveContentConfig;
28
- }
29
- /**
30
- * Configuration for components with multiple text properties.
31
- */
32
- export interface MultiTextConfig {
33
- /** Map of property names to their content configurations */
34
- textConfigs: Record<string, ReactiveContentConfig>;
35
- }
36
- /**
37
- * Enhanced metadata for components that support reactive content.
38
- */
39
- export interface ReactiveTextMetadata extends HybridContentConfig {
40
- size?: 'small' | 'medium' | 'large' | 'xlarge';
41
- color?: string;
42
- bold?: boolean;
43
- processLinks?: boolean;
44
- linkConfig?: any;
45
- }
46
- /**
47
- * Helper class for managing reactive content in components.
48
- */
49
- export declare class ComponentContentHelper {
50
- private contentService;
51
- private defaultClassName?;
52
- constructor(contentService: ContentService, defaultClassName?: string);
53
- /**
54
- * Resolves content based on hybrid configuration (static vs reactive).
55
- */
56
- resolveContent(config: HybridContentConfig): Observable<string> | string;
57
- /**
58
- * Resolves multiple text properties for components with multiple text fields.
59
- */
60
- resolveMultipleTexts(config: MultiTextConfig): Record<string, Observable<string>>;
61
- /**
62
- * Creates a reactive content configuration for array items.
63
- * Useful for list components where items might have translatable text.
64
- */
65
- createArrayItemConfig(baseKey: string, index: number, fallback?: string): ReactiveContentConfig;
66
- /**
67
- * Helper for button/action text that commonly needs translation.
68
- */
69
- createActionConfig(actionKey: 'ok' | 'cancel' | 'save' | 'delete' | 'edit' | 'close' | 'back' | 'next' | 'previous' | 'finish' | 'continue' | 'add' | 'remove' | 'search' | 'filter' | 'sort' | 'refresh', fallback?: string): ReactiveContentConfig;
70
- }
71
- /**
72
- * Factory function to create content helpers for components.
73
- */
74
- export declare function createComponentContentHelper(contentService: ContentService, componentClassName?: string): ComponentContentHelper;
75
- /**
76
- * Utility function to determine if content should be reactive.
77
- */
78
- export declare function shouldUseReactiveContent(config: HybridContentConfig): boolean;
79
- /**
80
- * Enhanced props factory for components that support reactive content.
81
- */
82
- export declare function createReactiveProps<T extends Record<string, any>>(contentHelper: ComponentContentHelper, staticProps: Omit<T, keyof HybridContentConfig>, contentConfig: HybridContentConfig): T;
83
- /**
84
- * Configuration for list components that mix static and dynamic content.
85
- */
86
- export interface ListComponentConfig<T> {
87
- /** Static items that don't need translation */
88
- staticItems?: T[];
89
- /** Reactive items configuration */
90
- reactiveItems?: {
91
- /** Base key for the items (e.g., 'navigationLinks') */
92
- baseKey: string;
93
- /** Number of items expected */
94
- count: number;
95
- /** Template for creating individual items */
96
- itemTemplate: (contentHelper: ComponentContentHelper, index: number) => T;
97
- };
98
- }
99
- /**
100
- * Helper for list components that need to mix static and reactive content.
101
- */
102
- export declare class ListContentHelper<T> {
103
- private contentHelper;
104
- constructor(contentHelper: ComponentContentHelper);
105
- /**
106
- * Resolves a list configuration into final items.
107
- */
108
- resolveListItems(config: ListComponentConfig<T>): T[];
109
- }