@pushwoosh/dumb-components 1.1.132 → 1.1.134
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/Calendar/CalendarDropdown/CalendarDropdown.js +15 -3
- package/Calendar/CalendarSuperForm/components/CalendarTimeAndTimezoneSection/CalendarTimeAndTimezoneSection.js +14 -4
- package/Calendar/polyglot/index.d.ts +2 -0
- package/Calendar/polyglot/index.js +10 -0
- package/Calendar/polyglot/messages_en.d.ts +3 -0
- package/Calendar/polyglot/messages_en.js +11 -0
- package/Calendar/polyglot/messages_ru.d.ts +3 -0
- package/Calendar/polyglot/messages_ru.js +11 -0
- package/Calendar/polyglot/types.d.ts +14 -0
- package/Calendar/polyglot/types.js +1 -0
- package/FrequencyCapping/FrequencyCappingEdit.js +7 -2
- package/FrequencyCapping/FrequencyCappingInApps.js +7 -2
- package/FrequencyCapping/FrequencyCappingReadonly.js +5 -2
- package/FrequencyCapping/components/Description/index.js +3 -1
- package/FrequencyCapping/components/Settings/EditCappingSettings.js +10 -3
- package/FrequencyCapping/components/Settings/EditInAppCappingSettings.js +25 -8
- package/FrequencyCapping/helpers/getCappingChipText.d.ts +2 -1
- package/FrequencyCapping/helpers/getCappingChipText.js +13 -15
- package/FrequencyCapping/helpers/getDescriptionMessages.d.ts +2 -1
- package/FrequencyCapping/helpers/getDescriptionMessages.js +42 -22
- package/FrequencyCapping/helpers/getGlobalCappingLinkText.d.ts +2 -0
- package/FrequencyCapping/helpers/getGlobalCappingLinkText.js +7 -0
- package/FrequencyCapping/helpers/getReadonlyCappingHelpers.d.ts +2 -1
- package/FrequencyCapping/helpers/getReadonlyCappingHelpers.js +27 -15
- package/FrequencyCapping/polyglot/index.d.ts +4 -0
- package/FrequencyCapping/polyglot/index.js +10 -0
- package/FrequencyCapping/polyglot/messages_en.d.ts +3 -0
- package/FrequencyCapping/polyglot/messages_en.js +33 -0
- package/FrequencyCapping/polyglot/messages_ru.d.ts +3 -0
- package/FrequencyCapping/polyglot/messages_ru.js +33 -0
- package/FrequencyCapping/polyglot/types.d.ts +46 -0
- package/FrequencyCapping/polyglot/types.js +1 -0
- package/Select/styles.js +2 -2
- package/SendRate/SendRateEdit.js +7 -2
- package/SendRate/SendRateReadonly.js +5 -2
- package/SendRate/components/Condition/index.js +8 -1
- package/SendRate/components/Description/index.js +20 -6
- package/SendRate/components/Settings/index.js +7 -2
- package/SendRate/helpers/getGlobalSendRateLinkText.d.ts +2 -0
- package/SendRate/helpers/getGlobalSendRateLinkText.js +7 -0
- package/SendRate/helpers/getReadonlySendRateHelpers.d.ts +2 -1
- package/SendRate/helpers/getReadonlySendRateHelpers.js +20 -11
- package/SendRate/polyglot/index.d.ts +4 -0
- package/SendRate/polyglot/index.js +10 -0
- package/SendRate/polyglot/messages_en.d.ts +3 -0
- package/SendRate/polyglot/messages_en.js +20 -0
- package/SendRate/polyglot/messages_ru.d.ts +3 -0
- package/SendRate/polyglot/messages_ru.js +20 -0
- package/SendRate/polyglot/types.d.ts +23 -0
- package/SendRate/polyglot/types.js +1 -0
- package/package.json +1 -1
- package/polyglot/index.d.ts +1 -1
- package/polyglot/index.js +1 -1
- package/polyglot/react.d.ts +12 -2
- package/polyglot/react.js +80 -45
package/polyglot/react.d.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import { type FC, type PropsWithChildren } from 'react';
|
|
2
|
-
import { type LangMessages } from './types';
|
|
2
|
+
import { type LangMessages, type LangProps } from './types';
|
|
3
|
+
type LanguagesMap = Record<string, LangMessages<any>>;
|
|
3
4
|
type LangProviderProps = {
|
|
4
5
|
timezone: string;
|
|
5
6
|
language: string;
|
|
6
|
-
languages:
|
|
7
|
+
languages: LanguagesMap;
|
|
7
8
|
};
|
|
8
9
|
export declare const LangProvider: FC<PropsWithChildren<LangProviderProps>>;
|
|
9
10
|
export declare const LangBase: FC;
|
|
10
11
|
export declare const useLangBase: () => (allProps: any) => string;
|
|
12
|
+
type LangLibProps = {
|
|
13
|
+
$languages: LanguagesMap;
|
|
14
|
+
} & Record<string, any>;
|
|
15
|
+
export declare const LangLib: FC<LangLibProps>;
|
|
16
|
+
export declare const useLangLib: (languages: LanguagesMap) => (allProps: any) => string;
|
|
17
|
+
export declare const createLang: <M>(languages: Record<string, LangMessages<M>>) => {
|
|
18
|
+
Lang: FC<LangProps<M>>;
|
|
19
|
+
useLang: () => (props: LangProps<M>) => string;
|
|
20
|
+
};
|
|
11
21
|
export {};
|
package/polyglot/react.js
CHANGED
|
@@ -1,7 +1,62 @@
|
|
|
1
1
|
import React, { createContext, useContext, useMemo } from 'react';
|
|
2
2
|
import { stringToAst } from './liquid/parser';
|
|
3
3
|
import { renderToReact, renderToString } from './liquid/render';
|
|
4
|
-
const
|
|
4
|
+
const createLangPack = (language, timezone) => {
|
|
5
|
+
const astCache = {};
|
|
6
|
+
const register = languages => {
|
|
7
|
+
const langMessages = languages[language] ?? languages.en;
|
|
8
|
+
if (!langMessages) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
Object.entries(langMessages).forEach(([key, message]) => {
|
|
12
|
+
if (key in astCache) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
astCache[key] = stringToAst(message);
|
|
17
|
+
} catch (e) {
|
|
18
|
+
console.error(key, message, e);
|
|
19
|
+
astCache[key] = [];
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
const getAst = message => {
|
|
24
|
+
const ast = astCache[message];
|
|
25
|
+
if (!ast) {
|
|
26
|
+
console.error('no message', message);
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
return ast;
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
language,
|
|
33
|
+
timezone,
|
|
34
|
+
register,
|
|
35
|
+
lang: allProps => {
|
|
36
|
+
const {
|
|
37
|
+
message,
|
|
38
|
+
...values
|
|
39
|
+
} = allProps;
|
|
40
|
+
return renderToString(getAst(message), {
|
|
41
|
+
values,
|
|
42
|
+
language,
|
|
43
|
+
timezone
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
langReact: allProps => {
|
|
47
|
+
const {
|
|
48
|
+
message,
|
|
49
|
+
...values
|
|
50
|
+
} = allProps;
|
|
51
|
+
return renderToReact(getAst(message), {
|
|
52
|
+
values,
|
|
53
|
+
language,
|
|
54
|
+
timezone
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
const LangContext = createContext(createLangPack('en', 'UTC'));
|
|
5
60
|
export const LangProvider = ({
|
|
6
61
|
timezone,
|
|
7
62
|
language,
|
|
@@ -9,49 +64,9 @@ export const LangProvider = ({
|
|
|
9
64
|
children
|
|
10
65
|
}) => {
|
|
11
66
|
const langFnPack = useMemo(() => {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return [k, stringToAst(v)];
|
|
16
|
-
} catch (e) {
|
|
17
|
-
console.error(k, v, e);
|
|
18
|
-
return [k, []];
|
|
19
|
-
}
|
|
20
|
-
}));
|
|
21
|
-
const getAst = message => {
|
|
22
|
-
const ast = asts[message];
|
|
23
|
-
if (!ast) {
|
|
24
|
-
console.error('no message', message);
|
|
25
|
-
return [];
|
|
26
|
-
}
|
|
27
|
-
return ast;
|
|
28
|
-
};
|
|
29
|
-
return {
|
|
30
|
-
lang: allProps => {
|
|
31
|
-
const {
|
|
32
|
-
message,
|
|
33
|
-
...values
|
|
34
|
-
} = allProps;
|
|
35
|
-
const ast = getAst(message);
|
|
36
|
-
return renderToString(ast, {
|
|
37
|
-
values,
|
|
38
|
-
language,
|
|
39
|
-
timezone
|
|
40
|
-
});
|
|
41
|
-
},
|
|
42
|
-
langReact: allProps => {
|
|
43
|
-
const {
|
|
44
|
-
message,
|
|
45
|
-
...values
|
|
46
|
-
} = allProps;
|
|
47
|
-
const ast = getAst(message);
|
|
48
|
-
return renderToReact(ast, {
|
|
49
|
-
values,
|
|
50
|
-
language,
|
|
51
|
-
timezone
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
};
|
|
67
|
+
const pack = createLangPack(language, timezone);
|
|
68
|
+
pack.register(languages);
|
|
69
|
+
return pack;
|
|
55
70
|
}, [languages, language, timezone]);
|
|
56
71
|
return React.createElement(LangContext.Provider, {
|
|
57
72
|
value: langFnPack
|
|
@@ -60,4 +75,24 @@ export const LangProvider = ({
|
|
|
60
75
|
export const LangBase = props => {
|
|
61
76
|
return useContext(LangContext).langReact(props);
|
|
62
77
|
};
|
|
63
|
-
export const useLangBase = () => useContext(LangContext).lang;
|
|
78
|
+
export const useLangBase = () => useContext(LangContext).lang;
|
|
79
|
+
export const LangLib = ({
|
|
80
|
+
$languages,
|
|
81
|
+
...props
|
|
82
|
+
}) => {
|
|
83
|
+
const ctx = useContext(LangContext);
|
|
84
|
+
useMemo(() => ctx.register($languages), [ctx, $languages]);
|
|
85
|
+
return ctx.langReact(props);
|
|
86
|
+
};
|
|
87
|
+
export const useLangLib = languages => {
|
|
88
|
+
const ctx = useContext(LangContext);
|
|
89
|
+
useMemo(() => ctx.register(languages), [ctx, languages]);
|
|
90
|
+
return ctx.lang;
|
|
91
|
+
};
|
|
92
|
+
export const createLang = languages => ({
|
|
93
|
+
Lang: props => React.createElement(LangLib, {
|
|
94
|
+
"$languages": languages,
|
|
95
|
+
...props
|
|
96
|
+
}),
|
|
97
|
+
useLang: () => useLangLib(languages)
|
|
98
|
+
});
|