diff --git a/frontend/index.d.ts b/frontend/index.d.ts index a74ed0cd5e..90231e4355 100644 --- a/frontend/index.d.ts +++ b/frontend/index.d.ts @@ -1,3 +1,4 @@ declare module "*.svg"; declare module "*.webp"; +declare module "*.css"; declare module "regex-colorize"; diff --git a/frontend/package.json b/frontend/package.json index 91d6a42f67..1fb885a7a0 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -46,8 +46,11 @@ "lodash": "^4.17.21", "micromark": "^3.1.0", "node-fetch": "^3.1.0", + "patch-package": "^8.0.0", "postcss": "^8.4.5", + "postcss-lit": "^1.1.1", "postcss-loader": "^6.1.1", + "postinstall-postinstall": "^2.1.0", "prettier": "^2.4.1", "pretty-ms": "^7.0.1", "query-string": "^8.1.0", @@ -90,8 +93,6 @@ "@web/dev-server-rollup": "^0.3.21", "husky": "^8.0.3", "lint-staged": "^13.1.0", - "patch-package": "^8.0.0", - "postinstall-postinstall": "^2.1.0", "rollup-plugin-typescript-paths": "^1.4.0", "sinon": "^12.0.1", "ts-lit-plugin": "^2.0.1", diff --git a/frontend/postcss.config.js b/frontend/postcss.config.js index 116848f66a..c5339384f0 100644 --- a/frontend/postcss.config.js +++ b/frontend/postcss.config.js @@ -1,3 +1,4 @@ +/** @type {import('postcss-load-config').Config} */ module.exports = { plugins: [require("tailwindcss"), require("autoprefixer")], }; diff --git a/frontend/src/__mocks__/css.js b/frontend/src/__mocks__/css.js index f88ea095a5..38ac58d911 100644 --- a/frontend/src/__mocks__/css.js +++ b/frontend/src/__mocks__/css.js @@ -8,3 +8,4 @@ * }, * }, */ +export default ""; diff --git a/frontend/src/classes/TailwindElement.ts b/frontend/src/classes/TailwindElement.ts new file mode 100644 index 0000000000..3ca265665c --- /dev/null +++ b/frontend/src/classes/TailwindElement.ts @@ -0,0 +1,18 @@ +import { LitElement } from "lit"; +import { theme } from "@/theme"; + +export class TailwindElement extends LitElement { + connectedCallback(): void { + super.connectedCallback(); + // Insert the compiled Tailwind css into the shadow root. + // This has the benefit of not requiring a whole copy of compiled Tailwind + // for every TailwindElement, so we still get the benefits of atomic CSS. + // And because Tailwind uses `@layer`[^1], the order of declarations ends up + // correct, and you can use component styles with `static styles = ...`, + // *and* you can use Tailwind functions and directives in those styles + // thanks to `postcss-lit`. + // + // [^1]: (see https://tailwindcss.com/docs/adding-custom-styles#using-css-and-layer), + this.shadowRoot?.adoptedStyleSheets.push(theme); + } +} diff --git a/frontend/src/components/screencast.ts b/frontend/src/components/screencast.ts index 403241f3c5..a72dfd926f 100644 --- a/frontend/src/components/screencast.ts +++ b/frontend/src/components/screencast.ts @@ -42,6 +42,7 @@ export class Screencast extends LitElement { }/watch`; static maxRetries = 10; + // postcss-lit-disable-next-line static styles = css` .wrapper { position: relative; diff --git a/frontend/src/components/ui/alert.ts b/frontend/src/components/ui/alert.ts index ced051a82a..341a83fbbb 100644 --- a/frontend/src/components/ui/alert.ts +++ b/frontend/src/components/ui/alert.ts @@ -15,6 +15,7 @@ export class Alert extends LitElement { @property({ type: String }) variant: "success" | "warning" | "danger" | "info" = "info"; + // postcss-lit-disable-next-line static styles = css` :host > div { padding: var(--sl-spacing-x-small) var(--sl-spacing-small); diff --git a/frontend/src/components/ui/badge.ts b/frontend/src/components/ui/badge.ts index e4533fbbcb..f3b5831f85 100644 --- a/frontend/src/components/ui/badge.ts +++ b/frontend/src/components/ui/badge.ts @@ -14,6 +14,7 @@ export class Badge extends LitElement { @property({ type: String }) variant: "success" | "warning" | "danger" | "neutral" = "neutral"; + // postcss-lit-disable-next-line static styles = css` :host > span { display: inline-flex; diff --git a/frontend/src/components/ui/button.ts b/frontend/src/components/ui/button.ts index 67ee122087..890d2425c9 100644 --- a/frontend/src/components/ui/button.ts +++ b/frontend/src/components/ui/button.ts @@ -40,6 +40,7 @@ export class Button extends LitElement { @property({ type: Boolean }) icon: boolean = false; + // postcss-lit-disable-next-line static styles = css` :host { display: inline-block; diff --git a/frontend/src/components/ui/code.ts b/frontend/src/components/ui/code.ts index 07fc1d75f9..02aad91338 100644 --- a/frontend/src/components/ui/code.ts +++ b/frontend/src/components/ui/code.ts @@ -4,35 +4,26 @@ import { html as staticHtml, unsafeStatic } from "lit/static-html.js"; import hljs from "highlight.js/lib/core"; import javascript from "highlight.js/lib/languages/javascript"; import xml from "highlight.js/lib/languages/xml"; +import { TailwindElement } from "@/classes/TailwindElement"; /** * Syntax highlighting for javascript and HTML (XML) */ @customElement("btrix-code") -export class Code extends LitElement { - static styles = [ - css` - pre { - white-space: pre-wrap; - font-family: var(--sl-font-mono); - font-size: 0.9em; - color: #24292e; - margin: 0; - } +export class Code extends TailwindElement { + static styles = css` + .hljs-name { + color: #22863a; + } - .hljs-name { - color: #22863a; - } + .hljs-attr { + color: #6f42c1; + } - .hljs-attr { - color: #6f42c1; - } - - .hljs-string { - color: #032f62; - } - `, - ]; + .hljs-string { + color: #032f62; + } + `; @property({ type: String }) value: string = ""; @@ -50,8 +41,8 @@ export class Code extends LitElement { const htmlStr = hljs.highlight(this.value, { language: this.language, }).value; - return html`
${staticHtml`${unsafeStatic(
- htmlStr
- )}`}
`;
+ return html`${staticHtml`${unsafeStatic(htmlStr)}`}
`;
}
}
diff --git a/frontend/src/components/ui/copy-button.ts b/frontend/src/components/ui/copy-button.ts
index b99549105c..f09b41089a 100644
--- a/frontend/src/components/ui/copy-button.ts
+++ b/frontend/src/components/ui/copy-button.ts
@@ -31,6 +31,9 @@ export class CopyButton extends LitElement {
@property({ attribute: false })
getValue?: () => string | undefined;
+ @property({ type: Boolean })
+ hoist = false;
+
@state()
private isCopied: boolean = false;
@@ -53,6 +56,7 @@ export class CopyButton extends LitElement {
: this.content
? this.content
: msg("Copy")}
+ ?hoist=${this.hoist}
>
${msg("This collection can be viewed by anyone with the link.")}
-${this.crawl.id}
-