valtech-components 2.0.277 → 2.0.278

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 (26) hide show
  1. package/README.md +149 -6
  2. package/esm2022/lib/components/_examples/global-content-example-content.mjs +23 -0
  3. package/esm2022/lib/components/_examples/global-content-example.component.mjs +504 -0
  4. package/esm2022/lib/components/_examples/reactive-content-example-content.mjs +43 -0
  5. package/esm2022/lib/components/_examples/reactive-content-example.component.mjs +347 -0
  6. package/esm2022/lib/components/atoms/text/text.component.mjs +143 -15
  7. package/esm2022/lib/components/atoms/text/types.mjs +1 -1
  8. package/esm2022/lib/services/content.service.mjs +327 -0
  9. package/esm2022/lib/services/icons.service.mjs +3 -2
  10. package/esm2022/lib/services/lang-provider/content.mjs +136 -1
  11. package/esm2022/lib/services/lang-provider/lang-provider.service.mjs +118 -8
  12. package/esm2022/lib/shared/utils/content.mjs +186 -0
  13. package/esm2022/public-api.mjs +11 -5
  14. package/fesm2022/valtech-components.mjs +2938 -1359
  15. package/fesm2022/valtech-components.mjs.map +1 -1
  16. package/lib/components/_examples/global-content-example-content.d.ts +9 -0
  17. package/lib/components/_examples/global-content-example.component.d.ts +73 -0
  18. package/lib/components/_examples/reactive-content-example-content.d.ts +32 -0
  19. package/lib/components/_examples/reactive-content-example.component.d.ts +47 -0
  20. package/lib/components/atoms/text/text.component.d.ts +57 -8
  21. package/lib/components/atoms/text/types.d.ts +26 -5
  22. package/lib/services/content.service.d.ts +296 -0
  23. package/lib/services/lang-provider/lang-provider.service.d.ts +87 -7
  24. package/lib/shared/utils/content.d.ts +199 -0
  25. package/package.json +1 -1
  26. package/public-api.d.ts +9 -4
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "valtech-components",
3
- "version": "2.0.277",
3
+ "version": "2.0.278",
4
4
  "peerDependencies": {
5
5
  "@angular/common": "^18.0.0",
6
6
  "@angular/core": "^18.0.0",
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,6 +79,9 @@ 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';
@@ -90,6 +93,8 @@ export * from './lib/services/theme.service';
90
93
  export * from './lib/services/toast.service';
91
94
  export * from './lib/services/types';
92
95
  export * from './lib/components/types';
96
+ export * from './lib/shared/utils/content';
93
97
  export * from './lib/shared/utils/dom';
94
- export * from './lib/shared/utils/text';
98
+ export * from './lib/shared/utils/form-defaults';
95
99
  export * from './lib/shared/utils/styles';
100
+ export * from './lib/shared/utils/text';