mn-angular-lib 0.0.53 → 0.0.55
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.
|
@@ -173,11 +173,11 @@ const mnAlertVariants = tv({
|
|
|
173
173
|
base: 'flex items-start gap-3 p-4 border rounded-xl shadow-sm transition-all duration-300',
|
|
174
174
|
variants: {
|
|
175
175
|
kind: {
|
|
176
|
-
success: 'bg-
|
|
177
|
-
info: 'bg-
|
|
178
|
-
warning: 'bg-
|
|
179
|
-
error: 'bg-
|
|
180
|
-
default: 'bg-
|
|
176
|
+
success: 'bg-success/10 border-success/30 text-success',
|
|
177
|
+
info: 'bg-info/10 border-info/30 text-info',
|
|
178
|
+
warning: 'bg-warning/10 border-warning/30 text-warning',
|
|
179
|
+
error: 'bg-error/10 border-error/30 text-error',
|
|
180
|
+
default: 'bg-base-100 border-base-300 text-base-content',
|
|
181
181
|
},
|
|
182
182
|
variant: {
|
|
183
183
|
fill: '',
|
|
@@ -189,22 +189,22 @@ const mnAlertVariants = tv({
|
|
|
189
189
|
{
|
|
190
190
|
kind: 'success',
|
|
191
191
|
variant: 'fill',
|
|
192
|
-
class: 'bg-
|
|
192
|
+
class: 'bg-success border-success text-success-content'
|
|
193
193
|
},
|
|
194
194
|
{
|
|
195
195
|
kind: 'info',
|
|
196
196
|
variant: 'fill',
|
|
197
|
-
class: 'bg-
|
|
197
|
+
class: 'bg-info border-info text-info-content'
|
|
198
198
|
},
|
|
199
199
|
{
|
|
200
200
|
kind: 'warning',
|
|
201
201
|
variant: 'fill',
|
|
202
|
-
class: 'bg-
|
|
202
|
+
class: 'bg-warning border-warning text-warning-content'
|
|
203
203
|
},
|
|
204
204
|
{
|
|
205
205
|
kind: 'error',
|
|
206
206
|
variant: 'fill',
|
|
207
|
-
class: 'bg-
|
|
207
|
+
class: 'bg-error border-error text-error-content'
|
|
208
208
|
}
|
|
209
209
|
],
|
|
210
210
|
defaultVariants: {
|
|
@@ -289,23 +289,23 @@ const mnButtonVariants = tv({
|
|
|
289
289
|
},
|
|
290
290
|
compoundVariants: [
|
|
291
291
|
// Fill
|
|
292
|
-
{ variant: 'fill', color: 'primary', class: 'bg-
|
|
293
|
-
{ variant: 'fill', color: 'secondary', class: 'bg-
|
|
294
|
-
{ variant: 'fill', color: 'danger', class: 'bg-
|
|
295
|
-
{ variant: 'fill', color: 'warning', class: 'bg-
|
|
296
|
-
{ variant: 'fill', color: 'success', class: 'bg-
|
|
292
|
+
{ variant: 'fill', color: 'primary', class: 'bg-primary text-primary-content hover:bg-primary/80' },
|
|
293
|
+
{ variant: 'fill', color: 'secondary', class: 'bg-neutral text-neutral-content hover:bg-neutral/80' },
|
|
294
|
+
{ variant: 'fill', color: 'danger', class: 'bg-error text-error-content hover:bg-error/80' },
|
|
295
|
+
{ variant: 'fill', color: 'warning', class: 'bg-warning text-warning-content hover:bg-warning/80' },
|
|
296
|
+
{ variant: 'fill', color: 'success', class: 'bg-success text-success-content hover:bg-success/80' },
|
|
297
297
|
// Outline
|
|
298
|
-
{ variant: 'outline', color: 'primary', class: 'border-
|
|
299
|
-
{ variant: 'outline', color: 'secondary', class: 'border-
|
|
300
|
-
{ variant: 'outline', color: 'danger', class: 'border-
|
|
301
|
-
{ variant: 'outline', color: 'warning', class: 'border-
|
|
302
|
-
{ variant: 'outline', color: 'success', class: 'border-
|
|
298
|
+
{ variant: 'outline', color: 'primary', class: 'border-primary text-primary hover:bg-primary/10' },
|
|
299
|
+
{ variant: 'outline', color: 'secondary', class: 'border-neutral text-neutral hover:bg-neutral/10' },
|
|
300
|
+
{ variant: 'outline', color: 'danger', class: 'border-error text-error hover:bg-error/10' },
|
|
301
|
+
{ variant: 'outline', color: 'warning', class: 'border-warning text-warning hover:bg-warning/10' },
|
|
302
|
+
{ variant: 'outline', color: 'success', class: 'border-success text-success hover:bg-success/10' },
|
|
303
303
|
// Text
|
|
304
|
-
{ variant: 'text', color: 'primary', class: 'text-
|
|
305
|
-
{ variant: 'text', color: 'secondary', class: 'text-
|
|
306
|
-
{ variant: 'text', color: 'danger', class: 'text-
|
|
307
|
-
{ variant: 'text', color: 'warning', class: 'text-
|
|
308
|
-
{ variant: 'text', color: 'success', class: 'text-
|
|
304
|
+
{ variant: 'text', color: 'primary', class: 'text-primary hover:bg-primary/10' },
|
|
305
|
+
{ variant: 'text', color: 'secondary', class: 'text-neutral hover:bg-neutral/10' },
|
|
306
|
+
{ variant: 'text', color: 'danger', class: 'text-error hover:bg-error/10' },
|
|
307
|
+
{ variant: 'text', color: 'warning', class: 'text-warning hover:bg-warning/10' },
|
|
308
|
+
{ variant: 'text', color: 'success', class: 'text-success hover:bg-success/10' },
|
|
309
309
|
],
|
|
310
310
|
defaultVariants: {
|
|
311
311
|
size: 'md',
|
|
@@ -553,7 +553,7 @@ function pickAdapter(type) {
|
|
|
553
553
|
}
|
|
554
554
|
|
|
555
555
|
const mnInputFieldVariants = tv({
|
|
556
|
-
base: 'bg-
|
|
556
|
+
base: 'bg-base-100 border-1 border-base-300 placeholder-base-content/50 text-base-content text-sm',
|
|
557
557
|
variants: {
|
|
558
558
|
shadow: {
|
|
559
559
|
true: 'shadow-lg',
|
|
@@ -606,6 +606,7 @@ class MnLanguageService {
|
|
|
606
606
|
_translations = {};
|
|
607
607
|
_locale$ = new BehaviorSubject('en');
|
|
608
608
|
_urlPattern = null;
|
|
609
|
+
_debug = false;
|
|
609
610
|
/** Observable of the current active locale. */
|
|
610
611
|
locale$ = this._locale$.asObservable();
|
|
611
612
|
constructor(http) {
|
|
@@ -615,11 +616,23 @@ class MnLanguageService {
|
|
|
615
616
|
get locale() {
|
|
616
617
|
return this._locale$.value;
|
|
617
618
|
}
|
|
619
|
+
/**
|
|
620
|
+
* Enable or disable debug logging.
|
|
621
|
+
*/
|
|
622
|
+
setDebug(enabled) {
|
|
623
|
+
this._debug = enabled;
|
|
624
|
+
if (enabled) {
|
|
625
|
+
console.log(`[MnLanguage] Debug mode enabled`);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
618
628
|
/**
|
|
619
629
|
* Configure the URL pattern used to fetch translation files.
|
|
620
630
|
* Use `{locale}` as placeholder, e.g. `"assets/i18n/{locale}.json"`.
|
|
621
631
|
*/
|
|
622
632
|
configure(urlPattern) {
|
|
633
|
+
if (this._debug) {
|
|
634
|
+
console.log(`[MnLanguage] Configured urlPattern: ${urlPattern}`);
|
|
635
|
+
}
|
|
623
636
|
this._urlPattern = urlPattern;
|
|
624
637
|
}
|
|
625
638
|
/**
|
|
@@ -634,9 +647,15 @@ class MnLanguageService {
|
|
|
634
647
|
return;
|
|
635
648
|
}
|
|
636
649
|
const url = this._urlPattern.replace('{locale}', locale);
|
|
650
|
+
if (this._debug) {
|
|
651
|
+
console.log(`[MnLanguage] Loading locale "${locale}" from ${url}`);
|
|
652
|
+
}
|
|
637
653
|
try {
|
|
638
654
|
const map = await firstValueFrom(this.http.get(url));
|
|
639
655
|
this._translations[locale] = map ?? {};
|
|
656
|
+
if (this._debug) {
|
|
657
|
+
console.log(`[MnLanguage] Loaded locale "${locale}"`, this._translations[locale]);
|
|
658
|
+
}
|
|
640
659
|
}
|
|
641
660
|
catch (err) {
|
|
642
661
|
console.warn(`[MnLanguage] Failed to load translations from ${url}`, err);
|
|
@@ -647,6 +666,9 @@ class MnLanguageService {
|
|
|
647
666
|
* Switch the active locale. Loads translations if not yet loaded.
|
|
648
667
|
*/
|
|
649
668
|
async setLocale(locale) {
|
|
669
|
+
if (this._debug) {
|
|
670
|
+
console.log(`[MnLanguage] Setting locale to "${locale}"`);
|
|
671
|
+
}
|
|
650
672
|
await this.loadLocale(locale);
|
|
651
673
|
this._locale$.next(locale);
|
|
652
674
|
}
|
|
@@ -667,8 +689,11 @@ class MnLanguageService {
|
|
|
667
689
|
*/
|
|
668
690
|
translate(key, params) {
|
|
669
691
|
const map = this._translations[this.locale] ?? {};
|
|
670
|
-
let value = map
|
|
692
|
+
let value = this.getValueFromMap(map, key);
|
|
671
693
|
if (value === undefined) {
|
|
694
|
+
if (this._debug) {
|
|
695
|
+
console.warn(`[MnLanguage] Missing translation for key: "${key}" in locale: "${this.locale}"`);
|
|
696
|
+
}
|
|
672
697
|
return key;
|
|
673
698
|
}
|
|
674
699
|
if (params) {
|
|
@@ -678,6 +703,21 @@ class MnLanguageService {
|
|
|
678
703
|
}
|
|
679
704
|
return value;
|
|
680
705
|
}
|
|
706
|
+
/**
|
|
707
|
+
* Helper to retrieve a value from a potentially nested translation map using a dot-notated key.
|
|
708
|
+
*/
|
|
709
|
+
getValueFromMap(map, key) {
|
|
710
|
+
if (map[key] !== undefined)
|
|
711
|
+
return map[key];
|
|
712
|
+
const parts = key.split('.');
|
|
713
|
+
let current = map;
|
|
714
|
+
for (const part of parts) {
|
|
715
|
+
if (current === null || typeof current !== 'object')
|
|
716
|
+
return undefined;
|
|
717
|
+
current = current[part];
|
|
718
|
+
}
|
|
719
|
+
return typeof current === 'string' ? current : undefined;
|
|
720
|
+
}
|
|
681
721
|
/**
|
|
682
722
|
* Shorthand alias for `translate`.
|
|
683
723
|
*/
|
|
@@ -739,6 +779,7 @@ class MnConfigService {
|
|
|
739
779
|
*/
|
|
740
780
|
async load(url, debugMode = false) {
|
|
741
781
|
this._debugMode = debugMode;
|
|
782
|
+
this.lang.setDebug(debugMode);
|
|
742
783
|
let text;
|
|
743
784
|
try {
|
|
744
785
|
text = await firstValueFrom(this.http.get(url, { responseType: 'text' }));
|
|
@@ -768,9 +809,12 @@ class MnConfigService {
|
|
|
768
809
|
const langCfg = cfg.language;
|
|
769
810
|
if (isPlainObject(langCfg) && typeof langCfg['urlPattern'] === 'string') {
|
|
770
811
|
const lc = langCfg;
|
|
812
|
+
if (this._debugMode) {
|
|
813
|
+
console.log(`[MnConfig] Applying language config from file`, lc);
|
|
814
|
+
}
|
|
771
815
|
this.lang.configure(lc.urlPattern);
|
|
772
816
|
const effectiveLocale = this.lang.resolveLocaleForDomain(lc.domainLocaleMap, lc.defaultLocale);
|
|
773
|
-
const localesToLoad = lc.preload ?? [effectiveLocale];
|
|
817
|
+
const localesToLoad = Array.from(new Set([...(lc.preload ?? []), effectiveLocale]));
|
|
774
818
|
await Promise.all(localesToLoad.map(l => this.lang.loadLocale(l)));
|
|
775
819
|
await this.lang.setLocale(effectiveLocale);
|
|
776
820
|
}
|
|
@@ -791,9 +835,12 @@ class MnConfigService {
|
|
|
791
835
|
const langCfg = config['language'];
|
|
792
836
|
if (isPlainObject(langCfg) && typeof langCfg['urlPattern'] === 'string') {
|
|
793
837
|
const lc = langCfg;
|
|
838
|
+
if (this._debugMode) {
|
|
839
|
+
console.log(`[MnConfig] Applying language config from object`, lc);
|
|
840
|
+
}
|
|
794
841
|
this.lang.configure(lc.urlPattern);
|
|
795
842
|
const effectiveLocale = this.lang.resolveLocaleForDomain(lc.domainLocaleMap, lc.defaultLocale);
|
|
796
|
-
const localesToLoad = lc.preload ?? [effectiveLocale];
|
|
843
|
+
const localesToLoad = Array.from(new Set([...(lc.preload ?? []), effectiveLocale]));
|
|
797
844
|
await Promise.all(localesToLoad.map(l => this.lang.loadLocale(l)));
|
|
798
845
|
await this.lang.setLocale(effectiveLocale);
|
|
799
846
|
}
|
|
@@ -1278,7 +1325,7 @@ function provideMnComponentConfig(token, componentName, initial) {
|
|
|
1278
1325
|
const cfg = resolveConfig();
|
|
1279
1326
|
// Re-resolve translatable values whenever the locale changes.
|
|
1280
1327
|
// skip(1) because the current locale was already used for the initial resolve.
|
|
1281
|
-
const sub = lang.locale$.
|
|
1328
|
+
const sub = lang.locale$.subscribe(() => {
|
|
1282
1329
|
const updated = resolveConfig();
|
|
1283
1330
|
// Mutate the existing object in place so all template bindings pick up the new values.
|
|
1284
1331
|
for (const key of Object.keys(updated)) {
|
|
@@ -1405,7 +1452,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImpor
|
|
|
1405
1452
|
}] } });
|
|
1406
1453
|
|
|
1407
1454
|
const mnTextareaVariants = tv({
|
|
1408
|
-
base: 'bg-
|
|
1455
|
+
base: 'bg-base-100 border-1 border-base-300 placeholder-base-content/50 text-base-content text-sm',
|
|
1409
1456
|
variants: {
|
|
1410
1457
|
shadow: {
|
|
1411
1458
|
true: 'shadow-lg',
|
|
@@ -1869,7 +1916,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImpor
|
|
|
1869
1916
|
}] } });
|
|
1870
1917
|
|
|
1871
1918
|
const mnDatetimeVariants = tv({
|
|
1872
|
-
base: 'bg-
|
|
1919
|
+
base: 'bg-base-100 border-1 border-base-300 placeholder-base-content/50 text-base-content text-sm',
|
|
1873
1920
|
variants: {
|
|
1874
1921
|
shadow: {
|
|
1875
1922
|
true: 'shadow-lg',
|
|
@@ -2045,7 +2092,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImpor
|
|
|
2045
2092
|
}] } });
|
|
2046
2093
|
|
|
2047
2094
|
const mnMultiSelectVariants = tv({
|
|
2048
|
-
base: 'bg-
|
|
2095
|
+
base: 'bg-base-100 border-1 border-base-300 text-base-content text-sm cursor-pointer',
|
|
2049
2096
|
variants: {
|
|
2050
2097
|
shadow: {
|
|
2051
2098
|
true: 'shadow-lg',
|
|
@@ -6578,6 +6625,9 @@ function provideMnLanguage(config) {
|
|
|
6578
6625
|
provide: APP_INITIALIZER,
|
|
6579
6626
|
multi: true,
|
|
6580
6627
|
useFactory: (svc) => async () => {
|
|
6628
|
+
if (config.debug) {
|
|
6629
|
+
svc.setDebug(true);
|
|
6630
|
+
}
|
|
6581
6631
|
svc.configure(config.urlPattern);
|
|
6582
6632
|
const effectiveLocale = svc.resolveLocaleForDomain(config.domainLocaleMap, config.defaultLocale);
|
|
6583
6633
|
const localesToLoad = config.preload ?? [effectiveLocale];
|