Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions web/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
* @import { StorybookConfig } from "@storybook/web-components-vite";
*/

/**
* @param {TemplateStringsArray} strings
* @param {...any} values
* @returns {string}
*/
const html = (strings, ...values) => String.raw({ raw: strings }, ...values);

/**
* @satisfies {StorybookConfig}
*/
Expand All @@ -18,6 +25,27 @@ const config = {
"@storybook/addon-docs",
],
framework: "@storybook/web-components-vite",
viteFinal: async (config) => {
return {
...config,
define: {
...config.define,
"import.meta.env.AK_BUNDLER": JSON.stringify("storybook"),
},
resolve: {
...config.resolve,
// Avoid multiple instances of web components packages.
conditions: [],
},
};
},

previewBody: (body) => html`
<ak-skip-to-content></ak-skip-to-content>
<ak-message-container></ak-message-container>

${body}
`,
};

export default config;
1 change: 1 addition & 0 deletions web/.storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import "#styles/authentik/interface.global.css";
import "#styles/authentik/static.global.css";
import "#styles/authentik/storybook.css";

import { ThemedDocsContainer } from "./DocsContainer.tsx";
Expand Down
1 change: 1 addition & 0 deletions web/bundler/utils/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export function createBundleDefinitions() {
AK_DOCS_RELEASE_NOTES_URL: ReleaseNotesURL.href,
AK_DOCS_PRE_RELEASE_URL: PreReleaseDocsURL.href,
AK_API_BASE_PATH: process.env.AK_API_BASE_PATH ?? "",
AK_BUNDLER: JSON.stringify(process.env.AK_BUNDLER ?? "authentik"),
};

return {
Expand Down
170 changes: 163 additions & 7 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
"remark-frontmatter": "^5.0.0",
"remark-gfm": "^4.0.1",
"remark-mdx-frontmatter": "^5.2.0",
"storybook": "^10.0.8",
"storybook": "^10.2.1",
"style-mod": "^4.1.3",
"trusted-types": "^2.0.0",
"ts-pattern": "^5.9.0",
Expand Down
5 changes: 3 additions & 2 deletions web/src/common/api/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ export class LoggingMiddleware implements Middleware {

constructor(brand: CurrentBrand) {
const prefix =
brand.matchedDomain === "authentik-default" ? "api" : `api/${brand.matchedDomain}`;

brand.matchedDomain && brand.matchedDomain !== "authentik-default"
? `api/${brand.matchedDomain}`
: "api";
this.#logger = ConsoleLogger.prefix(prefix);
}

Expand Down
15 changes: 12 additions & 3 deletions web/src/common/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,29 +321,38 @@ function pluckCurrentBackgroundURL(
return null;
}

export interface BackgroundImageInit {
baseOrigin?: string;
target?: HTMLElement | null;
}

/**
* Applies the given background image URL to the document body.
*
* This method is very defensive to avoid unnecessary DOM repaints.
*/
export function applyBackgroundImageProperty(
value?: string | null,
baseOrigin = window.location.origin,
init?: BackgroundImageInit,
): void {
const baseOrigin = init?.baseOrigin ?? window.location.origin;

if (!value || !URL.canParse(value, baseOrigin)) {
return;
}

const target = init?.target ?? document.body;

const nextURL = new URL(value, baseOrigin);

const { backgroundImage } = getComputedStyle(document.body, "::before");
const { backgroundImage } = getComputedStyle(target, "::before");

const currentURL = pluckCurrentBackgroundURL(backgroundImage, baseOrigin);
if (currentURL?.href === nextURL.href) {
return;
}

document.body.style.setProperty(AKBackgroundImageProperty, `url("${nextURL.href}")`);
target.style.setProperty(AKBackgroundImageProperty, `url("${nextURL.href}")`);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions web/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
* @file Common utility types.
*/

/**
* Type utility to make all properties in T recursively optional.
*/
export type DeepPartial<T> = T extends object
? {
[P in keyof T]?: DeepPartial<T[P]>;
}
: T;

/**
* Type utility to make readonly properties mutable.
*/
Expand Down
Loading
Loading