keycloakify 10.0.0-rc.76 → 10.0.0-rc.78
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/account/i18n/i18n.d.ts +4 -4
- package/account/i18n/i18n.js +12 -34
- package/account/i18n/i18n.js.map +1 -1
- package/account/i18n/index.d.ts +1 -1
- package/account/i18n/index.js +1 -1
- package/account/i18n/index.js.map +1 -1
- package/account/i18n/useI18n.d.ts +13 -0
- package/account/i18n/useI18n.js +26 -0
- package/account/i18n/useI18n.js.map +1 -0
- package/bin/440.index.js +15 -19
- package/bin/453.index.js +3 -2
- package/bin/751.index.js +0 -2
- package/bin/shared/constants.d.ts +0 -1
- package/bin/shared/constants.js +0 -1
- package/bin/shared/constants.js.map +1 -1
- package/login/KcContext/KcContext.d.ts +5 -1
- package/login/KcContext/KcContext.js +0 -1
- package/login/KcContext/KcContext.js.map +1 -1
- package/login/KcContext/kcContextMocks.js +4 -1
- package/login/KcContext/kcContextMocks.js.map +1 -1
- package/login/i18n/i18n.d.ts +7 -4
- package/login/i18n/i18n.js +23 -38
- package/login/i18n/i18n.js.map +1 -1
- package/login/i18n/index.d.ts +1 -1
- package/login/i18n/index.js +1 -1
- package/login/i18n/index.js.map +1 -1
- package/login/i18n/useI18n.d.ts +13 -0
- package/login/i18n/useI18n.js +26 -0
- package/login/i18n/useI18n.js.map +1 -0
- package/login/lib/useDownloadTerms.d.ts +5 -4
- package/login/lib/useDownloadTerms.js +26 -5
- package/login/lib/useDownloadTerms.js.map +1 -1
- package/login/pages/Register.js +7 -6
- package/login/pages/Register.js.map +1 -1
- package/login/pages/Terms.d.ts +1 -1
- package/login/pages/Terms.js +6 -4
- package/login/pages/Terms.js.map +1 -1
- package/package.json +15 -7
- package/src/account/i18n/i18n.tsx +19 -53
- package/src/account/i18n/index.ts +1 -1
- package/src/account/i18n/useI18n.ts +44 -0
- package/src/bin/eject-page.ts +4 -5
- package/src/bin/keycloakify/generateFtl/generateFtl.ts +1 -6
- package/src/bin/keycloakify/generateFtl/kcContextDeclarationTemplate.ftl +8 -1
- package/src/bin/keycloakify/generateResources/generateMessageProperties.ts +23 -17
- package/src/bin/shared/constants.ts +0 -2
- package/src/login/KcContext/KcContext.ts +6 -14
- package/src/login/KcContext/kcContextMocks.ts +4 -1
- package/src/login/i18n/i18n.tsx +37 -58
- package/src/login/i18n/index.ts +1 -1
- package/src/login/i18n/useI18n.ts +44 -0
- package/src/login/lib/useDownloadTerms.tsx +88 -0
- package/src/login/pages/Register.tsx +12 -12
- package/src/login/pages/Terms.tsx +12 -11
- package/src/tools/react-markdown.ts +3 -0
- package/tools/react-markdown.d.ts +3 -0
- package/tools/react-markdown.js +4 -0
- package/tools/react-markdown.js.map +1 -0
- package/vite-plugin/index.js +0 -2
- package/src/login/lib/useDownloadTerms.ts +0 -57
- package/src/tools/Markdown.ts +0 -3
- package/tools/Markdown.d.ts +0 -2
- package/tools/Markdown.js +0 -3
- package/tools/Markdown.js.map +0 -1
package/src/login/i18n/i18n.tsx
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
import "keycloakify/tools/Object.fromEntries";
|
2
|
-
import { useEffect, useState } from "react";
|
3
2
|
import { assert } from "tsafe/assert";
|
4
3
|
import messages_fallbackLanguage from "./baseMessages/en";
|
5
4
|
import { getMessages } from "./baseMessages";
|
6
5
|
import type { KcContext } from "../KcContext";
|
7
|
-
import { Reflect } from "tsafe/Reflect";
|
8
6
|
|
9
7
|
export const fallbackLanguageTag = "en";
|
10
8
|
|
@@ -13,7 +11,10 @@ export type KcContextLike = {
|
|
13
11
|
currentLanguageTag: string;
|
14
12
|
supported: { languageTag: string; url: string; label: string }[];
|
15
13
|
};
|
16
|
-
|
14
|
+
"x-keycloakify": {
|
15
|
+
realmMessageBundleUserProfile: Record<string, string> | undefined;
|
16
|
+
realmMessageBundleTermsText: string | undefined;
|
17
|
+
};
|
17
18
|
};
|
18
19
|
|
19
20
|
assert<KcContext extends KcContextLike ? true : false>();
|
@@ -89,7 +90,9 @@ export type GenericI18n<MessageKey extends string> = {
|
|
89
90
|
isFetchingTranslations: boolean;
|
90
91
|
};
|
91
92
|
|
92
|
-
function createGetI18n<ExtraMessageKey extends string = never>(
|
93
|
+
export function createGetI18n<ExtraMessageKey extends string = never>(messageBundle: {
|
94
|
+
[languageTag: string]: { [key in ExtraMessageKey]: string };
|
95
|
+
}) {
|
93
96
|
type I18n = GenericI18n<MessageKey | ExtraMessageKey>;
|
94
97
|
|
95
98
|
type Result = { i18n: I18n; prI18n_currentLanguage: Promise<I18n> | undefined };
|
@@ -127,9 +130,10 @@ function createGetI18n<ExtraMessageKey extends string = never>(extraMessages: {
|
|
127
130
|
|
128
131
|
const { createI18nTranslationFunctions } = createI18nTranslationFunctionsFactory<MessageKey, ExtraMessageKey>({
|
129
132
|
messages_fallbackLanguage,
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
+
messageBundle_fallbackLanguage: messageBundle[fallbackLanguageTag],
|
134
|
+
messageBundle_currentLanguage: messageBundle[partialI18n.currentLanguageTag],
|
135
|
+
realmMessageBundleUserProfile: kcContext["x-keycloakify"].realmMessageBundleUserProfile,
|
136
|
+
realmMessageBundleTermsText: kcContext["x-keycloakify"].realmMessageBundleTermsText
|
133
137
|
});
|
134
138
|
|
135
139
|
const isCurrentLanguageFallbackLanguage = partialI18n.currentLanguageTag === fallbackLanguageTag;
|
@@ -137,17 +141,19 @@ function createGetI18n<ExtraMessageKey extends string = never>(extraMessages: {
|
|
137
141
|
const result: Result = {
|
138
142
|
i18n: {
|
139
143
|
...partialI18n,
|
140
|
-
...createI18nTranslationFunctions({
|
144
|
+
...createI18nTranslationFunctions({
|
145
|
+
messages_currentLanguage: isCurrentLanguageFallbackLanguage ? messages_fallbackLanguage : undefined
|
146
|
+
}),
|
141
147
|
isFetchingTranslations: !isCurrentLanguageFallbackLanguage
|
142
148
|
},
|
143
149
|
prI18n_currentLanguage: isCurrentLanguageFallbackLanguage
|
144
150
|
? undefined
|
145
151
|
: (async () => {
|
146
|
-
const
|
152
|
+
const messages_currentLanguage = await getMessages(partialI18n.currentLanguageTag);
|
147
153
|
|
148
154
|
const i18n_currentLanguage: I18n = {
|
149
155
|
...partialI18n,
|
150
|
-
...createI18nTranslationFunctions({
|
156
|
+
...createI18nTranslationFunctions({ messages_currentLanguage }),
|
151
157
|
isFetchingTranslations: false
|
152
158
|
};
|
153
159
|
|
@@ -170,67 +176,40 @@ function createGetI18n<ExtraMessageKey extends string = never>(extraMessages: {
|
|
170
176
|
return { getI18n };
|
171
177
|
}
|
172
178
|
|
173
|
-
export function createUseI18n<ExtraMessageKey extends string = never>(extraMessages: {
|
174
|
-
[languageTag: string]: { [key in ExtraMessageKey]: string };
|
175
|
-
}) {
|
176
|
-
type I18n = GenericI18n<MessageKey | ExtraMessageKey>;
|
177
|
-
|
178
|
-
const { getI18n } = createGetI18n(extraMessages);
|
179
|
-
|
180
|
-
function useI18n(params: { kcContext: KcContextLike }): { i18n: I18n } {
|
181
|
-
const { kcContext } = params;
|
182
|
-
|
183
|
-
const { i18n, prI18n_currentLanguage } = getI18n({ kcContext });
|
184
|
-
|
185
|
-
const [i18n_toReturn, setI18n_toReturn] = useState<I18n>(i18n);
|
186
|
-
|
187
|
-
useEffect(() => {
|
188
|
-
let isActive = true;
|
189
|
-
|
190
|
-
prI18n_currentLanguage?.then(i18n => {
|
191
|
-
if (!isActive) {
|
192
|
-
return;
|
193
|
-
}
|
194
|
-
|
195
|
-
setI18n_toReturn(i18n);
|
196
|
-
});
|
197
|
-
|
198
|
-
return () => {
|
199
|
-
isActive = false;
|
200
|
-
};
|
201
|
-
}, []);
|
202
|
-
|
203
|
-
return { i18n: i18n_toReturn };
|
204
|
-
}
|
205
|
-
|
206
|
-
return { useI18n, ofTypeI18n: Reflect<I18n>() };
|
207
|
-
}
|
208
|
-
|
209
179
|
function createI18nTranslationFunctionsFactory<MessageKey extends string, ExtraMessageKey extends string>(params: {
|
210
180
|
messages_fallbackLanguage: Record<MessageKey, string>;
|
211
|
-
|
212
|
-
|
213
|
-
|
181
|
+
messageBundle_fallbackLanguage: Record<ExtraMessageKey, string> | undefined;
|
182
|
+
messageBundle_currentLanguage: Partial<Record<ExtraMessageKey, string>> | undefined;
|
183
|
+
realmMessageBundleUserProfile: Record<string, string> | undefined;
|
184
|
+
realmMessageBundleTermsText: string | undefined;
|
214
185
|
}) {
|
215
|
-
const {
|
186
|
+
const { messageBundle_currentLanguage, realmMessageBundleUserProfile, realmMessageBundleTermsText } = params;
|
216
187
|
|
217
188
|
const messages_fallbackLanguage = {
|
218
189
|
...params.messages_fallbackLanguage,
|
219
|
-
...params.
|
190
|
+
...params.messageBundle_fallbackLanguage
|
220
191
|
};
|
221
192
|
|
222
193
|
function createI18nTranslationFunctions(params: {
|
223
|
-
|
194
|
+
messages_currentLanguage: Partial<Record<MessageKey, string>> | undefined;
|
224
195
|
}): Pick<GenericI18n<MessageKey | ExtraMessageKey>, "msg" | "msgStr" | "advancedMsg" | "advancedMsgStr"> {
|
225
|
-
const
|
226
|
-
...params.
|
227
|
-
...
|
196
|
+
const messages_currentLanguage = {
|
197
|
+
...params.messages_currentLanguage,
|
198
|
+
...messageBundle_currentLanguage
|
228
199
|
};
|
229
200
|
|
230
201
|
function resolveMsg(props: { key: string; args: (string | undefined)[]; doRenderAsHtml: boolean }): string | JSX.Element | undefined {
|
231
202
|
const { key, args, doRenderAsHtml } = props;
|
232
203
|
|
233
|
-
const messageOrUndefined: string | undefined = (
|
204
|
+
const messageOrUndefined: string | undefined = (() => {
|
205
|
+
const messageOrUndefined = (messages_currentLanguage as any)[key] ?? (messages_fallbackLanguage as any)[key];
|
206
|
+
|
207
|
+
if (key === "termsText") {
|
208
|
+
return realmMessageBundleTermsText;
|
209
|
+
}
|
210
|
+
|
211
|
+
return messageOrUndefined;
|
212
|
+
})();
|
234
213
|
|
235
214
|
if (messageOrUndefined === undefined) {
|
236
215
|
return undefined;
|
@@ -281,8 +260,8 @@ function createI18nTranslationFunctionsFactory<MessageKey extends string, ExtraM
|
|
281
260
|
function resolveMsgAdvanced(props: { key: string; args: (string | undefined)[]; doRenderAsHtml: boolean }): JSX.Element | string {
|
282
261
|
const { key, args, doRenderAsHtml } = props;
|
283
262
|
|
284
|
-
if (
|
285
|
-
const resolvedMessage =
|
263
|
+
if (realmMessageBundleUserProfile !== undefined && key in realmMessageBundleUserProfile) {
|
264
|
+
const resolvedMessage = realmMessageBundleUserProfile[key];
|
286
265
|
|
287
266
|
return doRenderAsHtml ? (
|
288
267
|
<span
|
package/src/login/i18n/index.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { GenericI18n, MessageKey, KcContextLike } from "./i18n";
|
2
2
|
export type { MessageKey, KcContextLike };
|
3
3
|
export type I18n = GenericI18n<MessageKey>;
|
4
|
-
export { createUseI18n } from "./
|
4
|
+
export { createUseI18n } from "./useI18n";
|
5
5
|
export { fallbackLanguageTag } from "./i18n";
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import { useEffect, useState } from "react";
|
2
|
+
import {
|
3
|
+
createGetI18n,
|
4
|
+
type GenericI18n,
|
5
|
+
type MessageKey,
|
6
|
+
type KcContextLike
|
7
|
+
} from "./i18n";
|
8
|
+
import { Reflect } from "tsafe/Reflect";
|
9
|
+
|
10
|
+
export function createUseI18n<ExtraMessageKey extends string = never>(extraMessages: {
|
11
|
+
[languageTag: string]: { [key in ExtraMessageKey]: string };
|
12
|
+
}) {
|
13
|
+
type I18n = GenericI18n<MessageKey | ExtraMessageKey>;
|
14
|
+
|
15
|
+
const { getI18n } = createGetI18n(extraMessages);
|
16
|
+
|
17
|
+
function useI18n(params: { kcContext: KcContextLike }): { i18n: I18n } {
|
18
|
+
const { kcContext } = params;
|
19
|
+
|
20
|
+
const { i18n, prI18n_currentLanguage } = getI18n({ kcContext });
|
21
|
+
|
22
|
+
const [i18n_toReturn, setI18n_toReturn] = useState<I18n>(i18n);
|
23
|
+
|
24
|
+
useEffect(() => {
|
25
|
+
let isActive = true;
|
26
|
+
|
27
|
+
prI18n_currentLanguage?.then(i18n => {
|
28
|
+
if (!isActive) {
|
29
|
+
return;
|
30
|
+
}
|
31
|
+
|
32
|
+
setI18n_toReturn(i18n);
|
33
|
+
});
|
34
|
+
|
35
|
+
return () => {
|
36
|
+
isActive = false;
|
37
|
+
};
|
38
|
+
}, []);
|
39
|
+
|
40
|
+
return { i18n: i18n_toReturn };
|
41
|
+
}
|
42
|
+
|
43
|
+
return { useI18n, ofTypeI18n: Reflect<I18n>() };
|
44
|
+
}
|
@@ -0,0 +1,88 @@
|
|
1
|
+
import { useState, useEffect } from "react";
|
2
|
+
import { fallbackLanguageTag } from "keycloakify/login/i18n";
|
3
|
+
import { assert } from "tsafe/assert";
|
4
|
+
import { createStatefulObservable, useRerenderOnChange } from "keycloakify/tools/StatefulObservable";
|
5
|
+
import { useOnFistMount } from "keycloakify/tools/useOnFirstMount";
|
6
|
+
import { KcContext } from "../KcContext";
|
7
|
+
import type { Options as ReactMarkdownOptions } from "../../tools/react-markdown";
|
8
|
+
|
9
|
+
const obs = createStatefulObservable<
|
10
|
+
| {
|
11
|
+
ReactMarkdown: (props: Readonly<ReactMarkdownOptions>) => JSX.Element;
|
12
|
+
termsMarkdown: string;
|
13
|
+
}
|
14
|
+
| undefined
|
15
|
+
>(() => undefined);
|
16
|
+
|
17
|
+
export type KcContextLike_useDownloadTerms = {
|
18
|
+
pageId: string;
|
19
|
+
locale?: {
|
20
|
+
currentLanguageTag: string;
|
21
|
+
};
|
22
|
+
termsAcceptanceRequired?: boolean;
|
23
|
+
};
|
24
|
+
|
25
|
+
assert<KcContext extends KcContextLike_useDownloadTerms ? true : false>();
|
26
|
+
|
27
|
+
/** Allow to avoid bundling the terms and download it on demand*/
|
28
|
+
export function useDownloadTerms(params: {
|
29
|
+
kcContext: KcContextLike_useDownloadTerms;
|
30
|
+
downloadTermsMarkdown: (params: { currentLanguageTag: string }) => Promise<{ termsMarkdown: string; termsLanguageTag: string | undefined }>;
|
31
|
+
}) {
|
32
|
+
const { kcContext, downloadTermsMarkdown } = params;
|
33
|
+
|
34
|
+
useOnFistMount(async () => {
|
35
|
+
if (kcContext.pageId === "terms.ftl" || kcContext.termsAcceptanceRequired) {
|
36
|
+
const currentLanguageTag = kcContext.locale?.currentLanguageTag ?? fallbackLanguageTag;
|
37
|
+
|
38
|
+
const [ReactMarkdown_base, { termsMarkdown, termsLanguageTag }] = await Promise.all([
|
39
|
+
import("../../tools/react-markdown").then(_ => _.default),
|
40
|
+
downloadTermsMarkdown({ currentLanguageTag })
|
41
|
+
] as const);
|
42
|
+
|
43
|
+
const htmlLang = termsLanguageTag !== currentLanguageTag ? termsLanguageTag : undefined;
|
44
|
+
|
45
|
+
const ReactMarkdown: (props: Readonly<ReactMarkdownOptions>) => JSX.Element =
|
46
|
+
htmlLang === undefined
|
47
|
+
? ReactMarkdown_base
|
48
|
+
: props => {
|
49
|
+
const [anchor, setAnchor] = useState<HTMLDivElement | null>(null);
|
50
|
+
|
51
|
+
useEffect(() => {
|
52
|
+
if (anchor === null) {
|
53
|
+
return;
|
54
|
+
}
|
55
|
+
|
56
|
+
const parent = anchor.parentElement;
|
57
|
+
|
58
|
+
assert(parent !== null);
|
59
|
+
|
60
|
+
parent.setAttribute("lang", htmlLang);
|
61
|
+
|
62
|
+
anchor.remove();
|
63
|
+
}, [anchor]);
|
64
|
+
|
65
|
+
return (
|
66
|
+
<>
|
67
|
+
<ReactMarkdown_base {...props} />
|
68
|
+
<div ref={setAnchor} style={{ display: "none" }} aria-hidden />
|
69
|
+
</>
|
70
|
+
);
|
71
|
+
};
|
72
|
+
|
73
|
+
obs.current = { ReactMarkdown, termsMarkdown };
|
74
|
+
}
|
75
|
+
});
|
76
|
+
}
|
77
|
+
|
78
|
+
export function useTermsMarkdown() {
|
79
|
+
useRerenderOnChange(obs);
|
80
|
+
|
81
|
+
if (obs.current === undefined) {
|
82
|
+
return { isDownloadComplete: false as const };
|
83
|
+
}
|
84
|
+
|
85
|
+
const { ReactMarkdown, termsMarkdown } = obs.current;
|
86
|
+
|
87
|
+
return { isDownloadComplete: true, ReactMarkdown, termsMarkdown };
|
88
|
+
}
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import { useState } from "react";
|
2
|
-
import { Markdown } from "keycloakify/tools/Markdown";
|
3
2
|
import type { LazyOrNot } from "keycloakify/tools/LazyOrNot";
|
4
3
|
import { useTermsMarkdown } from "keycloakify/login/lib/useDownloadTerms";
|
5
4
|
import { getKcClsx, type KcClsx } from "keycloakify/login/lib/kcClsx";
|
@@ -78,23 +77,14 @@ export default function Register(props: RegisterProps) {
|
|
78
77
|
function TermsAcceptance(props: { i18n: I18n; kcClsx: KcClsx; messagesPerField: Pick<KcContext["messagesPerField"], "existsError" | "get"> }) {
|
79
78
|
const { i18n, kcClsx, messagesPerField } = props;
|
80
79
|
|
81
|
-
const { msg } = i18n;
|
82
|
-
|
83
|
-
// NOTE: Refer to https://docs.keycloakify.dev/terms-and-conditions to load your terms and conditions.
|
84
|
-
const { termsMarkdown } = useTermsMarkdown();
|
85
|
-
|
86
|
-
if (termsMarkdown === undefined) {
|
87
|
-
return null;
|
88
|
-
}
|
80
|
+
const { msg, msgStr } = i18n;
|
89
81
|
|
90
82
|
return (
|
91
83
|
<>
|
92
84
|
<div className="form-group">
|
93
85
|
<div className={kcClsx("kcInputWrapperClass")}>
|
94
86
|
{msg("termsTitle")}
|
95
|
-
<div id="kc-registration-terms-text">
|
96
|
-
<Markdown>{termsMarkdown}</Markdown>
|
97
|
-
</div>
|
87
|
+
<div id="kc-registration-terms-text">{msgStr("termsText") ? msg("termsText") : <TermsMarkdown />}</div>
|
98
88
|
</div>
|
99
89
|
</div>
|
100
90
|
<div className="form-group">
|
@@ -121,3 +111,13 @@ function TermsAcceptance(props: { i18n: I18n; kcClsx: KcClsx; messagesPerField:
|
|
121
111
|
</>
|
122
112
|
);
|
123
113
|
}
|
114
|
+
|
115
|
+
function TermsMarkdown() {
|
116
|
+
const { isDownloadComplete, termsMarkdown, ReactMarkdown } = useTermsMarkdown();
|
117
|
+
|
118
|
+
if (!isDownloadComplete) {
|
119
|
+
return null;
|
120
|
+
}
|
121
|
+
|
122
|
+
return <ReactMarkdown>{termsMarkdown}</ReactMarkdown>;
|
123
|
+
}
|
@@ -1,4 +1,3 @@
|
|
1
|
-
import { Markdown } from "keycloakify/tools/Markdown";
|
2
1
|
import { getKcClsx } from "keycloakify/login/lib/kcClsx";
|
3
2
|
import { useTermsMarkdown } from "keycloakify/login/lib/useDownloadTerms";
|
4
3
|
import type { PageProps } from "keycloakify/login/pages/PageProps";
|
@@ -15,13 +14,7 @@ export default function Terms(props: PageProps<Extract<KcContext, { pageId: "ter
|
|
15
14
|
|
16
15
|
const { msg, msgStr } = i18n;
|
17
16
|
|
18
|
-
const {
|
19
|
-
|
20
|
-
const { isDownloadComplete, termsMarkdown, termsLanguageTag } = useTermsMarkdown();
|
21
|
-
|
22
|
-
if (!isDownloadComplete) {
|
23
|
-
return null;
|
24
|
-
}
|
17
|
+
const { url } = kcContext;
|
25
18
|
|
26
19
|
return (
|
27
20
|
<Template
|
@@ -32,9 +25,7 @@ export default function Terms(props: PageProps<Extract<KcContext, { pageId: "ter
|
|
32
25
|
displayMessage={false}
|
33
26
|
headerNode={msg("termsTitle")}
|
34
27
|
>
|
35
|
-
<div id="kc-terms-text"
|
36
|
-
<Markdown>{termsMarkdown}</Markdown>
|
37
|
-
</div>
|
28
|
+
<div id="kc-terms-text">{msgStr("termsText") ? msg("termsText") : <TermsMarkdown />}</div>
|
38
29
|
<form className="form-actions" action={url.loginAction} method="POST">
|
39
30
|
<input
|
40
31
|
className={kcClsx("kcButtonClass", "kcButtonClass", "kcButtonClass", "kcButtonPrimaryClass", "kcButtonLargeClass")}
|
@@ -55,3 +46,13 @@ export default function Terms(props: PageProps<Extract<KcContext, { pageId: "ter
|
|
55
46
|
</Template>
|
56
47
|
);
|
57
48
|
}
|
49
|
+
|
50
|
+
function TermsMarkdown() {
|
51
|
+
const { isDownloadComplete, termsMarkdown, ReactMarkdown } = useTermsMarkdown();
|
52
|
+
|
53
|
+
if (!isDownloadComplete) {
|
54
|
+
return null;
|
55
|
+
}
|
56
|
+
|
57
|
+
return <ReactMarkdown>{termsMarkdown}</ReactMarkdown>;
|
58
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"react-markdown.js","sourceRoot":"","sources":["../src/tools/react-markdown.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,eAAe,QAAQ,CAAC"}
|
package/vite-plugin/index.js
CHANGED
@@ -4569,12 +4569,10 @@ __nccwpck_require__.r(__webpack_exports__);
|
|
4569
4569
|
/* harmony export */ "keycloak_resources": () => (/* binding */ keycloak_resources),
|
4570
4570
|
/* harmony export */ "lastKeycloakVersionWithAccountV1": () => (/* binding */ lastKeycloakVersionWithAccountV1),
|
4571
4571
|
/* harmony export */ "loginThemePageIds": () => (/* binding */ loginThemePageIds),
|
4572
|
-
/* harmony export */ "nameOfTheLocalizationRealmOverridesUserProfileProperty": () => (/* binding */ nameOfTheLocalizationRealmOverridesUserProfileProperty),
|
4573
4572
|
/* harmony export */ "resources_common": () => (/* binding */ resources_common),
|
4574
4573
|
/* harmony export */ "themeTypes": () => (/* binding */ themeTypes),
|
4575
4574
|
/* harmony export */ "vitePluginSubScriptEnvNames": () => (/* binding */ vitePluginSubScriptEnvNames)
|
4576
4575
|
/* harmony export */ });
|
4577
|
-
const nameOfTheLocalizationRealmOverridesUserProfileProperty = "__localizationRealmOverridesUserProfile";
|
4578
4576
|
const keycloak_resources = "keycloak-resources";
|
4579
4577
|
const resources_common = "resources-common";
|
4580
4578
|
const lastKeycloakVersionWithAccountV1 = "21.1.2";
|
@@ -1,57 +0,0 @@
|
|
1
|
-
import { fallbackLanguageTag } from "keycloakify/login/i18n";
|
2
|
-
import { assert } from "tsafe/assert";
|
3
|
-
import {
|
4
|
-
createStatefulObservable,
|
5
|
-
useRerenderOnChange
|
6
|
-
} from "keycloakify/tools/StatefulObservable";
|
7
|
-
import { useOnFistMount } from "keycloakify/tools/useOnFirstMount";
|
8
|
-
import { KcContext } from "../KcContext";
|
9
|
-
|
10
|
-
const obs = createStatefulObservable<
|
11
|
-
| {
|
12
|
-
termsMarkdown: string;
|
13
|
-
termsLanguageTag: string | undefined;
|
14
|
-
}
|
15
|
-
| undefined
|
16
|
-
>(() => undefined);
|
17
|
-
|
18
|
-
export type KcContextLike = {
|
19
|
-
pageId: string;
|
20
|
-
locale?: {
|
21
|
-
currentLanguageTag: string;
|
22
|
-
};
|
23
|
-
termsAcceptanceRequired?: boolean;
|
24
|
-
};
|
25
|
-
|
26
|
-
assert<KcContext extends KcContextLike ? true : false>();
|
27
|
-
|
28
|
-
/** Allow to avoid bundling the terms and download it on demand*/
|
29
|
-
export function useDownloadTerms(params: {
|
30
|
-
kcContext: KcContextLike;
|
31
|
-
downloadTermsMarkdown: (params: {
|
32
|
-
currentLanguageTag: string;
|
33
|
-
}) => Promise<{ termsMarkdown: string; termsLanguageTag: string | undefined }>;
|
34
|
-
}) {
|
35
|
-
const { kcContext, downloadTermsMarkdown } = params;
|
36
|
-
|
37
|
-
useOnFistMount(async () => {
|
38
|
-
if (kcContext.pageId === "terms.ftl" || kcContext.termsAcceptanceRequired) {
|
39
|
-
obs.current = await downloadTermsMarkdown({
|
40
|
-
currentLanguageTag:
|
41
|
-
kcContext.locale?.currentLanguageTag ?? fallbackLanguageTag
|
42
|
-
});
|
43
|
-
}
|
44
|
-
});
|
45
|
-
}
|
46
|
-
|
47
|
-
export function useTermsMarkdown() {
|
48
|
-
useRerenderOnChange(obs);
|
49
|
-
|
50
|
-
if (obs.current === undefined) {
|
51
|
-
return { isDownloadComplete: false as const };
|
52
|
-
}
|
53
|
-
|
54
|
-
const { termsMarkdown, termsLanguageTag } = obs.current;
|
55
|
-
|
56
|
-
return { isDownloadComplete: true, termsMarkdown, termsLanguageTag };
|
57
|
-
}
|
package/src/tools/Markdown.ts
DELETED
package/tools/Markdown.d.ts
DELETED
package/tools/Markdown.js
DELETED
package/tools/Markdown.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"Markdown.js","sourceRoot":"","sources":["../src/tools/Markdown.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAEtC,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|