diff --git a/apps/client/src/services/glob.ts b/apps/client/src/services/glob.ts index a1666b041..1b8a0e168 100644 --- a/apps/client/src/services/glob.ts +++ b/apps/client/src/services/glob.ts @@ -1,7 +1,6 @@ import utils from "./utils.js"; import appContext from "../components/app_context.js"; import server from "./server.js"; -import libraryLoader from "./library_loader.js"; import ws from "./ws.js"; import froca from "./froca.js"; import linkService from "./link.js"; @@ -17,7 +16,6 @@ function setupGlobs() { // required for ESLint plugin and CKEditor window.glob.getActiveContextNote = () => appContext.tabManager.getActiveContextNote(); - window.glob.requireLibrary = libraryLoader.requireLibrary; window.glob.appContext = appContext; // for debugging window.glob.froca = froca; window.glob.treeCache = froca; // compatibility for CKEditor builds for a while diff --git a/apps/client/src/services/library_loader.ts b/apps/client/src/services/library_loader.ts deleted file mode 100644 index e32003e7c..000000000 --- a/apps/client/src/services/library_loader.ts +++ /dev/null @@ -1,67 +0,0 @@ -export interface Library { - js?: string[] | (() => string[]); - css?: string[]; -} - -const KATEX: Library = { - js: ["node_modules/katex/dist/katex.min.js", "node_modules/katex/dist/contrib/mhchem.min.js", "node_modules/katex/dist/contrib/auto-render.min.js"], - css: ["node_modules/katex/dist/katex.min.css"] -}; - -async function requireLibrary(library: Library) { - if (library.css) { - library.css.map((cssUrl) => requireCss(cssUrl)); - } - - if (library.js) { - for (const scriptUrl of await unwrapValue(library.js)) { - await requireScript(scriptUrl); - } - } -} - -async function unwrapValue(value: T | (() => T) | Promise) { - if (value && typeof value === "object" && "then" in value) { - return (await (value as Promise<() => T>))(); - } - - if (typeof value === "function") { - return (value as () => T)(); - } - - return value; -} - -// we save the promises in case of the same script being required concurrently multiple times -const loadedScriptPromises: Record = {}; - -async function requireScript(url: string) { - url = `${window.glob.assetPath}/${url}`; - - if (!loadedScriptPromises[url]) { - loadedScriptPromises[url] = $.ajax({ - url: url, - dataType: "script", - cache: true - }); - } - - await loadedScriptPromises[url]; -} - -async function requireCss(url: string, prependAssetPath = true) { - const cssLinks = Array.from(document.querySelectorAll("link")).map((el) => el.href); - - if (!cssLinks.some((l) => l.endsWith(url))) { - if (prependAssetPath) { - url = `${window.glob.assetPath}/${url}`; - } - - $("head").append($('').attr("href", url)); - } -} - -export default { - requireCss, - requireLibrary -}; diff --git a/apps/client/src/types.d.ts b/apps/client/src/types.d.ts index c109b2f01..9970b99d3 100644 --- a/apps/client/src/types.d.ts +++ b/apps/client/src/types.d.ts @@ -22,7 +22,6 @@ interface CustomGlobals { getReferenceLinkTitle: (href: string) => Promise; getReferenceLinkTitleSync: (href: string) => string; getActiveContextNote: () => FNote | null; - requireLibrary: typeof library_loader.requireLibrary; ESLINT: Library; appContext: AppContext; froca: Froca; diff --git a/apps/client/src/widgets/type_widgets/editable_text.ts b/apps/client/src/widgets/type_widgets/editable_text.ts index c66c4ea02..a50b7a638 100644 --- a/apps/client/src/widgets/type_widgets/editable_text.ts +++ b/apps/client/src/widgets/type_widgets/editable_text.ts @@ -1,5 +1,4 @@ import { t } from "../../services/i18n.js"; -import libraryLoader from "../../services/library_loader.js"; import noteAutocompleteService, { type Suggestion } from "../../services/note_autocomplete.js"; import mimeTypesService from "../../services/mime_types.js"; import utils, { hasTouchBar } from "../../services/utils.js";