Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit a0a5a2c

Browse files
authored
Merge pull request #1956 from TriliumNext/client_vite
Port client to Vite
2 parents 8f3d98b + e573fd7 commit a0a5a2c

43 files changed

Lines changed: 393 additions & 891 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/client/package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@
2222
"@mind-elixir/node-menu": "1.0.5",
2323
"@popperjs/core": "2.11.8",
2424
"@triliumnext/ckeditor5": "workspace:*",
25-
"@triliumnext/commons": "workspace:*",
2625
"@triliumnext/codemirror": "workspace:*",
26+
"@triliumnext/commons": "workspace:*",
27+
"@triliumnext/highlightjs": "workspace:*",
28+
"autocomplete.js": "0.38.1",
2729
"bootstrap": "5.3.6",
30+
"boxicons": "2.1.4",
2831
"dayjs": "1.11.13",
2932
"dayjs-plugin-utc": "0.1.2",
3033
"debounce": "2.2.0",
@@ -37,13 +40,15 @@
3740
"jquery-hotkeys": "0.2.2",
3841
"jquery.fancytree": "2.38.5",
3942
"jsplumb": "2.15.6",
43+
"katex": "0.16.22",
4044
"knockout": "3.5.1",
4145
"leaflet": "1.9.4",
4246
"leaflet-gpx": "2.2.0",
4347
"mark.js": "8.11.1",
4448
"marked": "15.0.12",
4549
"mermaid": "11.6.0",
4650
"mind-elixir": "4.5.2",
51+
"normalize.css": "8.0.1",
4752
"panzoom": "9.4.3",
4853
"react": "19.1.0",
4954
"react-dom": "19.1.0",
@@ -57,11 +62,13 @@
5762
"@types/jquery": "3.5.32",
5863
"@types/leaflet": "1.9.18",
5964
"@types/leaflet-gpx": "1.3.7",
65+
"@types/mark.js": "8.11.12",
6066
"@types/react": "19.1.4",
6167
"@types/react-dom": "19.1.5",
6268
"copy-webpack-plugin": "13.0.0",
6369
"happy-dom": "17.4.7",
64-
"script-loader": "0.7.2"
70+
"script-loader": "0.7.2",
71+
"vite-plugin-static-copy": "3.0.0"
6572
},
6673
"nx": {
6774
"name": "client"

apps/client/src/desktop.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import options from "./services/options.js";
1111
import type ElectronRemote from "@electron/remote";
1212
import type Electron from "electron";
1313
import "./stylesheets/bootstrap.scss";
14+
import "boxicons/css/boxicons.min.css";
15+
import "jquery-hotkeys";
16+
import "autocomplete.js/index_jquery.js";
1417

1518
await appContext.earlyInit();
1619

apps/client/src/mobile.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import appContext from "./components/app_context.js";
22
import noteAutocompleteService from "./services/note_autocomplete.js";
33
import glob from "./services/glob.js";
44
import "./stylesheets/bootstrap.scss";
5+
import "boxicons/css/boxicons.min.css";
6+
import "autocomplete.js/index_jquery.js";
57

68
glob.setupGlobs();
79

apps/client/src/runtime.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import $ from "jquery";
2+
(window as any).$ = $;
3+
(window as any).jQuery = $;
4+
5+
$("body").show();

apps/client/src/services/content_renderer.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import renderService from "./render.js";
22
import protectedSessionService from "./protected_session.js";
33
import protectedSessionHolder from "./protected_session_holder.js";
4-
import libraryLoader from "./library_loader.js";
54
import openService from "./open.js";
65
import froca from "./froca.js";
76
import utils from "./utils.js";
@@ -15,6 +14,7 @@ import { loadElkIfNeeded, postprocessMermaidSvg } from "./mermaid.js";
1514
import renderDoc from "./doc_renderer.js";
1615
import { t } from "../services/i18n.js";
1716
import WheelZoom from 'vanilla-js-wheel-zoom';
17+
import { renderMathInElement } from "./math.js";
1818
import { normalizeMimeTypeForCKEditor } from "@triliumnext/commons";
1919

2020
let idCounter = 1;
@@ -94,8 +94,6 @@ async function renderText(note: FNote | FAttachment, $renderedContent: JQuery<HT
9494
$renderedContent.append($('<div class="ck-content">').html(blob.content));
9595

9696
if ($renderedContent.find("span.math-tex").length > 0) {
97-
await libraryLoader.requireLibrary(libraryLoader.KATEX);
98-
9997
renderMathInElement($renderedContent[0], { trust: true });
10098
}
10199

apps/client/src/services/doc_renderer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@ function getUrl(docNameValue: string, language: string) {
4848
// Cannot have spaces in the URL due to how JQuery.load works.
4949
docNameValue = docNameValue.replaceAll(" ", "%20");
5050

51-
return `${window.glob.appPath}/doc_notes/${language}/${docNameValue}.html`;
51+
const basePath = window.glob.isDev ? new URL(window.glob.assetPath).pathname : window.glob.assetPath;
52+
return `${basePath}/doc_notes/${language}/${docNameValue}.html`;
5253
}

apps/client/src/services/glob.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import utils from "./utils.js";
22
import appContext from "../components/app_context.js";
33
import server from "./server.js";
4-
import libraryLoader from "./library_loader.js";
54
import ws from "./ws.js";
65
import froca from "./froca.js";
76
import linkService from "./link.js";
@@ -17,7 +16,6 @@ function setupGlobs() {
1716

1817
// required for ESLint plugin and CKEditor
1918
window.glob.getActiveContextNote = () => appContext.tabManager.getActiveContextNote();
20-
window.glob.requireLibrary = libraryLoader.requireLibrary;
2119
window.glob.appContext = appContext; // for debugging
2220
window.glob.froca = froca;
2321
window.glob.treeCache = froca; // compatibility for CKEditor builds for a while
@@ -64,7 +62,7 @@ function setupGlobs() {
6462
});
6563

6664
for (const appCssNoteId of glob.appCssNoteIds || []) {
67-
libraryLoader.requireCss(`api/notes/download/${appCssNoteId}`, false);
65+
requireCss(`api/notes/download/${appCssNoteId}`, false);
6866
}
6967

7068
utils.initHelpButtons($(window));
@@ -76,6 +74,18 @@ function setupGlobs() {
7674
});
7775
}
7876

77+
async function requireCss(url: string, prependAssetPath = true) {
78+
const cssLinks = Array.from(document.querySelectorAll("link")).map((el) => el.href);
79+
80+
if (!cssLinks.some((l) => l.endsWith(url))) {
81+
if (prependAssetPath) {
82+
url = `${window.glob.assetPath}/${url}`;
83+
}
84+
85+
$("head").append($('<link rel="stylesheet" type="text/css" />').attr("href", url));
86+
}
87+
}
88+
7989
export default {
8090
setupGlobs
8191
};

apps/client/src/services/library_loader.ts

Lines changed: 0 additions & 68 deletions
This file was deleted.

apps/client/src/services/math.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import katex from "katex";
2+
import "katex/contrib/mhchem";
3+
import "katex/dist/katex.min.css";
4+
export { default as renderMathInElement } from "katex/contrib/auto-render";
5+
export default katex;

apps/client/src/setup.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import "jquery";
2+
import "jquery-hotkeys";
13
import utils from "./services/utils.js";
24
import ko from "knockout";
35
import "./stylesheets/bootstrap.scss";

0 commit comments

Comments
 (0)