Skip to content

Build your personal knowledge base with Trilium Notes

refactor(server): remove dependency on codemirror project

Elian Doranac49c0f59b51
diff --git a/apps/client/src/widgets/type_widgets/options/code_notes/code_theme.ts b/apps/client/src/widgets/type_widgets/options/code_notes/code_theme.ts
index f56aff682e..52818e11b4 100644
--- a/apps/client/src/widgets/type_widgets/options/code_notes/code_theme.ts
+++ b/apps/client/src/widgets/type_widgets/options/code_notes/code_theme.ts
@@ -4,6 +4,7 @@ import server from "../../../../services/server";
import CodeMirror, { getThemeById } from "@triliumnext/codemirror";
import { DEFAULT_PREFIX } from "../../abstract_code_type_widget";
import { t } from "../../../../services/i18n";
+import { ColorThemes } from "@triliumnext/codemirror";
// TODO: Deduplicate
interface Theme {
@@ -129,6 +130,15 @@ export default class CodeTheme extends OptionsWidget {
const newTheme = String(this.$themeSelect.val());
await server.put(`options/codeNoteTheme/${newTheme}`);
});
+
+ // Populate the list of themes.
+ for (const theme of ColorThemes) {
+ const option = $("<option>")
+ .attr("value", `default:${theme.id}`)
+ .text(theme.name);
+ this.$themeSelect.append(option);
+ }
+
this.$sampleEl = this.$widget.find(".note-detail-readonly-code-content");
this.$lineWrapEnabled = this.$widget.find(".word-wrap");
this.$lineWrapEnabled.on("change", () => this.updateCheckboxOption("codeLineWrapEnabled", this.$lineWrapEnabled));
@@ -155,14 +165,6 @@ export default class CodeTheme extends OptionsWidget {
}
async optionsLoaded(options: OptionMap) {
- const themes = await server.get<Response>("options/codenote-themes");
- this.$themeSelect.empty();
-
- for (const theme of themes) {
- const option = $("<option>").attr("value", theme.val).text(theme.title);
- this.$themeSelect.append(option);
- }
-
this.$themeSelect.val(options.codeNoteTheme);
this.#setupPreview(options);
this.setCheckboxState(this.$lineWrapEnabled, options.codeLineWrapEnabled);
diff --git a/apps/server/src/routes/api/options.ts b/apps/server/src/routes/api/options.ts
index 8cf88502f9..4b7ce655d4 100644
--- a/apps/server/src/routes/api/options.ts
+++ b/apps/server/src/routes/api/options.ts
@@ -8,7 +8,6 @@ import type { Request } from "express";
import { changeLanguage, getLocales } from "../../services/i18n.js";
import { listSyntaxHighlightingThemes } from "../../services/code_block_theme.js";
import type { OptionNames } from "@triliumnext/commons";
-import { ColorThemes } from "@triliumnext/codemirror";
// options allowed to be updated directly in the Options dialog
const ALLOWED_OPTIONS = new Set<OptionNames>([
@@ -195,13 +194,6 @@ function getSyntaxHighlightingThemes() {
return listSyntaxHighlightingThemes();
}
-function getCodeNoteThemes() {
- return ColorThemes.map((theme) => ({
- val: `default:${theme.id}`,
- title: theme.name
- }));
-}
-
function getSupportedLocales() {
return getLocales();
}
@@ -219,6 +211,5 @@ export default {
updateOptions,
getUserThemes,
getSyntaxHighlightingThemes,
- getCodeNoteThemes,
getSupportedLocales
};
diff --git a/apps/server/src/routes/routes.ts b/apps/server/src/routes/routes.ts
index 4cab8d9436..2707c3cd8f 100644
--- a/apps/server/src/routes/routes.ts
+++ b/apps/server/src/routes/routes.ts
@@ -245,7 +245,6 @@ function register(app: express.Application) {
apiRoute(PUT, "/api/options", optionsApiRoute.updateOptions);
apiRoute(GET, "/api/options/user-themes", optionsApiRoute.getUserThemes);
apiRoute(GET, "/api/options/codeblock-themes", optionsApiRoute.getSyntaxHighlightingThemes);
- apiRoute(GET, "/api/options/codenote-themes", optionsApiRoute.getCodeNoteThemes)
apiRoute(GET, "/api/options/locales", optionsApiRoute.getSupportedLocales);
apiRoute(PST, "/api/password/change", passwordApiRoute.changePassword);
diff --git a/apps/server/tsconfig.app.json b/apps/server/tsconfig.app.json
index d95d85b207..591b4a5dbc 100644
--- a/apps/server/tsconfig.app.json
+++ b/apps/server/tsconfig.app.json
@@ -36,9 +36,6 @@
{
"path": "../../packages/ckeditor5/tsconfig.lib.json"
},
- {
- "path": "../../packages/codemirror/tsconfig.lib.json"
- },
{
"path": "../../packages/turndown-plugin-gfm/tsconfig.lib.json"
},
diff --git a/apps/server/tsconfig.json b/apps/server/tsconfig.json
index 6b70171002..6bc2242953 100644
--- a/apps/server/tsconfig.json
+++ b/apps/server/tsconfig.json
@@ -6,9 +6,6 @@
{
"path": "../../packages/ckeditor5"
},
- {
- "path": "../../packages/codemirror"
- },
{
"path": "../../packages/turndown-plugin-gfm"
},