keycloakify 6.11.8 → 6.12.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.
Files changed (253) hide show
  1. package/README.md +10 -7
  2. package/bin/create-keycloak-email-directory.js +1 -1
  3. package/bin/download-builtin-keycloak-theme.js +1 -1
  4. package/bin/keycloakify/BuildOptions.d.ts +2 -2
  5. package/bin/keycloakify/BuildOptions.js.map +1 -1
  6. package/bin/keycloakify/generateFtl/generateFtl.d.ts +2 -2
  7. package/bin/keycloakify/generateJavaStackFiles.d.ts +1 -1
  8. package/bin/keycloakify/generateKeycloakThemeResources.d.ts +1 -1
  9. package/bin/keycloakify/generateKeycloakThemeResources.js +1 -1
  10. package/bin/keycloakify/generateStartKeycloakTestingContainer.d.ts +1 -1
  11. package/bin/keycloakify/keycloakify.js +1 -1
  12. package/bin/keycloakify/replacers/replaceImportsFromStaticInJsCode.d.ts +1 -1
  13. package/bin/keycloakify/replacers/replaceImportsInCssCode.d.ts +1 -1
  14. package/bin/keycloakify/replacers/replaceImportsInInlineCssCode.d.ts +1 -1
  15. package/bin/promptKeycloakVersion.js +1 -1
  16. package/bin/tools/NpmModuleVersion.d.ts +1 -1
  17. package/bin/tools/cliOptions.d.ts +1 -1
  18. package/bin/tools/deflate.js +1 -1
  19. package/bin/tools/downloadAndUnzip.js +51 -44
  20. package/bin/tools/downloadAndUnzip.js.map +1 -1
  21. package/bin/tools/grant-exec-perms.js +3 -2
  22. package/bin/tools/grant-exec-perms.js.map +1 -1
  23. package/bin/tools/jar.d.ts +1 -1
  24. package/bin/tools/jar.js +1 -1
  25. package/bin/tools/logger.d.ts +2 -2
  26. package/bin/tools/octokit-addons/getLatestsSemVersionedTag.js +34 -27
  27. package/bin/tools/octokit-addons/getLatestsSemVersionedTag.js.map +1 -1
  28. package/bin/tools/octokit-addons/listTags.js +1 -1
  29. package/bin/tools/transformCodebase.d.ts +1 -1
  30. package/bin/tools/walk.js +1 -1
  31. package/bin/tools/zip.d.ts +2 -2
  32. package/bin/tools/zip.js +1 -1
  33. package/bin/tsconfig.tsbuildinfo +1 -1
  34. package/lib/KcApp.d.ts +6 -0
  35. package/lib/{components/KcApp.js → KcApp.js} +25 -26
  36. package/lib/KcApp.js.map +1 -0
  37. package/lib/{components/KcProps.d.ts → KcProps.d.ts} +30 -6
  38. package/lib/{components/KcProps.js → KcProps.js} +1 -1
  39. package/lib/KcProps.js.map +1 -0
  40. package/lib/Template.d.ts +5 -0
  41. package/lib/{components/Template.js → Template.js} +12 -14
  42. package/lib/Template.js.map +1 -0
  43. package/lib/getKcContext/KcContextBase.d.ts +6 -6
  44. package/lib/getKcContext/getKcContextFromWindow.d.ts +1 -1
  45. package/lib/getKcContext/{kcContextMocks/kcContextMocks.d.ts → kcContextMocks.d.ts} +1 -1
  46. package/lib/getKcContext/{kcContextMocks/kcContextMocks.js → kcContextMocks.js} +8 -5
  47. package/lib/getKcContext/kcContextMocks.js.map +1 -0
  48. package/lib/i18n/i18n.d.ts +100 -0
  49. package/lib/i18n/i18n.js +160 -0
  50. package/lib/i18n/i18n.js.map +1 -0
  51. package/lib/i18n/index.d.ts +1 -99
  52. package/lib/i18n/index.js +1 -159
  53. package/lib/i18n/index.js.map +1 -1
  54. package/lib/index.d.ts +3 -3
  55. package/lib/index.js +3 -3
  56. package/lib/index.js.map +1 -1
  57. package/lib/pages/Error.d.ts +5 -0
  58. package/lib/{components → pages}/Error.js +4 -6
  59. package/lib/pages/Error.js.map +1 -0
  60. package/lib/pages/IdpReviewUserProfile.d.ts +5 -0
  61. package/lib/{components → pages}/IdpReviewUserProfile.js +4 -6
  62. package/lib/pages/IdpReviewUserProfile.js.map +1 -0
  63. package/lib/pages/Info.d.ts +5 -0
  64. package/lib/{components → pages}/Info.js +4 -6
  65. package/lib/pages/Info.js.map +1 -0
  66. package/lib/pages/Login.d.ts +5 -0
  67. package/lib/{components → pages}/Login.js +5 -7
  68. package/lib/pages/Login.js.map +1 -0
  69. package/lib/pages/LoginConfigTotp.d.ts +5 -0
  70. package/lib/{components → pages}/LoginConfigTotp.js +4 -6
  71. package/lib/pages/LoginConfigTotp.js.map +1 -0
  72. package/lib/pages/LoginIdpLinkConfirm.d.ts +5 -0
  73. package/lib/{components → pages}/LoginIdpLinkConfirm.js +4 -6
  74. package/lib/pages/LoginIdpLinkConfirm.js.map +1 -0
  75. package/lib/pages/LoginIdpLinkEmail.d.ts +5 -0
  76. package/lib/{components → pages}/LoginIdpLinkEmail.js +4 -6
  77. package/lib/pages/LoginIdpLinkEmail.js.map +1 -0
  78. package/lib/pages/LoginOtp.d.ts +5 -0
  79. package/lib/{components → pages}/LoginOtp.js +4 -6
  80. package/lib/pages/LoginOtp.js.map +1 -0
  81. package/lib/pages/LoginPageExpired.d.ts +5 -0
  82. package/lib/{components → pages}/LoginPageExpired.js +4 -6
  83. package/lib/pages/LoginPageExpired.js.map +1 -0
  84. package/lib/pages/LoginPassword.d.ts +5 -0
  85. package/lib/{components → pages}/LoginPassword.js +5 -7
  86. package/lib/pages/LoginPassword.js.map +1 -0
  87. package/lib/pages/LoginResetPassword.d.ts +5 -0
  88. package/lib/{components → pages}/LoginResetPassword.js +4 -6
  89. package/lib/pages/LoginResetPassword.js.map +1 -0
  90. package/lib/pages/LoginUpdatePassword.d.ts +5 -0
  91. package/lib/{components → pages}/LoginUpdatePassword.js +4 -6
  92. package/lib/pages/LoginUpdatePassword.js.map +1 -0
  93. package/lib/pages/LoginUpdateProfile.d.ts +5 -0
  94. package/lib/{components → pages}/LoginUpdateProfile.js +4 -6
  95. package/lib/pages/LoginUpdateProfile.js.map +1 -0
  96. package/lib/pages/LoginUsername.d.ts +5 -0
  97. package/lib/{components → pages}/LoginUsername.js +5 -7
  98. package/lib/pages/LoginUsername.js.map +1 -0
  99. package/lib/pages/LoginVerifyEmail.d.ts +5 -0
  100. package/lib/{components → pages}/LoginVerifyEmail.js +4 -6
  101. package/lib/pages/LoginVerifyEmail.js.map +1 -0
  102. package/lib/pages/LogoutConfirm.d.ts +5 -0
  103. package/lib/{components → pages}/LogoutConfirm.js +4 -6
  104. package/lib/pages/LogoutConfirm.js.map +1 -0
  105. package/lib/pages/Register.d.ts +5 -0
  106. package/lib/{components → pages}/Register.js +4 -6
  107. package/lib/pages/Register.js.map +1 -0
  108. package/lib/pages/RegisterUserProfile.d.ts +5 -0
  109. package/lib/{components → pages}/RegisterUserProfile.js +4 -6
  110. package/lib/pages/RegisterUserProfile.js.map +1 -0
  111. package/lib/pages/Terms.d.ts +19 -0
  112. package/lib/{components → pages}/Terms.js +20 -22
  113. package/lib/pages/Terms.js.map +1 -0
  114. package/lib/pages/UpdateUserProfile.d.ts +5 -0
  115. package/lib/{components → pages}/UpdateUserProfile.js +4 -6
  116. package/lib/pages/UpdateUserProfile.js.map +1 -0
  117. package/lib/pages/WebauthnAuthenticate.d.ts +5 -0
  118. package/lib/{components → pages}/WebauthnAuthenticate.js +5 -7
  119. package/lib/pages/WebauthnAuthenticate.js.map +1 -0
  120. package/lib/{components → pages}/shared/UserProfileCommons.d.ts +6 -6
  121. package/lib/{components → pages}/shared/UserProfileCommons.js +4 -4
  122. package/lib/pages/shared/UserProfileCommons.js.map +1 -0
  123. package/lib/tools/AndByDiscriminatingKey.d.ts +1 -1
  124. package/lib/tools/DeepPartial.d.ts +1 -1
  125. package/lib/tools/ReactComponent.d.ts +1 -1
  126. package/lib/tools/SetOptional.d.ts +1 -0
  127. package/lib/tools/SetOptional.js +2 -0
  128. package/lib/tools/SetOptional.js.map +1 -0
  129. package/lib/tools/clsx.d.ts +2 -3
  130. package/lib/tools/clsx.js +39 -3
  131. package/lib/tools/clsx.js.map +1 -1
  132. package/lib/tools/deepAssign.js +1 -1
  133. package/lib/tools/deepAssign.js.map +1 -1
  134. package/lib/tools/memoize.d.ts +7 -0
  135. package/lib/tools/memoize.js +38 -0
  136. package/lib/tools/memoize.js.map +1 -0
  137. package/lib/tools/useCallbackFactory.d.ts +15 -0
  138. package/lib/tools/useCallbackFactory.js +28 -0
  139. package/lib/tools/useCallbackFactory.js.map +1 -0
  140. package/lib/tools/useConst.d.ts +5 -0
  141. package/lib/tools/useConst.js +10 -0
  142. package/lib/tools/useConst.js.map +1 -0
  143. package/lib/tools/useConstCallback.d.ts +2 -0
  144. package/lib/tools/useConstCallback.js +8 -0
  145. package/lib/tools/useConstCallback.js.map +1 -0
  146. package/lib/tools/useCssAndCx.d.ts +1 -1
  147. package/lib/tsconfig.tsbuildinfo +1 -1
  148. package/lib/useFormValidationSlice.d.ts +4 -4
  149. package/lib/useFormValidationSlice.js +1 -1
  150. package/lib/useFormValidationSlice.js.map +1 -1
  151. package/package.json +133 -124
  152. package/src/bin/keycloakify/BuildOptions.ts +2 -2
  153. package/src/bin/keycloakify/generateFtl/generateFtl.ts +1 -1
  154. package/src/lib/{components/KcApp.tsx → KcApp.tsx} +29 -38
  155. package/src/lib/{components/KcProps.ts → KcProps.ts} +27 -1
  156. package/src/lib/{components/Template.tsx → Template.tsx} +23 -38
  157. package/src/lib/getKcContext/KcContextBase.ts +1 -1
  158. package/src/lib/getKcContext/{kcContextMocks/kcContextMocks.ts → kcContextMocks.ts} +9 -6
  159. package/src/lib/i18n/i18n.tsx +292 -0
  160. package/src/lib/i18n/index.tsx +1 -290
  161. package/src/lib/index.ts +3 -3
  162. package/src/lib/{components → pages}/Error.tsx +7 -18
  163. package/src/lib/{components → pages}/IdpReviewUserProfile.tsx +7 -18
  164. package/src/lib/{components → pages}/Info.tsx +7 -18
  165. package/src/lib/{components → pages}/Login.tsx +8 -20
  166. package/src/lib/{components → pages}/LoginConfigTotp.tsx +7 -18
  167. package/src/lib/{components → pages}/LoginIdpLinkConfirm.tsx +7 -18
  168. package/src/lib/{components → pages}/LoginIdpLinkEmail.tsx +7 -18
  169. package/src/lib/{components → pages}/LoginOtp.tsx +7 -18
  170. package/src/lib/{components → pages}/LoginPageExpired.tsx +7 -18
  171. package/src/lib/{components → pages}/LoginPassword.tsx +8 -19
  172. package/src/lib/{components → pages}/LoginResetPassword.tsx +7 -18
  173. package/src/lib/{components → pages}/LoginUpdatePassword.tsx +7 -18
  174. package/src/lib/{components → pages}/LoginUpdateProfile.tsx +7 -18
  175. package/src/lib/{components → pages}/LoginUsername.tsx +8 -19
  176. package/src/lib/{components → pages}/LoginVerifyEmail.tsx +7 -18
  177. package/src/lib/{components → pages}/LogoutConfirm.tsx +7 -18
  178. package/src/lib/{components → pages}/Register.tsx +7 -18
  179. package/src/lib/{components → pages}/RegisterUserProfile.tsx +7 -18
  180. package/src/lib/{components → pages}/Terms.tsx +50 -61
  181. package/src/lib/{components → pages}/UpdateUserProfile.tsx +7 -18
  182. package/src/lib/{components → pages}/WebauthnAuthenticate.tsx +9 -19
  183. package/src/lib/pages/shared/UserProfileCommons.tsx +178 -0
  184. package/src/lib/tools/SetOptional.ts +1 -0
  185. package/src/lib/tools/clsx.ts +42 -5
  186. package/src/lib/tools/deepAssign.ts +1 -1
  187. package/src/lib/tools/memoize.ts +55 -0
  188. package/src/lib/tools/useCallbackFactory.ts +45 -0
  189. package/src/lib/tools/useConst.ts +10 -0
  190. package/src/lib/tools/useConstCallback.ts +15 -0
  191. package/src/lib/useFormValidationSlice.tsx +4 -4
  192. package/bin/generate-i18n-messages.d.ts +0 -1
  193. package/bin/generate-i18n-messages.js +0 -126
  194. package/bin/generate-i18n-messages.js.map +0 -1
  195. package/bin/link_in_test_app.d.ts +0 -1
  196. package/bin/link_in_test_app.js +0 -141
  197. package/bin/link_in_test_app.js.map +0 -1
  198. package/lib/components/Error.d.ts +0 -13
  199. package/lib/components/Error.js.map +0 -1
  200. package/lib/components/IdpReviewUserProfile.d.ts +0 -13
  201. package/lib/components/IdpReviewUserProfile.js.map +0 -1
  202. package/lib/components/Info.d.ts +0 -13
  203. package/lib/components/Info.js.map +0 -1
  204. package/lib/components/KcApp.d.ts +0 -13
  205. package/lib/components/KcApp.js.map +0 -1
  206. package/lib/components/KcProps.js.map +0 -1
  207. package/lib/components/Login.d.ts +0 -13
  208. package/lib/components/Login.js.map +0 -1
  209. package/lib/components/LoginConfigTotp.d.ts +0 -13
  210. package/lib/components/LoginConfigTotp.js.map +0 -1
  211. package/lib/components/LoginIdpLinkConfirm.d.ts +0 -13
  212. package/lib/components/LoginIdpLinkConfirm.js.map +0 -1
  213. package/lib/components/LoginIdpLinkEmail.d.ts +0 -13
  214. package/lib/components/LoginIdpLinkEmail.js.map +0 -1
  215. package/lib/components/LoginOtp.d.ts +0 -13
  216. package/lib/components/LoginOtp.js.map +0 -1
  217. package/lib/components/LoginPageExpired.d.ts +0 -13
  218. package/lib/components/LoginPageExpired.js.map +0 -1
  219. package/lib/components/LoginPassword.d.ts +0 -13
  220. package/lib/components/LoginPassword.js.map +0 -1
  221. package/lib/components/LoginResetPassword.d.ts +0 -13
  222. package/lib/components/LoginResetPassword.js.map +0 -1
  223. package/lib/components/LoginUpdatePassword.d.ts +0 -13
  224. package/lib/components/LoginUpdatePassword.js.map +0 -1
  225. package/lib/components/LoginUpdateProfile.d.ts +0 -13
  226. package/lib/components/LoginUpdateProfile.js.map +0 -1
  227. package/lib/components/LoginUsername.d.ts +0 -13
  228. package/lib/components/LoginUsername.js.map +0 -1
  229. package/lib/components/LoginVerifyEmail.d.ts +0 -13
  230. package/lib/components/LoginVerifyEmail.js.map +0 -1
  231. package/lib/components/LogoutConfirm.d.ts +0 -13
  232. package/lib/components/LogoutConfirm.js.map +0 -1
  233. package/lib/components/Register.d.ts +0 -13
  234. package/lib/components/Register.js.map +0 -1
  235. package/lib/components/RegisterUserProfile.d.ts +0 -13
  236. package/lib/components/RegisterUserProfile.js.map +0 -1
  237. package/lib/components/Template.d.ts +0 -25
  238. package/lib/components/Template.js.map +0 -1
  239. package/lib/components/Terms.d.ts +0 -27
  240. package/lib/components/Terms.js.map +0 -1
  241. package/lib/components/UpdateUserProfile.d.ts +0 -13
  242. package/lib/components/UpdateUserProfile.js.map +0 -1
  243. package/lib/components/WebauthnAuthenticate.d.ts +0 -13
  244. package/lib/components/WebauthnAuthenticate.js.map +0 -1
  245. package/lib/components/shared/UserProfileCommons.js.map +0 -1
  246. package/lib/getKcContext/kcContextMocks/index.d.ts +0 -1
  247. package/lib/getKcContext/kcContextMocks/index.js +0 -2
  248. package/lib/getKcContext/kcContextMocks/index.js.map +0 -1
  249. package/lib/getKcContext/kcContextMocks/kcContextMocks.js.map +0 -1
  250. package/src/bin/generate-i18n-messages.ts +0 -86
  251. package/src/bin/link_in_test_app.ts +0 -128
  252. package/src/lib/components/shared/UserProfileCommons.tsx +0 -173
  253. package/src/lib/getKcContext/kcContextMocks/index.ts +0 -1
