Compare commits

...

13 Commits

8 changed files with 30 additions and 20 deletions

View File

@ -1,6 +1,6 @@
{
"name": "keycloakify",
"version": "11.3.12",
"version": "11.3.18",
"description": "Framework to create custom Keycloak UIs",
"repository": {
"type": "git",

View File

@ -51,7 +51,7 @@ export async function command(params: { buildContext: BuildContext }) {
2
)};`,
``,
`export type KcContext =`,
`type KcContext =`,
hasLoginTheme && ` | import("./login/KcContext").KcContext`,
hasAccountTheme && ` | import("./account/KcContext").KcContext`,
` ;`,

View File

@ -102,7 +102,7 @@ export declare namespace KcContext {
showTryAnotherWayLink?: boolean;
attemptedUsername?: string;
};
scripts: string[];
scripts?: string[];
message?: {
type: "success" | "warning" | "error" | "info";
summary: string;

View File

@ -10,7 +10,7 @@ export type KcContextLike = {
resourcesPath: string;
ssoLoginInOtherTabsUrl: string;
};
scripts: string[];
scripts?: string[];
};
assert<keyof KcContextLike extends keyof KcContext ? true : false>();
@ -45,10 +45,12 @@ export function useInitialize(params: {
type: "module",
src: `${url.resourcesPath}/js/menu-button-links.js`
},
...scripts.map(src => ({
type: "text/javascript" as const,
src
})),
...(scripts === undefined
? []
: scripts.map(src => ({
type: "text/javascript" as const,
src
}))),
{
type: "module",
textContent: `

View File

@ -16,6 +16,9 @@ import type { GenericI18n_noJsx } from "./GenericI18n_noJsx";
export type KcContextLike = {
themeName: string;
realm: {
internationalizationEnabled: boolean;
};
locale?: {
currentLanguageTag: string;
supported: { languageTag: string; url: string; label: string }[];
@ -91,14 +94,16 @@ export function createGetI18n<
return cachedResult;
}
const kcContextLocale = params.kcContext.realm.internationalizationEnabled ? params.kcContext.locale : undefined;
{
const currentLanguageTag = kcContext.locale?.currentLanguageTag ?? FALLBACK_LANGUAGE_TAG;
const currentLanguageTag = kcContextLocale?.currentLanguageTag ?? FALLBACK_LANGUAGE_TAG;
const html = document.querySelector("html");
assert(html !== null);
html.lang = currentLanguageTag;
const isRtl = (() => {
const { rtl } = kcContext.locale ?? {};
const { rtl } = kcContextLocale ?? {};
if (rtl !== undefined) {
return rtl;
@ -154,11 +159,11 @@ export function createGetI18n<
}
from_server: {
if (kcContext.locale === undefined) {
if (kcContextLocale === undefined) {
break from_server;
}
const supportedEntry = kcContext.locale.supported.find(entry => entry.languageTag === languageTag);
const supportedEntry = kcContextLocale.supported.find(entry => entry.languageTag === languageTag);
if (supportedEntry === undefined) {
break from_server;
@ -180,7 +185,7 @@ export function createGetI18n<
};
const currentLanguage: I18n["currentLanguage"] = (() => {
const languageTag = id<string>(kcContext.locale?.currentLanguageTag ?? FALLBACK_LANGUAGE_TAG) as LanguageTag;
const languageTag = id<string>(kcContextLocale?.currentLanguageTag ?? FALLBACK_LANGUAGE_TAG) as LanguageTag;
return {
languageTag,
@ -191,8 +196,8 @@ export function createGetI18n<
const enabledLanguages: I18n["enabledLanguages"] = (() => {
const enabledLanguages: I18n["enabledLanguages"] = [];
if (kcContext.locale !== undefined) {
for (const entry of kcContext.locale.supported ?? []) {
if (kcContextLocale !== undefined) {
for (const entry of kcContextLocale.supported ?? []) {
const languageTag = id<string>(entry.languageTag) as LanguageTag;
enabledLanguages.push({

View File

@ -70,9 +70,9 @@ export default function LoginRecoveryAuthnCodeConfig(props: PageProps<Extract<Kc
type="checkbox"
id="kcRecoveryCodesConfirmationCheck"
name="kcRecoveryCodesConfirmationCheck"
onChange={function () {
//@ts-expect-error: This is code from the original theme, we trust it.
document.getElementById("saveRecoveryAuthnCodesBtn").disabled = !this.checked;
onChange={event => {
//@ts-expect-error: This is inherited from the original code
document.getElementById("saveRecoveryAuthnCodesBtn").disabled = !event.target.checked;
}}
/>
<label htmlFor="kcRecoveryCodesConfirmationCheck">{msg("recovery-codes-confirmation-message")}</label>

View File

@ -16,6 +16,7 @@ import {
} from "../bin/shared/buildContext";
import MagicString from "magic-string";
import { command as updateKcGenCommand } from "../bin/update-kc-gen";
import { replaceAll } from "../bin/tools/String.prototype.replaceAll";
export namespace keycloakify {
export type Params = BuildOptions & {
@ -130,6 +131,8 @@ export function keycloakify(params: keycloakify.Params) {
await updateKcGenCommand({ buildContext });
},
transform: (code, id) => {
id = replaceAll(id, "/", pathSep);
assert(command !== undefined);
assert(shouldGenerateSourcemap !== undefined);

View File

@ -2,10 +2,10 @@ import React from "react";
import type { Meta, StoryObj } from "@storybook/react";
import { createKcPageStory } from "../KcPageStory";
const { KcPageStory } = createKcPageStory({ pageId: "login-oauth2-device-verify-user-code.ftl" });
const { KcPageStory } = createKcPageStory({ pageId: "login-device-verify-user-code.ftl" });
const meta = {
title: "login/login-oauth2-device-verify-user-code.ftl",
title: "login/login-device-verify-user-code.ftl",
component: KcPageStory
} satisfies Meta<typeof KcPageStory>;