mn-angular-lib 0.0.45 → 0.0.46
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,7 +1,7 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { InjectionToken, Injectable, Optional, Inject, inject, Input, ChangeDetectionStrategy, Component, HostBinding, Self, APP_INITIALIZER, ElementRef, HostListener, forwardRef, Directive, EventEmitter, TemplateRef, Output, ViewChildren, ViewContainerRef, ViewChild, ApplicationRef, EnvironmentInjector, createComponent, SkipSelf, Attribute, Pipe } from '@angular/core';
|
|
2
|
+
import { InjectionToken, Injectable, Optional, Inject, inject, Input, ChangeDetectionStrategy, Component, HostBinding, Self, DestroyRef, APP_INITIALIZER, ElementRef, HostListener, forwardRef, Directive, EventEmitter, TemplateRef, Output, ViewChildren, ViewContainerRef, ViewChild, ApplicationRef, EnvironmentInjector, createComponent, SkipSelf, Attribute, Pipe } from '@angular/core';
|
|
3
3
|
export { TemplateRef, Type } from '@angular/core';
|
|
4
|
-
import { BehaviorSubject, firstValueFrom, Subject, debounceTime, map, catchError, of } from 'rxjs';
|
|
4
|
+
import { BehaviorSubject, firstValueFrom, skip, Subject, debounceTime, map, catchError, of } from 'rxjs';
|
|
5
5
|
import * as i1 from '@angular/common';
|
|
6
6
|
import { CommonModule, NgClass, NgOptimizedImage, NgForOf, NgIf, NgTemplateOutlet } from '@angular/common';
|
|
7
7
|
import { tv } from 'tailwind-variants';
|
|
@@ -1119,16 +1119,39 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImpor
|
|
|
1119
1119
|
* providers: [ provideMnComponentConfig(MY_CFG, 'my-component') ]
|
|
1120
1120
|
* Then in the component:
|
|
1121
1121
|
* readonly cfg = inject(MY_CFG)
|
|
1122
|
+
*
|
|
1123
|
+
* The returned config object is **reactive**: when the active locale changes,
|
|
1124
|
+
* all translatable values are re-resolved in place so that templates using
|
|
1125
|
+
* `cfg.someLabel` automatically reflect the new language on the next change-detection cycle.
|
|
1122
1126
|
*/
|
|
1123
1127
|
function provideMnComponentConfig(token, componentName, initial) {
|
|
1124
1128
|
return {
|
|
1125
1129
|
provide: token,
|
|
1126
|
-
deps: [
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1130
|
+
deps: [
|
|
1131
|
+
MnConfigService,
|
|
1132
|
+
MnLanguageService,
|
|
1133
|
+
DestroyRef,
|
|
1134
|
+
[new Optional(), MN_SECTION_PATH],
|
|
1135
|
+
[new Optional(), MN_INSTANCE_ID],
|
|
1136
|
+
],
|
|
1137
|
+
useFactory: (svc, lang, destroyRef, sectionPath, instanceId) => {
|
|
1138
|
+
const resolveConfig = () => {
|
|
1139
|
+
const resolved = svc.resolve(componentName, sectionPath ?? [], instanceId ?? undefined);
|
|
1140
|
+
return Object.assign({}, initial ?? {}, resolved);
|
|
1141
|
+
};
|
|
1142
|
+
// Create the initial config object that will be shared by reference.
|
|
1143
|
+
const cfg = resolveConfig();
|
|
1144
|
+
// Re-resolve translatable values whenever the locale changes.
|
|
1145
|
+
// skip(1) because the current locale was already used for the initial resolve.
|
|
1146
|
+
const sub = lang.locale$.pipe(skip(1)).subscribe(() => {
|
|
1147
|
+
const updated = resolveConfig();
|
|
1148
|
+
// Mutate the existing object in place so all template bindings pick up the new values.
|
|
1149
|
+
for (const key of Object.keys(updated)) {
|
|
1150
|
+
cfg[key] = updated[key];
|
|
1151
|
+
}
|
|
1152
|
+
});
|
|
1153
|
+
destroyRef.onDestroy(() => sub.unsubscribe());
|
|
1154
|
+
return cfg;
|
|
1132
1155
|
},
|
|
1133
1156
|
};
|
|
1134
1157
|
}
|