@@ -0,0 +1,178 @@
1
+ import React, { useEffect, Fragment } from "react";
2
+ import type { KcProps } from "../../KcProps";
3
+ import type { Attribute } from "../../getKcContext/KcContextBase";
4
+ import { clsx } from "../../tools/clsx";
5
+ import type { ReactComponent } from "../../tools/ReactComponent";
6
+ import { useCallbackFactory } from "../../tools/useCallbackFactory";
7
+ import { useFormValidationSlice } from "../../useFormValidationSlice";
8
+ import type { I18nBase } from "../../i18n";
9
+ import type { Param0 } from "tsafe/Param0";
10
+
11
+ export type UserProfileFormFieldsProps = {
12
+ kcContext: Param0<typeof useFormValidationSlice>["kcContext"];
13
+ i18n: I18nBase;
14
+ } & KcProps &
15
+ Partial<Record<"BeforeField" | "AfterField", ReactComponent<{ attribute: Attribute }>>> & {
16
+ onIsFormSubmittableValueChange: (isFormSubmittable: boolean) => void;
17
+ };
18
+
19
+ export function UserProfileFormFields({
20
+ kcContext,
21
+ onIsFormSubmittableValueChange,
22
+ i18n,
23
+ BeforeField,
24
+ AfterField,
25
+ ...props
26
+ }: UserProfileFormFieldsProps) {
27
+ const { advancedMsg } = i18n;
28
+
29
+ const {
30
+ formValidationState: { fieldStateByAttributeName, isFormSubmittable },
31
+ formValidationReducer,
32
+ attributesWithPassword
33
+ } = useFormValidationSlice({
34
+ kcContext,
35
+ i18n
36
+ });
37
+
38
+ useEffect(() => {
39
+ onIsFormSubmittableValueChange(isFormSubmittable);
40
+ }, [isFormSubmittable]);
41
+
42
+ const onChangeFactory = useCallbackFactory(
43
+ (
44
+ [name]: [string],
45
+ [
46
+ {
47
+ target: { value }
48
+ }
49
+ ]: [React.ChangeEvent<HTMLInputElement | HTMLSelectElement>]
50
+ ) =>
51
+ formValidationReducer({
52
+ "action": "update value",
53
+ name,
54
+ "newValue": value
55
+ })
56
+ );
57
+
58
+ const onBlurFactory = useCallbackFactory(([name]: [string]) =>
59
+ formValidationReducer({
60
+ "action": "focus lost",
61
+ name
62
+ })
63
+ );
64
+
65
+ let currentGroup = "";
66
+
67
+ return (
68
+ <>
69
+ {attributesWithPassword.map((attribute, i) => {
70
+ const { group = "", groupDisplayHeader = "", groupDisplayDescription = "" } = attribute;
71
+
72
+ const { value, displayableErrors } = fieldStateByAttributeName[attribute.name];
73
+
74
+ const formGroupClassName = clsx(props.kcFormGroupClass, displayableErrors.length !== 0 && props.kcFormGroupErrorClass);
75
+
76
+ return (
77
+ <Fragment key={i}>
78
+ {group !== currentGroup && (currentGroup = group) !== "" && (
79
+ <div className={formGroupClassName}>
80
+ <div className={clsx(props.kcContentWrapperClass)}>
81
+ <label id={`header-${group}`} className={clsx(props.kcFormGroupHeader)}>
82
+ {advancedMsg(groupDisplayHeader) || currentGroup}
83
+ </label>
84
+ </div>
85
+ {groupDisplayDescription !== "" && (
86
+ <div className={clsx(props.kcLabelWrapperClass)}>
87
+ <label id={`description-${group}`} className={`${clsx(props.kcLabelClass)}`}>
88
+ {advancedMsg(groupDisplayDescription)}
89
+ </label>
90
+ </div>
91
+ )}
92
+ </div>
93
+ )}
94
+
95
+ {BeforeField && <BeforeField attribute={attribute} />}
96
+
97
+ <div className={formGroupClassName}>
98
+ <div className={clsx(props.kcLabelWrapperClass)}>
99
+ <label htmlFor={attribute.name} className={clsx(props.kcLabelClass)}>
100
+ {advancedMsg(attribute.displayName ?? "")}
101
+ </label>
102
+ {attribute.required && <>*</>}
103
+ </div>
104
+ <div className={clsx(props.kcInputWrapperClass)}>
105
+ {(() => {
106
+ const { options } = attribute.validators;
107
+
108
+ if (options !== undefined) {
109
+ return (
110
+ <select
111
+ id={attribute.name}
112
+ name={attribute.name}
113
+ onChange={onChangeFactory(attribute.name)}
114
+ onBlur={onBlurFactory(attribute.name)}
115
+ value={value}
116
+ >
117
+ {options.options.map(option => (
118
+ <option key={option} value={option}>
119
+ {option}
120
+ </option>
121
+ ))}
122
+ </select>
123
+ );
124
+ }
125
+
126
+ return (
127
+ <input
128
+ type={(() => {
129
+ switch (attribute.name) {
130
+ case "password-confirm":
131
+ case "password":
132
+ return "password";
133
+ default:
134
+ return "text";
135
+ }
136
+ })()}
137
+ id={attribute.name}
138
+ name={attribute.name}
139
+ value={value}
140
+ onChange={onChangeFactory(attribute.name)}
141
+ className={clsx(props.kcInputClass)}
142
+ aria-invalid={displayableErrors.length !== 0}
143
+ disabled={attribute.readOnly}
144
+ autoComplete={attribute.autocomplete}
145
+ onBlur={onBlurFactory(attribute.name)}
146
+ />
147
+ );
148
+ })()}
149
+ {displayableErrors.length !== 0 &&
150
+ (() => {
151
+ const divId = `input-error-${attribute.name}`;
152
+
153
+ return (
154
+ <>
155
+ <style>{`#${divId} > span: { display: block; }`}</style>
156
+ <span
157
+ id={divId}
158
+ className={clsx(props.kcInputErrorMessageClass)}
159
+ style={{
160
+ "position": displayableErrors.length === 1 ? "absolute" : undefined
161
+ }}
162
+ aria-live="polite"
163
+ >
164
+ {displayableErrors.map(({ errorMessage }) => errorMessage)}
165
+ </span>
166
+ </>
167
+ );
168
+ })()}
169
+ </div>
170
+ </div>
171
+
172
+ {AfterField && <AfterField attribute={attribute} />}
173
+ </Fragment>
174
+ );
175
+ })}
176
+ </>
177
+ );
178
+ }
@@ -0,0 +1 @@
1
+ export type SetOptional<T extends Record<string, unknown>, K extends keyof T> = Omit<T, K> & Partial<Record<K, T[K]>>;
@@ -1,7 +1,44 @@
1
- import { classnames } from "tss-react/tools/classnames";
2
- import type { Cx } from "tss-react";
1
+ import { assert } from "tsafe/assert";
2
+ import { typeGuard } from "tsafe/typeGuard";
3
3
 
