mn-angular-lib 0.0.45 → 0.0.47

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';
@@ -755,6 +755,17 @@ class MnConfigService {
755
755
  if (isTranslatable(value)) {
756
756
  out[key] = this.lang.translate(value.$translate, value.params);
757
757
  }
758
+ else if (Array.isArray(value)) {
759
+ out[key] = value.map(item => {
760
+ if (isTranslatable(item)) {
761
+ return this.lang.translate(item.$translate, item.params);
762
+ }
763
+ else if (isPlainObject(item)) {
764
+ return this.resolveTranslatables(item);
765
+ }
766
+ return item;
767
+ });
768
+ }
758
769
  else if (isPlainObject(value)) {
759
770
  out[key] = this.resolveTranslatables(value);
760
771
  }
@@ -1119,16 +1130,39 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImpor
1119
1130
  * providers: [ provideMnComponentConfig(MY_CFG, 'my-component') ]
1120
1131
  * Then in the component:
1121
1132
  * readonly cfg = inject(MY_CFG)
1133
+ *
1134
+ * The returned config object is **reactive**: when the active locale changes,
1135
+ * all translatable values are re-resolved in place so that templates using
1136
+ * `cfg.someLabel` automatically reflect the new language on the next change-detection cycle.
1122
1137
  */
1123
1138
  function provideMnComponentConfig(token, componentName, initial) {
1124
1139
  return {
1125
1140
  provide: token,
1126
- deps: [MnConfigService, [new Optional(), MN_SECTION_PATH], [new Optional(), MN_INSTANCE_ID]],
1127
- useFactory: (svc, sectionPath, instanceId) => {
1128
- const resolved = svc.resolve(componentName, sectionPath ?? [], instanceId ?? undefined);
1129
- // Apply optional initial (local defaults) over resolved? We prefer resolved to override initial local defaults,
1130
- // so merge initial first, then resolved on top.
1131
- return Object.assign({}, initial ?? {}, resolved);
1141
+ deps: [
1142
+ MnConfigService,
1143
+ MnLanguageService,
1144
+ DestroyRef,
1145
+ [new Optional(), MN_SECTION_PATH],
1146
+ [new Optional(), MN_INSTANCE_ID],
1147
+ ],
1148
+ useFactory: (svc, lang, destroyRef, sectionPath, instanceId) => {
1149
+ const resolveConfig = () => {
1150
+ const resolved = svc.resolve(componentName, sectionPath ?? [], instanceId ?? undefined);
1151
+ return Object.assign({}, initial ?? {}, resolved);
1152
+ };
1153
+ // Create the initial config object that will be shared by reference.
1154
+ const cfg = resolveConfig();
1155
+ // Re-resolve translatable values whenever the locale changes.
1156
+ // skip(1) because the current locale was already used for the initial resolve.
1157
+ const sub = lang.locale$.pipe(skip(1)).subscribe(() => {
1158
+ const updated = resolveConfig();
1159
+ // Mutate the existing object in place so all template bindings pick up the new values.
1160
+ for (const key of Object.keys(updated)) {
1161
+ cfg[key] = updated[key];
1162
+ }
1163
+ });
1164
+ destroyRef.onDestroy(() => sub.unsubscribe());
1165
+ return cfg;
1132
1166
  },
1133
1167
  };
1134
1168
  }