Skip to content

Build your personal knowledge base with Trilium Notes

client/canvas: fix sidebar buttons

Adorian Dorane175516dcdf9
diff --git a/apps/client/vite-plugins.mts b/apps/client/vite-plugins.mts
index 0f5450adf1..dceabbc390 100644
--- a/apps/client/vite-plugins.mts
+++ b/apps/client/vite-plugins.mts
@@ -162,7 +162,7 @@ interface SelectorRewrite {
}
/**
- * Bootstrap's minified selectors, the same in its LTR and RTL builds. Trilium uses no `<legend>`,
+ * Bootstrap's minified selectors, the same in its LTR and RTL builds. Trilium uses no
* `.table-striped-columns` or `.has-validation`; floating labels need `.form-control` or
* `.form-select` on the field.
*/
@@ -224,12 +224,12 @@ export const THIRD_PARTY_STYLESHEETS = [
{
specifier: "bootstrap/dist/css/bootstrap.min.css",
file: "bootstrap/dist/css/bootstrap.min.css",
- rewrites: [ { from: "legend+*{clear:left}", to: "", count: 1 }, ...BOOTSTRAP_REWRITES ]
+ rewrites: [ clearAfterLegend("left"), ...BOOTSTRAP_REWRITES ]
},
{
specifier: "bootstrap/dist/css/bootstrap.rtl.min.css",
file: "bootstrap/dist/css/bootstrap.rtl.min.css",
- rewrites: [ { from: "legend+*{clear:right}", to: "", count: 1 }, ...BOOTSTRAP_REWRITES ]
+ rewrites: [ clearAfterLegend("right"), ...BOOTSTRAP_REWRITES ]
},
{
specifier: "ckeditor5/ckeditor5.css",
@@ -238,6 +238,18 @@ export const THIRD_PARTY_STYLESHEETS = [
}
];
+/**
+ * Bootstrap floats a `<legend>` to `side` and clears the element after it. Excalidraw's panels
+ * put each legend first in its `<fieldset>`, so the rewrite clears the other children instead.
+ */
+function clearAfterLegend(side: "left" | "right"): SelectorRewrite {
+ return {
+ from: `legend+*{clear:${side}}`,
+ to: `fieldset>:not(legend){clear:${side}}`,
+ count: 1
+ };
+}
+
/** The share theme's sources, which the app build bundles into the files shared pages load. */
const SHARE_THEME_SRC = join(import.meta.dirname, "../../packages/share-theme/src");
diff --git a/apps/client/vite-plugins.spec.ts b/apps/client/vite-plugins.spec.ts
index 81855fde8c..d951dd9152 100644
--- a/apps/client/vite-plugins.spec.ts
+++ b/apps/client/vite-plugins.spec.ts
@@ -340,6 +340,18 @@ describe("narrowThirdPartySelectors", () => {
}
});
+ it("clears the float of a `<legend>` on the side Bootstrap floats it", () => {
+ for (const { specifier } of THIRD_PARTY_STYLESHEETS.slice(0, 2)) {
+ const path = createRequire(import.meta.url).resolve(specifier);
+ const narrowed = narrowSelectorsSource(readFileSync(path, "utf8"), path) ?? "";
+
+ const side = narrowed.match(/\blegend\{float:(left|right);/)?.[1];
+ expect(side, specifier).toBeDefined();
+ expect(narrowed.match(/[^{}]*\{clear:(?:left|right)\}/g), specifier)
+ .toEqual([ `fieldset>:not(legend){clear:${side}}` ]);
+ }
+ });
+
it("leaves other modules alone and fails once a selector no longer matches", () => {
const other = "/app/node_modules/other/dist/a.css";
const ckeditor = "/app/node_modules/ckeditor5/dist/ckeditor5.css?direct";