@ankhorage/studio 0.0.12 → 0.0.13
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.
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare const STUDIO_LOCALIZED_PROP_PAIRS: readonly [readonly ["i18nKey", "text"], readonly ["titleI18nKey", "title"], readonly ["descriptionI18nKey", "description"], readonly ["eyebrowI18nKey", "eyebrow"], readonly ["labelI18nKey", "label"], readonly ["helperTextI18nKey", "helperText"], readonly ["errorTextI18nKey", "errorText"], readonly ["metaI18nKey", "meta"], readonly ["childrenI18nKey", "children"]];
|
|
2
|
+
export type StudioLocalizedPropPair = (typeof STUDIO_LOCALIZED_PROP_PAIRS)[number];
|
|
3
|
+
export interface StudioRuntimeNodePropsResolverContext {
|
|
4
|
+
node: {
|
|
5
|
+
id: string;
|
|
6
|
+
type: string;
|
|
7
|
+
};
|
|
8
|
+
props: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
export type StudioRuntimeNodePropsResolver = (context: StudioRuntimeNodePropsResolverContext) => Record<string, unknown>;
|
|
11
|
+
export interface StudioRuntimeActionHandlerContext {
|
|
12
|
+
action: unknown;
|
|
13
|
+
context: StudioRuntimeNodePropsResolverContext;
|
|
14
|
+
}
|
|
15
|
+
export type StudioRuntimeActionHandlers = Record<string, (context: StudioRuntimeActionHandlerContext) => void>;
|
|
16
|
+
export declare function resolveLocalizedPropValue(args: {
|
|
17
|
+
props: Record<string, unknown>;
|
|
18
|
+
keyProp: string;
|
|
19
|
+
targetProp: string;
|
|
20
|
+
translate: (key: string) => string;
|
|
21
|
+
}): string | undefined;
|
|
22
|
+
export declare function createStudioLocalizationNodePropsResolver(translate: (key: string) => string): StudioRuntimeNodePropsResolver;
|
|
23
|
+
export declare function getSetLanguageLocale(action: unknown): string | undefined;
|
|
24
|
+
export declare function createStudioLocalizationActionHandlers(setActiveLocale: (locale: string) => void): StudioRuntimeActionHandlers;
|
|
25
|
+
//# sourceMappingURL=runtimeLocalization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtimeLocalization.d.ts","sourceRoot":"","sources":["../src/runtimeLocalization.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,2BAA2B,+WAU9B,CAAC;AAEX,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,2BAA2B,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnF,MAAM,WAAW,qCAAqC;IACpD,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACnC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,MAAM,MAAM,8BAA8B,GAAG,CAC3C,OAAO,EAAE,qCAAqC,KAC3C,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE7B,MAAM,WAAW,iCAAiC;IAChD,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,qCAAqC,CAAC;CAChD;AAED,MAAM,MAAM,2BAA2B,GAAG,MAAM,CAC9C,MAAM,EACN,CAAC,OAAO,EAAE,iCAAiC,KAAK,IAAI,CACrD,CAAC;AAUF,wBAAgB,yBAAyB,CAAC,IAAI,EAAE;IAC9C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;CACpC,GAAG,MAAM,GAAG,SAAS,CAkBrB;AAED,wBAAgB,yCAAyC,CACvD,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GACjC,8BAA8B,CAuBhC;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAiBxE;AAED,wBAAgB,sCAAsC,CACpD,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GACxC,2BAA2B,CAS7B"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export const STUDIO_LOCALIZED_PROP_PAIRS = [
|
|
2
|
+
['i18nKey', 'text'],
|
|
3
|
+
['titleI18nKey', 'title'],
|
|
4
|
+
['descriptionI18nKey', 'description'],
|
|
5
|
+
['eyebrowI18nKey', 'eyebrow'],
|
|
6
|
+
['labelI18nKey', 'label'],
|
|
7
|
+
['helperTextI18nKey', 'helperText'],
|
|
8
|
+
['errorTextI18nKey', 'errorText'],
|
|
9
|
+
['metaI18nKey', 'meta'],
|
|
10
|
+
['childrenI18nKey', 'children'],
|
|
11
|
+
];
|
|
12
|
+
function isNonEmptyString(value) {
|
|
13
|
+
return typeof value === 'string' && value.length > 0;
|
|
14
|
+
}
|
|
15
|
+
function hasOwnProp(props, key) {
|
|
16
|
+
return Object.prototype.hasOwnProperty.call(props, key);
|
|
17
|
+
}
|
|
18
|
+
export function resolveLocalizedPropValue(args) {
|
|
19
|
+
const { props, keyProp, targetProp, translate } = args;
|
|
20
|
+
const key = props[keyProp];
|
|
21
|
+
if (!isNonEmptyString(key)) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
const translated = translate(key);
|
|
25
|
+
if (isNonEmptyString(translated) && translated !== key) {
|
|
26
|
+
return translated;
|
|
27
|
+
}
|
|
28
|
+
if (hasOwnProp(props, targetProp)) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
return key;
|
|
32
|
+
}
|
|
33
|
+
export function createStudioLocalizationNodePropsResolver(translate) {
|
|
34
|
+
return ({ props }) => {
|
|
35
|
+
let resolvedProps;
|
|
36
|
+
for (const [keyProp, targetProp] of STUDIO_LOCALIZED_PROP_PAIRS) {
|
|
37
|
+
const localizedValue = resolveLocalizedPropValue({
|
|
38
|
+
props,
|
|
39
|
+
keyProp,
|
|
40
|
+
targetProp,
|
|
41
|
+
translate,
|
|
42
|
+
});
|
|
43
|
+
if (localizedValue === undefined) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const nextProps = resolvedProps ?? { ...props };
|
|
47
|
+
nextProps[targetProp] = localizedValue;
|
|
48
|
+
resolvedProps = nextProps;
|
|
49
|
+
}
|
|
50
|
+
return resolvedProps ?? props;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export function getSetLanguageLocale(action) {
|
|
54
|
+
if (typeof action !== 'object' || action === null || Array.isArray(action)) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
const record = action;
|
|
58
|
+
if (record.type !== 'setLanguage') {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
const { payload } = record;
|
|
62
|
+
if (typeof payload !== 'object' || payload === null || Array.isArray(payload)) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
const { locale } = payload;
|
|
66
|
+
return typeof locale === 'string' && locale.length > 0 ? locale : undefined;
|
|
67
|
+
}
|
|
68
|
+
export function createStudioLocalizationActionHandlers(setActiveLocale) {
|
|
69
|
+
return {
|
|
70
|
+
setLanguage: ({ action }) => {
|
|
71
|
+
const locale = getSetLanguageLocale(action);
|
|
72
|
+
if (locale !== undefined) {
|
|
73
|
+
setActiveLocale(locale);
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=runtimeLocalization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtimeLocalization.js","sourceRoot":"","sources":["../src/runtimeLocalization.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC,CAAC,SAAS,EAAE,MAAM,CAAC;IACnB,CAAC,cAAc,EAAE,OAAO,CAAC;IACzB,CAAC,oBAAoB,EAAE,aAAa,CAAC;IACrC,CAAC,gBAAgB,EAAE,SAAS,CAAC;IAC7B,CAAC,cAAc,EAA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C;YAC5C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACzB,eAAe,CAAC,MAAM,CAAC,CAAC;YAC1B,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ankhorage/studio",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"description": "Studio authoring package for Ankhorage apps",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/ankhorage/studio#readme",
|
|
@@ -59,6 +59,10 @@
|
|
|
59
59
|
"./routeUtils": {
|
|
60
60
|
"types": "./dist/routeUtils.d.ts",
|
|
61
61
|
"import": "./dist/routeUtils.js"
|
|
62
|
+
},
|
|
63
|
+
"./runtimeLocalization": {
|
|
64
|
+
"types": "./dist/runtimeLocalization.d.ts",
|
|
65
|
+
"import": "./dist/runtimeLocalization.js"
|
|
62
66
|
}
|
|
63
67
|
},
|
|
64
68
|
"scripts": {
|