Skip to content

Commit ab587c6

Browse files
committed
web: Captcha Refinements, Part 2 (#19757)
* Move inline styles into separate file. * Fix preferred order of captcha vendor discovery. * Clean up mutation and resize observer lifecycle. * Flesh out controllers. * Tidy refresh. * Fix incompatibilities with Storybook. * Flesh out captcha stories. * Bump package. * Flesh out stories. * Move inline styles into separate file. * Fix preferred order of captcha vendor discovery. * Clean up mutation and resize observer lifecycle. * Flesh out controllers. * Tidy refresh. * Remove unused. * Bump package. (cherry picked from commit 388f426)
1 parent 4ef3573 commit ab587c6

43 files changed

Lines changed: 1340 additions & 955 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

web/.storybook/main.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
* @import { StorybookConfig } from "@storybook/web-components-vite";
44
*/
55

6+
/**
7+
* @param {TemplateStringsArray} strings
8+
* @param {...any} values
9+
* @returns {string}
10+
*/
11+
const html = (strings, ...values) => String.raw({ raw: strings }, ...values);
12+
613
/**
714
* @satisfies {StorybookConfig}
815
*/
@@ -18,6 +25,27 @@ const config = {
1825
"@storybook/addon-docs",
1926
],
2027
framework: "@storybook/web-components-vite",
28+
viteFinal: async (config) => {
29+
return {
30+
...config,
31+
define: {
32+
...config.define,
33+
"import.meta.env.AK_BUNDLER": JSON.stringify("storybook"),
34+
},
35+
resolve: {
36+
...config.resolve,
37+
// Avoid multiple instances of web components packages.
38+
conditions: [],
39+
},
40+
};
41+
},
42+
43+
previewBody: (body) => html`
44+
<ak-skip-to-content></ak-skip-to-content>
45+
<ak-message-container></ak-message-container>
46+
47+
${body}
48+
`,
2149
};
2250

2351
export default config;

web/.storybook/preview.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
import "#styles/authentik/interface.global.css";
8+
import "#styles/authentik/static.global.css";
89
import "#styles/authentik/storybook.css";
910

1011
import { ThemedDocsContainer } from "./DocsContainer.tsx";

web/bundler/utils/node.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export function createBundleDefinitions() {
2727
AK_DOCS_RELEASE_NOTES_URL: ReleaseNotesURL.href,
2828
AK_DOCS_PRE_RELEASE_URL: PreReleaseDocsURL.href,
2929
AK_API_BASE_PATH: process.env.AK_API_BASE_PATH ?? "",
30+
AK_BUNDLER: JSON.stringify(process.env.AK_BUNDLER ?? "authentik"),
3031
};
3132

3233
return {

web/package-lock.json

Lines changed: 163 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@
176176
"remark-frontmatter": "^5.0.0",
177177
"remark-gfm": "^4.0.1",
178178
"remark-mdx-frontmatter": "^5.2.0",
179-
"storybook": "^10.0.8",
179+
"storybook": "^10.2.1",
180180
"style-mod": "^4.1.3",
181181
"trusted-types": "^2.0.0",
182182
"ts-pattern": "^5.9.0",

web/src/common/api/middleware.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ export class LoggingMiddleware implements Middleware {
2222

2323
constructor(brand: CurrentBrand) {
2424
const prefix =
25-
brand.matchedDomain === "authentik-default" ? "api" : `api/${brand.matchedDomain}`;
26-
25+
brand.matchedDomain && brand.matchedDomain !== "authentik-default"
26+
? `api/${brand.matchedDomain}`
27+
: "api";
2728
this.#logger = ConsoleLogger.prefix(prefix);
2829
}
2930

web/src/common/theme.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,29 +321,38 @@ function pluckCurrentBackgroundURL(
321321
return null;
322322
}
323323

324+
export interface BackgroundImageInit {
325+
baseOrigin?: string;
326+
target?: HTMLElement | null;
327+
}
328+
324329
/**
325330
* Applies the given background image URL to the document body.
326331
*
327332
* This method is very defensive to avoid unnecessary DOM repaints.
328333
*/
329334
export function applyBackgroundImageProperty(
330335
value?: string | null,
331-
baseOrigin = window.location.origin,
336+
init?: BackgroundImageInit,
332337
): void {
338+
const baseOrigin = init?.baseOrigin ?? window.location.origin;
339+
333340
if (!value || !URL.canParse(value, baseOrigin)) {
334341
return;
335342
}
336343

344+
const target = init?.target ?? document.body;
345+
337346
const nextURL = new URL(value, baseOrigin);
338347

339-
const { backgroundImage } = getComputedStyle(document.body, "::before");
348+
const { backgroundImage } = getComputedStyle(target, "::before");
340349

341350
const currentURL = pluckCurrentBackgroundURL(backgroundImage, baseOrigin);
342351
if (currentURL?.href === nextURL.href) {
343352
return;
344353
}
345354

346-
document.body.style.setProperty(AKBackgroundImageProperty, `url("${nextURL.href}")`);
355+
target.style.setProperty(AKBackgroundImageProperty, `url("${nextURL.href}")`);
347356
}
348357

349358
/**

web/src/common/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
* @file Common utility types.
33
*/
44

5+
/**
6+
* Type utility to make all properties in T recursively optional.
7+
*/
8+
export type DeepPartial<T> = T extends object
9+
? {
10+
[P in keyof T]?: DeepPartial<T[P]>;
11+
}
12+
: T;
13+
514
/**
615
* Type utility to make readonly properties mutable.
716
*/

0 commit comments

Comments
 (0)