keycloakify 4.10.0 → 5.0.0
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/CHANGELOG.md +4 -0
- package/lib/components/Error.js +2 -2
- package/lib/components/Error.js.map +1 -1
- package/lib/components/Info.js +2 -2
- package/lib/components/Info.js.map +1 -1
- package/lib/components/Login.js +2 -2
- package/lib/components/Login.js.map +1 -1
- package/lib/components/LoginIdpLinkConfirm.js +2 -2
- package/lib/components/LoginIdpLinkConfirm.js.map +1 -1
- package/lib/components/LoginIdpLinkEmail.js +2 -2
- package/lib/components/LoginIdpLinkEmail.js.map +1 -1
- package/lib/components/LoginOtp.js +2 -2
- package/lib/components/LoginOtp.js.map +1 -1
- package/lib/components/LoginPageExpired.js +2 -2
- package/lib/components/LoginPageExpired.js.map +1 -1
- package/lib/components/LoginResetPassword.js +2 -2
- package/lib/components/LoginResetPassword.js.map +1 -1
- package/lib/components/LoginUpdatePassword.js +2 -2
- package/lib/components/LoginUpdatePassword.js.map +1 -1
- package/lib/components/LoginUpdateProfile.js +2 -2
- package/lib/components/LoginUpdateProfile.js.map +1 -1
- package/lib/components/LoginVerifyEmail.js +2 -2
- package/lib/components/LoginVerifyEmail.js.map +1 -1
- package/lib/components/Register.js +2 -2
- package/lib/components/Register.js.map +1 -1
- package/lib/components/RegisterUserProfile.js +3 -3
- package/lib/components/RegisterUserProfile.js.map +1 -1
- package/lib/components/Template.js +10 -28
- package/lib/components/Template.js.map +1 -1
- package/lib/components/Terms.d.ts +8 -0
- package/lib/components/Terms.js +33 -3
- package/lib/components/Terms.js.map +1 -1
- package/lib/getKcContext/KcContextBase.d.ts +4 -4
- package/lib/getKcContext/KcContextBase.js.map +1 -1
- package/lib/getKcContext/kcContextMocks/kcContextMocks.js +21 -8
- package/lib/getKcContext/kcContextMocks/kcContextMocks.js.map +1 -1
- package/lib/i18n/{kcMessages/login.d.ts → index.d.ts} +62 -4
- package/lib/i18n/{useKcMessage.js → index.js} +47 -33
- package/lib/i18n/index.js.map +1 -0
- package/lib/index.d.ts +2 -11
- package/lib/index.js +4 -11
- package/lib/index.js.map +1 -1
- package/lib/useFormValidationSlice.d.ts +4 -12
- package/lib/useFormValidationSlice.js +4 -3
- package/lib/useFormValidationSlice.js.map +1 -1
- package/package.json +7 -17
- package/src/lib/components/Error.tsx +2 -2
- package/src/lib/components/Info.tsx +2 -2
- package/src/lib/components/Login.tsx +2 -2
- package/src/lib/components/LoginIdpLinkConfirm.tsx +2 -2
- package/src/lib/components/LoginIdpLinkEmail.tsx +2 -2
- package/src/lib/components/LoginOtp.tsx +2 -2
- package/src/lib/components/LoginPageExpired.tsx +2 -2
- package/src/lib/components/LoginResetPassword.tsx +2 -2
- package/src/lib/components/LoginUpdatePassword.tsx +2 -2
- package/src/lib/components/LoginUpdateProfile.tsx +2 -2
- package/src/lib/components/LoginVerifyEmail.tsx +2 -2
- package/src/lib/components/Register.tsx +2 -2
- package/src/lib/components/RegisterUserProfile.tsx +3 -3
- package/src/lib/components/Template.tsx +11 -31
- package/src/lib/components/Terms.tsx +24 -3
- package/src/lib/getKcContext/KcContextBase.ts +4 -8
- package/src/lib/getKcContext/kcContextMocks/kcContextMocks.ts +21 -9
- package/src/lib/i18n/index.tsx +180 -0
- package/src/lib/index.ts +3 -11
- package/src/lib/useFormValidationSlice.tsx +10 -15
- package/lib/i18n/KcLanguageTag.d.ts +0 -35
- package/lib/i18n/KcLanguageTag.js +0 -57
- package/lib/i18n/KcLanguageTag.js.map +0 -1
- package/lib/i18n/kcMessages/login.js +0 -38
- package/lib/i18n/kcMessages/login.js.map +0 -1
- package/lib/i18n/useKcLanguageTag.d.ts +0 -4
- package/lib/i18n/useKcLanguageTag.js +0 -22
- package/lib/i18n/useKcLanguageTag.js.map +0 -1
- package/lib/i18n/useKcMessage.d.ts +0 -23
- package/lib/i18n/useKcMessage.js.map +0 -1
- package/src/lib/i18n/KcLanguageTag.ts +0 -63
- package/src/lib/i18n/kcMessages/login.ts +0 -50
- package/src/lib/i18n/useKcLanguageTag.ts +0 -28
- package/src/lib/i18n/useKcMessage.tsx +0 -115
@@ -1,115 +0,0 @@
|
|
1
|
-
import "minimal-polyfills/Object.fromEntries";
|
2
|
-
import { useReducer } from "react";
|
3
|
-
import { useKcLanguageTag } from "./useKcLanguageTag";
|
4
|
-
import { kcMessages, evtTermsUpdated } from "./kcMessages/login";
|
5
|
-
import { useEvt } from "evt/hooks";
|
6
|
-
//NOTE for later: https://github.com/remarkjs/react-markdown/blob/236182ecf30bd89c1e5a7652acaf8d0bf81e6170/src/renderers.js#L7-L35
|
7
|
-
import ReactMarkdown from "react-markdown";
|
8
|
-
import { useGuaranteedMemo } from "powerhooks/useGuaranteedMemo";
|
9
|
-
|
10
|
-
export { kcMessages };
|
11
|
-
|
12
|
-
export type MessageKey = keyof typeof kcMessages["en"];
|
13
|
-
|
14
|
-
function resolveMsg<Key extends string, DoRenderMarkdown extends boolean>(props: {
|
15
|
-
key: Key;
|
16
|
-
args: (string | undefined)[];
|
17
|
-
kcLanguageTag: string;
|
18
|
-
doRenderMarkdown: DoRenderMarkdown;
|
19
|
-
}): Key extends MessageKey ? (DoRenderMarkdown extends true ? JSX.Element : string) : undefined {
|
20
|
-
const { key, args, kcLanguageTag, doRenderMarkdown } = props;
|
21
|
-
|
22
|
-
let str = kcMessages[kcLanguageTag as any as "en"][key as MessageKey] ?? kcMessages["en"][key as MessageKey];
|
23
|
-
|
24
|
-
if (str === undefined) {
|
25
|
-
return undefined as any;
|
26
|
-
}
|
27
|
-
|
28
|
-
str = (() => {
|
29
|
-
const startIndex = str
|
30
|
-
.match(/{[0-9]+}/g)
|
31
|
-
?.map(g => g.match(/{([0-9]+)}/)![1])
|
32
|
-
.map(indexStr => parseInt(indexStr))
|
33
|
-
.sort((a, b) => a - b)[0];
|
34
|
-
|
35
|
-
if (startIndex === undefined) {
|
36
|
-
return str;
|
37
|
-
}
|
38
|
-
|
39
|
-
args.forEach((arg, i) => {
|
40
|
-
if (arg === undefined) {
|
41
|
-
return;
|
42
|
-
}
|
43
|
-
|
44
|
-
str = str.replace(new RegExp(`\\{${i + startIndex}\\}`, "g"), arg);
|
45
|
-
});
|
46
|
-
|
47
|
-
return str;
|
48
|
-
})();
|
49
|
-
|
50
|
-
return (
|
51
|
-
doRenderMarkdown ? (
|
52
|
-
<ReactMarkdown allowDangerousHtml renderers={key === "termsText" ? undefined : { "paragraph": "span" }}>
|
53
|
-
{str}
|
54
|
-
</ReactMarkdown>
|
55
|
-
) : (
|
56
|
-
str
|
57
|
-
)
|
58
|
-
) as any;
|
59
|
-
}
|
60
|
-
|
61
|
-
function resolveMsgAdvanced<Key extends string, DoRenderMarkdown extends boolean>(props: {
|
62
|
-
key: Key;
|
63
|
-
args: (string | undefined)[];
|
64
|
-
kcLanguageTag: string;
|
65
|
-
doRenderMarkdown: DoRenderMarkdown;
|
66
|
-
}): DoRenderMarkdown extends true ? JSX.Element : string {
|
67
|
-
const { key, args, kcLanguageTag, doRenderMarkdown } = props;
|
68
|
-
|
69
|
-
const match = key.match(/^\$\{([^{]+)\}$/);
|
70
|
-
|
71
|
-
const keyUnwrappedFromCurlyBraces = match === null ? key : match[1];
|
72
|
-
|
73
|
-
const out = resolveMsg({
|
74
|
-
"key": keyUnwrappedFromCurlyBraces,
|
75
|
-
args,
|
76
|
-
kcLanguageTag,
|
77
|
-
doRenderMarkdown,
|
78
|
-
});
|
79
|
-
|
80
|
-
return (out !== undefined ? out : doRenderMarkdown ? <span>{keyUnwrappedFromCurlyBraces}</span> : keyUnwrappedFromCurlyBraces) as any;
|
81
|
-
}
|
82
|
-
|
83
|
-
/**
|
84
|
-
* When the language is switched the page is reloaded, this may appear
|
85
|
-
* as a bug as you might notice that the language successfully switch before
|
86
|
-
* reload.
|
87
|
-
* However we need to tell Keycloak that the user have changed the language
|
88
|
-
* during login so we can retrieve the "local" field of the JWT encoded accessToken.
|
89
|
-
* https://user-images.githubusercontent.com/6702424/138096682-351bb61f-f24e-4caf-91b7-cca8cfa2cb58.mov
|
90
|
-
*
|
91
|
-
* advancedMsg("${access-denied}") === advancedMsg("access-denied") === msg("access-denied")
|
92
|
-
* advancedMsg("${not-a-message-key}") === advancedMsg(not-a-message-key") === "not-a-message-key"
|
93
|
-
*
|
94
|
-
*/
|
95
|
-
export function useKcMessage() {
|
96
|
-
const { kcLanguageTag } = useKcLanguageTag();
|
97
|
-
|
98
|
-
const [trigger, forceUpdate] = useReducer((counter: number) => counter + 1, 0);
|
99
|
-
|
100
|
-
useEvt(ctx => evtTermsUpdated.attach(ctx, forceUpdate), []);
|
101
|
-
|
102
|
-
return useGuaranteedMemo(
|
103
|
-
() => ({
|
104
|
-
"msgStr": (key: MessageKey, ...args: (string | undefined)[]): string =>
|
105
|
-
resolveMsg({ key, args, kcLanguageTag, "doRenderMarkdown": false }),
|
106
|
-
"msg": (key: MessageKey, ...args: (string | undefined)[]): JSX.Element =>
|
107
|
-
resolveMsg({ key, args, kcLanguageTag, "doRenderMarkdown": true }),
|
108
|
-
"advancedMsg": <Key extends string>(key: Key, ...args: (string | undefined)[]): JSX.Element =>
|
109
|
-
resolveMsgAdvanced({ key, args, kcLanguageTag, "doRenderMarkdown": true }),
|
110
|
-
"advancedMsgStr": <Key extends string>(key: Key, ...args: (string | undefined)[]): string =>
|
111
|
-
resolveMsgAdvanced({ key, args, kcLanguageTag, "doRenderMarkdown": false }),
|
112
|
-
}),
|
113
|
-
[kcLanguageTag, trigger],
|
114
|
-
);
|
115
|
-
}
|