* web: fix esbuild issue with style sheets
Getting ESBuild, Lit, and Storybook to all agree on how to read and parse stylesheets is a serious
pain. This fix better identifies the value types (instances) being passed from various sources in
the repo to the three *different* kinds of style processors we're using (the native one, the
polyfill one, and whatever the heck Storybook does internally).
Falling back to using older CSS instantiating techniques one era at a time seems to do the trick.
It's ugly, but in the face of the aggressive styling we use to avoid Flashes of Unstyled Content
(FLoUC), it's the logic with which we're left.
In standard mode, the following warning appears on the console when running a Flow:
```
Autofocus processing was blocked because a document already has a focused element.
```
In compatibility mode, the following **error** appears on the console when running a Flow:
```
crawler-inject.js:1106 Uncaught TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'.
at initDomMutationObservers (crawler-inject.js:1106:18)
at crawler-inject.js:1114:24
at Array.forEach (<anonymous>)
at initDomMutationObservers (crawler-inject.js:1114:10)
at crawler-inject.js:1549:1
initDomMutationObservers @ crawler-inject.js:1106
(anonymous) @ crawler-inject.js:1114
initDomMutationObservers @ crawler-inject.js:1114
(anonymous) @ crawler-inject.js:1549
```
Despite this error, nothing seems to be broken and flows work as anticipated.
* web: clean up and remove redundant alias '@goauthentik/app'
The path alias `@goauthentik/app` has been a thorn in our side for a long time, as it conflicts with
or is redundant with all the *other* aliases in `tsconfig.json`, such as `@goauthentik/elements` and
`@goauthentik/locales`.
This commit *replaces* `@goauthentik/app` with `@goauthentik/authentik` for a single use case: the
locale codes file in the project root. That also helps reserve the subproject name `authentik` in
case we ever do go the monorepo root.
Other than that, all the rest have been removed with the following mechanical refactor:
```
perl -pi.bak -e 's{\@goauthentik/app/}{\@goauthentik/}' $(rg -l '@goauthentik/app/' ./src/)
```
* web: separate the sizing enum from a specific component implementation (#8890)
The PFSizes enum is used by more than just the Spinner, but has been left inside the Spinner for all
this time, making refactoring the Spinner for Patternfly 5 a little harder (okay, an annoying amount
harder) than it should be.
This commit moves this UI-specific, widely-use enum into its own folder in `common`, and refactors
everything else to use it. As is often the case, the refactor is mechanical:
```
perl -pi.bak -e 's{import \{ PFSize \} from "\@goauthentik/elements/Spinner";}{import \{ PFSize \}
from "\@goauthentik/common/enums.js";}' \\
$(rg -l 'import.*PFSize')
```
**Note:** This commit is dependent upon the ["clean up and remove redundant alias `@goauthentik/app`" PR](https://github.com/goauthentik/authentik/pull/8889)
97 lines
3.3 KiB
TypeScript
97 lines
3.3 KiB
TypeScript
import { first } from "@goauthentik/common/utils";
|
|
|
|
import { TemplateResult, html, nothing } from "lit";
|
|
import { classMap } from "lit/directives/class-map.js";
|
|
import { map } from "lit/directives/map.js";
|
|
|
|
export type DescriptionDesc = string | TemplateResult | undefined | typeof nothing;
|
|
export type DescriptionPair = [string, DescriptionDesc];
|
|
export type DescriptionRecord = { term: string; desc: DescriptionDesc };
|
|
|
|
interface DescriptionConfig {
|
|
horizontal?: boolean;
|
|
compact?: boolean;
|
|
twocolumn?: boolean;
|
|
threecolumn?: boolean;
|
|
}
|
|
|
|
const isDescriptionRecordCollection = (v: Array<unknown>): v is DescriptionRecord[] =>
|
|
v.length > 0 && typeof v[0] === "object" && !Array.isArray(v[0]);
|
|
|
|
function renderDescriptionGroup([term, description]: DescriptionPair) {
|
|
return html` <div class="pf-c-description-list__group">
|
|
<dt class="pf-c-description-list__term">
|
|
<span class="pf-c-description-list__text">${term}</span>
|
|
</dt>
|
|
<dd class="pf-c-description-list__description">
|
|
<div class="pf-c-description-list__text">${description ?? nothing}</div>
|
|
</dd>
|
|
</div>`;
|
|
}
|
|
|
|
function recordToPair({ term, desc }: DescriptionRecord): DescriptionPair {
|
|
return [term, desc];
|
|
}
|
|
|
|
function alignTermType(terms: DescriptionRecord[] | DescriptionPair[] = []) {
|
|
if (isDescriptionRecordCollection(terms)) {
|
|
return terms.map(recordToPair);
|
|
}
|
|
return terms ?? [];
|
|
}
|
|
|
|
/**
|
|
* renderDescriptionList
|
|
*
|
|
* This function renders the most common form of the PatternFly description list used in our code.
|
|
* It expects either an array of term/description pairs or an array of `{ term: string, description:
|
|
* string | TemplateResult }`.
|
|
*
|
|
* An optional dictionary of configuration options is available. These enable the Patternfly
|
|
* "horizontal," "compact", "2 column on large," or "3 column on large" layouts that are (so far)
|
|
* the layouts used in Authentik's (and Gravity's, for that matter) code.
|
|
*
|
|
* This is not a web component and it does not bring its own styling ; calling code will still have
|
|
* to provide the styling necessary. It is only a function to replace the repetitious boilerplate of
|
|
* routine description lists. Its output is a standard TemplateResult that will be fully realized
|
|
* within the context of the DOM or ShadowDOM in which it is called.
|
|
*/
|
|
|
|
const defaultConfig = {
|
|
horizontal: false,
|
|
compact: false,
|
|
twocolumn: false,
|
|
threecolumn: false,
|
|
};
|
|
|
|
export function renderDescriptionList(
|
|
terms: DescriptionRecord[],
|
|
config?: DescriptionConfig,
|
|
): TemplateResult;
|
|
|
|
export function renderDescriptionList(
|
|
terms: DescriptionPair[],
|
|
config?: DescriptionConfig,
|
|
): TemplateResult;
|
|
|
|
export function renderDescriptionList(
|
|
terms: DescriptionRecord[] | DescriptionPair[] = [],
|
|
config: DescriptionConfig = defaultConfig,
|
|
) {
|
|
const checkedTerms = alignTermType(terms);
|
|
const classes = classMap({
|
|
"pf-m-horizontal": first(config.horizontal, false),
|
|
"pf-m-compact": first(config.compact, false),
|
|
"pf-m-2-col-on-lg": first(config.twocolumn, false),
|
|
"pf-m-3-col-on-lg": first(config.threecolumn, false),
|
|
});
|
|
|
|
return html`
|
|
<dl class="pf-c-description-list ${classes}">
|
|
${map(checkedTerms, renderDescriptionGroup)}
|
|
</dl>
|
|
`;
|
|
}
|
|
|
|
export default renderDescriptionList;
|