@tstdl/base 0.85.7 → 0.85.9
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.
- package/package.json +1 -1
- package/signals/index.d.ts +1 -0
- package/signals/index.js +1 -0
- package/signals/switch-map.d.ts +2 -0
- package/signals/switch-map.js +28 -0
- package/text/dynamic-text.model.js +15 -28
package/package.json
CHANGED
package/signals/index.d.ts
CHANGED
package/signals/index.js
CHANGED
|
@@ -19,4 +19,5 @@ __reExport(signals_exports, require("./api.js"), module.exports);
|
|
|
19
19
|
__reExport(signals_exports, require("./computed-with-dependencies.js"), module.exports);
|
|
20
20
|
__reExport(signals_exports, require("./effect-with-dependencies.js"), module.exports);
|
|
21
21
|
__reExport(signals_exports, require("./pipe.js"), module.exports);
|
|
22
|
+
__reExport(signals_exports, require("./switch-map.js"), module.exports);
|
|
22
23
|
__reExport(signals_exports, require("./types.js"), module.exports);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var switch_map_exports = {};
|
|
20
|
+
__export(switch_map_exports, {
|
|
21
|
+
switchMap: () => switchMap
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(switch_map_exports);
|
|
24
|
+
var import_api = require("./api.js");
|
|
25
|
+
function switchMap(source) {
|
|
26
|
+
const outerSource = (0, import_api.computed)(() => source());
|
|
27
|
+
return (0, import_api.computed)(() => outerSource()());
|
|
28
|
+
}
|
|
@@ -28,51 +28,38 @@ __export(dynamic_text_model_exports, {
|
|
|
28
28
|
resolveNestedDynamicTexts$: () => resolveNestedDynamicTexts$
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(dynamic_text_model_exports);
|
|
31
|
+
var import_rxjs = require("rxjs");
|
|
31
32
|
var import_container = require("../container/index.js");
|
|
32
33
|
var import_api = require("../signals/api.js");
|
|
33
|
-
var
|
|
34
|
-
var import_to_signal = require("../signals/implementation/to-signal.js");
|
|
35
|
-
var import_type_guards = require("../utils/type-guards.js");
|
|
36
|
-
var import_rxjs = require("rxjs");
|
|
34
|
+
var import_switch_map = require("../signals/switch-map.js");
|
|
37
35
|
var import_localization_service = require("./localization.service.js");
|
|
38
36
|
const missingLocalizationKeyText = "[MISSING LOCALIZATION KEY]";
|
|
39
37
|
function resolveDynamicText(text, localizationService) {
|
|
40
|
-
|
|
38
|
+
const resolvedLocalizationService = localizationService ?? import_container.container.resolve(import_localization_service.LocalizationService);
|
|
39
|
+
const localizableText = (0, import_api.isSignal)(text) ? text : (0, import_rxjs.isObservable)(text) ? (0, import_api.toSignal)(text, { initialValue: missingLocalizationKeyText }) : (0, import_api.computed)(() => text);
|
|
40
|
+
return (0, import_switch_map.switchMap)(() => resolvedLocalizationService.localize(localizableText()));
|
|
41
41
|
}
|
|
42
42
|
function resolveDynamicText$(text, localizationService) {
|
|
43
|
-
|
|
44
|
-
if ((0, import_rxjs.isObservable)(text)) {
|
|
45
|
-
return text.pipe((0, import_rxjs.switchMap)((inner) => resolveDynamicText$(inner, localizationService)));
|
|
46
|
-
}
|
|
47
|
-
if ((0, import_api.isSignal)(text)) {
|
|
48
|
-
const text$ = (0, import_to_observable.toObservable)(text);
|
|
49
|
-
return resolveDynamicText$(text$, resolvedLocalizationService);
|
|
50
|
-
}
|
|
51
|
-
if ((0, import_type_guards.isString)(text)) {
|
|
52
|
-
return (0, import_rxjs.of)(text);
|
|
53
|
-
}
|
|
54
|
-
return resolvedLocalizationService.localize$(text);
|
|
43
|
+
return (0, import_api.toObservable)(resolveDynamicText(text, localizationService));
|
|
55
44
|
}
|
|
56
45
|
function resolveDynamicTexts(texts, localizationService) {
|
|
57
|
-
const
|
|
58
|
-
return (0,
|
|
46
|
+
const signals = texts.map((text) => resolveDynamicText(text, localizationService));
|
|
47
|
+
return (0, import_api.computed)(() => signals.map((s) => s()));
|
|
59
48
|
}
|
|
60
49
|
function resolveDynamicTexts$(texts, localizationService) {
|
|
61
|
-
|
|
62
|
-
const resolvedTextObservables = texts.map((text) => resolveDynamicText$(text, resolvedLocalizationService));
|
|
63
|
-
return (0, import_rxjs.combineLatest)(resolvedTextObservables);
|
|
50
|
+
return (0, import_api.toObservable)(resolveDynamicTexts(texts, localizationService));
|
|
64
51
|
}
|
|
65
52
|
function resolveNestedDynamicText(item, key, localizationService) {
|
|
66
|
-
|
|
53
|
+
const result = resolveDynamicText(item[key], localizationService);
|
|
54
|
+
return (0, import_api.computed)(() => ({ ...item, [key]: result() }));
|
|
67
55
|
}
|
|
68
56
|
function resolveNestedDynamicText$(item, key, localizationService) {
|
|
69
|
-
return
|
|
57
|
+
return (0, import_api.toObservable)(resolveNestedDynamicText(item, key, localizationService));
|
|
70
58
|
}
|
|
71
59
|
function resolveNestedDynamicTexts(items, key, localizationService) {
|
|
72
|
-
|
|
60
|
+
const itemSignals = items.map((item) => resolveNestedDynamicText(item, key, localizationService));
|
|
61
|
+
return (0, import_api.computed)(() => itemSignals.map((s) => s()));
|
|
73
62
|
}
|
|
74
63
|
function resolveNestedDynamicTexts$(items, key, localizationService) {
|
|
75
|
-
|
|
76
|
-
const resolvedTextObservables = items.map((item) => resolveNestedDynamicText$(item, key, resolvedLocalizationService));
|
|
77
|
-
return (0, import_rxjs.combineLatest)(resolvedTextObservables);
|
|
64
|
+
return (0, import_api.toObservable)(resolveNestedDynamicTexts(items, key, localizationService));
|
|
78
65
|
}
|