Fix legacy editable styles

This commit is contained in:
Abdo 2025-10-18 06:45:17 +03:00
parent a305665bf6
commit 33a1b32095
2 changed files with 41 additions and 32 deletions

View file

@ -42,6 +42,16 @@ if (!sourcemap) {
]; ];
} }
const ignoreCssUrlPlugin = {
name: "ignore-css-url",
setup(build) {
// This works around esbuild unconditionally resolving CSS imports that uses Vite's `?url` syntax in the editor
build.onResolve({ filter: /.*?\.scss\?url$/ }, (args) => {
return { path: args.path, external: true };
});
},
};
build({ build({
bundle: true, bundle: true,
entryPoints: [entrypoint], entryPoints: [entrypoint],
@ -51,6 +61,7 @@ build({
loader: { ".svg": "text" }, loader: { ".svg": "text" },
preserveSymlinks: true, preserveSymlinks: true,
sourcemap: sourcemap ? "inline" : false, sourcemap: sourcemap ? "inline" : false,
plugins: [ plugins: [
sassPlugin({ loadPaths: ["node_modules"] }), sassPlugin({ loadPaths: ["node_modules"] }),
sveltePlugin({ sveltePlugin({
@ -59,6 +70,7 @@ build({
// let us focus on errors; we can see the warnings with svelte-check // let us focus on errors; we can see the warnings with svelte-check
filterWarnings: (_warning) => false, filterWarnings: (_warning) => false,
}), }),
ignoreCssUrlPlugin,
], ],
target, target,
// logLevel: "info", // logLevel: "info",

View file

@ -7,9 +7,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import type { StyleLinkType, StyleObject } from "./CustomStyles.svelte"; import type { StyleLinkType, StyleObject } from "./CustomStyles.svelte";
import CustomStyles from "./CustomStyles.svelte"; import CustomStyles from "./CustomStyles.svelte";
import editableBaseCSS from "$lib/editable/editable-base.scss?url";
import contentEditableCSS from "$lib/editable/content-editable.scss?url";
import mathjaxCSS from "$lib/editable/mathjax.scss?url";
import { mount } from "svelte"; import { mount } from "svelte";
@ -49,6 +46,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
$: setStyling("fontSize", fontSize + "px"); $: setStyling("fontSize", fontSize + "px");
$: setStyling("direction", direction); $: setStyling("direction", direction);
async function attachToShadow(element: Element) {
let styles: StyleLinkType[]; let styles: StyleLinkType[];
if (isLegacy) { if (isLegacy) {
styles = [ styles = [
@ -63,22 +62,20 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
{ {
id: "editableBaseStyle", id: "editableBaseStyle",
type: "link", type: "link",
href: editableBaseCSS, href: (await import("$lib/editable/editable-base.scss?url")).default,
}, },
{ {
id: "contentEditableStyle", id: "contentEditableStyle",
type: "link", type: "link",
href: contentEditableCSS, href: (await import("$lib/editable/content-editable.scss?url")).default,
}, },
{ {
id: "mathjaxStyle", id: "mathjaxStyle",
type: "link", type: "link",
href: mathjaxCSS, href: (await import("$lib/editable/mathjax.scss?url")).default,
}, },
]; ];
} }
function attachToShadow(element: Element) {
const customStyles = mount(CustomStyles, { const customStyles = mount(CustomStyles, {
target: element.shadowRoot!, target: element.shadowRoot!,
props: { styles }, props: { styles },