4
- /** Drop in replacement for https://www.npmjs.com/package/clsx */
5
- export const clsx: Cx = (...args) => {
6
- return classnames(args);
4
+ export type CxArg = undefined | null | string | boolean | Partial<Record<string, boolean | null | undefined>> | readonly CxArg[];
5
+
6
+ export const clsx = (...args: CxArg[]): string => {
7
+ const len = args.length;
8
+ let i = 0;
9
+ let cls = "";
10
+ for (; i < len; i++) {
11
+ const arg = args[i];
12
+ if (arg == null) continue;
13
+
14
+ let toAdd;
15
+ switch (typeof arg) {
16
+ case "boolean":
17
+ break;
18
+ case "object": {
19
+ if (Array.isArray(arg)) {
20
+ toAdd = clsx(...arg);
21
+ } else {
22
+ assert(!typeGuard<{ length: number }>(arg, false));
23
+
24
+ toAdd = "";
25
+ for (const k in arg) {
26
+ if (arg[k as string] && k) {
27
+ toAdd && (toAdd += " ");
28
+ toAdd += k;
29
+ }
30
+ }
31
+ }
32
+ break;
33
+ }
34
+ default: {
35
+ toAdd = arg;
36
+ }
37
+ }
38
+ if (toAdd) {
39
+ cls && (cls += " ");
40
+ cls += toAdd;
41
+ }
42
+ }
43
+ return cls;
7
44
  };
@@ -11,7 +11,7 @@ export function deepAssign(params: { target: Record<string, unknown>; source: Re
11
11
  Object.keys(source).forEach(key => {
12
12
  var dereferencedSource = source[key];
13
13
 
14
- if (target[key] === undefined || !(dereferencedSource instanceof Object)) {
14
+ if (target[key] === undefined || dereferencedSource instanceof Function || !(dereferencedSource instanceof Object)) {
15
15
  Object.defineProperty(target, key, {
16
16
  "enumerable": true,
17
17
  "writable": true,
@@ -0,0 +1,55 @@
1
+ type SimpleType = number | string | boolean | null | undefined;
2
+ type FuncWithSimpleParams<T extends SimpleType[], R> = (...args: T) => R;
3
+
4
+ export function memoize<T extends SimpleType[], R>(
5
+ fn: FuncWithSimpleParams<T, R>,
6
+ options?: {
7
+ argsLength?: number;
8
+ max?: number;
9
+ }
10
+ ): FuncWithSimpleParams<T, R> {
11
+ const cache = new Map<string, ReturnType<FuncWithSimpleParams<T, R>>>();
12
+
13
+ const { argsLength = fn.length, max = Infinity } = options ?? {};
14
+
15
+ return ((...args: Parameters<FuncWithSimpleParams<T, R>>) => {
16
+ const key = JSON.stringify(
17
+ args
18
+ .slice(0, argsLength)
19
+ .map(v => {
20
+ if (v === null) {
21
+ return "null";
22
+ }
23
+ if (v === undefined) {
24
+ return "undefined";
25
+ }
26
+ switch (typeof v) {
27
+ case "number":
28
+ return `number-${v}`;
29
+ case "string":
30
+ return `string-${v}`;
31
+ case "boolean":
32
+ return `boolean-${v ? "true" : "false"}`;
33
+ }
34
+ })
35
+ .join("-sIs9sAslOdeWlEdIos3-")
36
+ );
37
+
38
+ if (cache.has(key)) {
39
+ return cache.get(key);
40
+ }
41
+
42
+ if (max === cache.size) {
43
+ for (const key of cache.keys()) {
44
+ cache.delete(key);
45
+ break;
46
+ }
47
+ }
48
+
49
+ const value = fn(...args);
50
+
51
+ cache.set(key, value);
52
+
53
+ return value;
54
+ }) as any;
55
+ }
@@ -0,0 +1,45 @@
1
+ import { useRef, useState } from "react";
2
+ import { id } from "tsafe/id";
3
+ import { memoize } from "./memoize";
4
+
5
+ export type CallbackFactory<FactoryArgs extends unknown[], Args extends unknown[], R> = (...factoryArgs: FactoryArgs) => (...args: Args) => R;
6
+
7
+ /**
8
+ * https://docs.powerhooks.dev/api-reference/usecallbackfactory
9
+ *
10
+ * const callbackFactory= useCallbackFactory(
11
+ * ([key]: [string], [params]: [{ foo: number; }]) => {
12
+ * ...
13
+ * },
14
+ * []
15
+ * );
16
+ *
17
+ * WARNING: Factory args should not be of variable length.
18
+ *
19
+ */
20
+ export function useCallbackFactory<FactoryArgs extends (string | number | boolean)[], Args extends unknown[], R = void>(
21
+ callback: (...callbackArgs: [FactoryArgs, Args]) => R
22
+ ): CallbackFactory<FactoryArgs, Args, R> {
23
+ type Out = CallbackFactory<FactoryArgs, Args, R>;
24
+
25
+ const callbackRef = useRef<typeof callback>(callback);
26
+
27
+ callbackRef.current = callback;
28
+
29
+ const memoizedRef = useRef<Out | undefined>(undefined);
30
+
31
+ return useState(() =>
32
+ id<Out>((...factoryArgs) => {
33
+ if (memoizedRef.current === undefined) {
34
+ memoizedRef.current = memoize(
35
+ (...factoryArgs: FactoryArgs) =>
36
+ (...args: Args) =>
37
+ callbackRef.current(factoryArgs, args),
38
+ { "argsLength": factoryArgs.length }
39
+ );
40
+ }
41
+
42
+ return memoizedRef.current(...factoryArgs);
43
+ })
44
+ )[0];
45
+ }
@@ -0,0 +1,10 @@
1
+ import { useState } from "react";
2
+
3
+ /**
4
+ * Compute a value on first render and never again,
5
+ * Equivalent of const [x] = useState(()=> ...)
6
+ */
7
+ export function useConst<T>(getValue: () => T): T {
8
+ const [value] = useState(getValue);
9
+ return value;
10
+ }
@@ -0,0 +1,15 @@
1
+ import { useRef, useState } from "react";
2
+ import { Parameters } from "tsafe/Parameters";
3
+
4
+ /** https://stackoverflow.com/questions/65890278/why-cant-usecallback-always-return-the-same-ref */
5
+ export function useConstCallback<T extends ((...args: any[]) => unknown) | undefined | null>(callback: NonNullable<T>): T {
6
+ const callbackRef = useRef<typeof callback>(null as any);
7
+
8
+ callbackRef.current = callback;
9
+
10
+ return useState(
11
+ () =>
12
+ (...args: Parameters<T>) =>
13
+ callbackRef.current(...args)
14
+ )[0] as T;
15
+ }
@@ -1,8 +1,8 @@
1
1
  import "./tools/Array.prototype.every";
2
2
  import React, { useMemo, useReducer, Fragment } from "react";
3
3
  import type { KcContextBase, Validators, Attribute } from "./getKcContext/KcContextBase";
4
- import type { I18n, MessageKeyBase } from "./i18n";
5
- import { useConstCallback } from "powerhooks/useConstCallback";
4
+ import type { I18nBase, MessageKeyBase } from "./i18n";
5
+ import { useConstCallback } from "./tools/useConstCallback";
6
6
  import { id } from "tsafe/id";
7
7
  import { emailRegexp } from "./tools/emailRegExp";
8
8
 
@@ -14,7 +14,7 @@ export function useGetErrors(params: {
14
14
  attributes: { name: string; value?: string; validators: Validators }[];
15
15
  };
16
16
  };
17
- i18n: I18n;
17
+ i18n: I18nBase;
18
18
  }) {
19
19
  const { kcContext, i18n } = params;
20
20
 
@@ -319,7 +319,7 @@ export function useFormValidationSlice(params: {
319
319
  };
320
320
  /** NOTE: Try to avoid passing a new ref every render for better performances. */
321
321
  passwordValidators?: Validators;
322
- i18n: I18n;
322
+ i18n: I18nBase;
323
323
  }) {
324
324
  const {
325
325
  kcContext,
@@ -1 +0,0 @@
1
- import "minimal-polyfills/Object.fromEntries";
@@ -1,126 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __read = (this && this.__read) || function (o, n) {
26
- var m = typeof Symbol === "function" && o[Symbol.iterator];
27
- if (!m) return o;
28
- var i = m.call(o), r, ar = [], e;
29
- try {
30
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
31
- }
32
- catch (error) { e = { error: error }; }
33
- finally {
34
- try {
35
- if (r && !r.done && (m = i["return"])) m.call(i);
36
- }
37
- finally { if (e) throw e.error; }
38
- }
39
- return ar;
40
- };
41
- var __values = (this && this.__values) || function(o) {
42
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
43
- if (m) return m.call(o);
44
- if (o && typeof o.length === "number") return {
45
- next: function () {
46
- if (o && i >= o.length) o = void 0;
47
- return { value: o && o[i++], done: !o };
48
- }
49
- };
50
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
51
- };
52
- var e_1, _a;
53
- Object.defineProperty(exports, "__esModule", { value: true });
54
- require("minimal-polyfills/Object.fromEntries");
55
- var fs = __importStar(require("fs"));
56
- var path_1 = require("path");
57
- var crawl_1 = require("./tools/crawl");
58
- var download_builtin_keycloak_theme_1 = require("./download-builtin-keycloak-theme");
59
- var getProjectRoot_1 = require("./tools/getProjectRoot");
60
- var cliOptions_1 = require("./tools/cliOptions");
61
- var logger_1 = require("./tools/logger");
62
- //NOTE: To run without argument when we want to generate src/i18n/generated_kcMessages files,
63
- // update the version array for generating for newer version.
64
- //@ts-ignore
65
- var propertiesParser = require("properties-parser");
66
- var isSilent = (0, cliOptions_1.getCliOptions)(process.argv.slice(2)).isSilent;
67
- var logger = (0, logger_1.getLogger)({ isSilent: isSilent });
68
- var _loop_1 = function (keycloakVersion) {
69
- logger.log(JSON.stringify({ keycloakVersion: keycloakVersion }));
70
- var tmpDirPath = (0, path_1.join)((0, getProjectRoot_1.getProjectRoot)(), "tmp_xImOef9dOd44");
71
- fs.rmSync(tmpDirPath, { "recursive": true, "force": true });
72
- (0, download_builtin_keycloak_theme_1.downloadBuiltinKeycloakTheme)({
73
- keycloakVersion: keycloakVersion,
74
- "destDirPath": tmpDirPath,
75
- isSilent: isSilent
76
- });
77
- var record = {};
78
- {
79
- var baseThemeDirPath_1 = (0, path_1.join)(tmpDirPath, "base");
80
- (0, crawl_1.crawl)(baseThemeDirPath_1).forEach(function (filePath) {
81
- var _a;
82
- var match = filePath.match(/^([^/]+)\/messages\/messages_([^.]+)\.properties$/);
83
- if (match === null) {
84
- return;
85
- }
86
- var _b = __read(match, 3), typeOfPage = _b[1], language = _b[2];
87
- ((_a = record[typeOfPage]) !== null && _a !== void 0 ? _a : (record[typeOfPage] = {}))[language.replace(/_/g, "-")] = Object.fromEntries(Object.entries(propertiesParser.parse(fs.readFileSync((0, path_1.join)(baseThemeDirPath_1, filePath)).toString("utf8"))).map(function (_a) {
88
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
89
- return [key, value.replace(/''/g, "'")];
90
- }));
91
- });
92
- }
93
- fs.rmSync(tmpDirPath, { recursive: true, force: true });
94
- Object.keys(record).forEach(function (pageType) {
95
- var recordForPageType = record[pageType];
96
- Object.keys(recordForPageType).forEach(function (language) {
97
- var filePath = (0, path_1.join)((0, getProjectRoot_1.getProjectRoot)(), "src", "lib", "i18n", "generated_messages", keycloakVersion, pageType, "".concat(language, ".ts"));
98
- fs.mkdirSync((0, path_1.dirname)(filePath), { "recursive": true });
99
- fs.writeFileSync(filePath, Buffer.from([
100
- "//This code was automatically generated by running ".concat((0, path_1.relative)((0, getProjectRoot_1.getProjectRoot)(), __filename)),
101
- "//PLEASE DO NOT EDIT MANUALLY",
102
- "",
103
- "/* spell-checker: disable */",
104
- "const messages= ".concat(JSON.stringify(recordForPageType[language], null, 2), ";"),
105
- "",
106
- "export default messages;",
107
- "/* spell-checker: enable */"
108
- ].join("\n"), "utf8"));
109
- logger.log("".concat(filePath, " wrote"));
110
- });
111
- });
112
- };
113
- try {
114
- for (var _b = __values(["11.0.3", "15.0.2", "18.0.1"]), _c = _b.next(); !_c.done; _c = _b.next()) {
115
- var keycloakVersion = _c.value;
116
- _loop_1(keycloakVersion);
117
- }
118
- }
119
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
120
- finally {
121
- try {
122
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
123
- }
124
- finally { if (e_1) throw e_1.error; }
125
- }
126
- //# sourceMappingURL=generate-i18n-messages.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate-i18n-messages.js","sourceRoot":"","sources":["../src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