Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor(client): remove library loader entirely
Elian Doran8a1f05cd2629
diff --git a/apps/client/src/services/glob.ts b/apps/client/src/services/glob.tsindex a1666b0410..1b8a0e168a 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 CKEditorwindow.glob.getActiveContextNote = () => appContext.tabManager.getActiveContextNote();- window.glob.requireLibrary = libraryLoader.requireLibrary;window.glob.appContext = appContext; // for debuggingwindow.glob.froca = froca;window.glob.treeCache = froca; // compatibility for CKEditor builds for a whilediff --git a/apps/client/src/services/library_loader.ts b/apps/client/src/services/library_loader.tsdeleted file mode 100644index e32003e7c4..0000000000--- 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<T>(value: T | (() => T) | Promise<T>) {- 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<string, JQuery.jqXHR> = {};--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($('<link rel="stylesheet" type="text/css" />').attr("href", url));- }-}--export default {- requireCss,- requireLibrary-};diff --git a/apps/client/src/types.d.ts b/apps/client/src/types.d.tsindex c109b2f019..9970b99d3c 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<string>;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.tsindex c66c4ea02a..a50b7a6386 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";