feat(server): add endpoint to list code note themes

This commit is contained in:
Elian Doran 2025-05-11 20:40:22 +03:00
parent 7475e94c53
commit ca467fcd7a
No known key found for this signature in database
6 changed files with 20 additions and 4 deletions

View File

@ -8,6 +8,7 @@ import type { Request } from "express";
import { changeLanguage, getLocales } from "../../services/i18n.js"; import { changeLanguage, getLocales } from "../../services/i18n.js";
import { listSyntaxHighlightingThemes } from "../../services/code_block_theme.js"; import { listSyntaxHighlightingThemes } from "../../services/code_block_theme.js";
import type { OptionNames } from "@triliumnext/commons"; import type { OptionNames } from "@triliumnext/commons";
import { ColorThemes } from "@triliumnext/codemirror";
// options allowed to be updated directly in the Options dialog // options allowed to be updated directly in the Options dialog
const ALLOWED_OPTIONS = new Set<OptionNames>([ const ALLOWED_OPTIONS = new Set<OptionNames>([
@ -193,6 +194,13 @@ function getSyntaxHighlightingThemes() {
return listSyntaxHighlightingThemes(); return listSyntaxHighlightingThemes();
} }
function getCodeNoteThemes() {
return ColorThemes.map((theme) => ({
val: theme.id,
title: theme.id
}));
}
function getSupportedLocales() { function getSupportedLocales() {
return getLocales(); return getLocales();
} }
@ -210,5 +218,6 @@ export default {
updateOptions, updateOptions,
getUserThemes, getUserThemes,
getSyntaxHighlightingThemes, getSyntaxHighlightingThemes,
getCodeNoteThemes,
getSupportedLocales getSupportedLocales
}; };

View File

@ -245,6 +245,7 @@ function register(app: express.Application) {
apiRoute(PUT, "/api/options", optionsApiRoute.updateOptions); apiRoute(PUT, "/api/options", optionsApiRoute.updateOptions);
apiRoute(GET, "/api/options/user-themes", optionsApiRoute.getUserThemes); apiRoute(GET, "/api/options/user-themes", optionsApiRoute.getUserThemes);
apiRoute(GET, "/api/options/codeblock-themes", optionsApiRoute.getSyntaxHighlightingThemes); apiRoute(GET, "/api/options/codeblock-themes", optionsApiRoute.getSyntaxHighlightingThemes);
apiRoute(GET, "/api/options/codenote-themes", optionsApiRoute.getCodeNoteThemes)
apiRoute(GET, "/api/options/locales", optionsApiRoute.getSupportedLocales); apiRoute(GET, "/api/options/locales", optionsApiRoute.getSupportedLocales);
apiRoute(PST, "/api/password/change", passwordApiRoute.changePassword); apiRoute(PST, "/api/password/change", passwordApiRoute.changePassword);

View File

@ -36,6 +36,9 @@
{ {
"path": "../../packages/ckeditor5/tsconfig.lib.json" "path": "../../packages/ckeditor5/tsconfig.lib.json"
}, },
{
"path": "../../packages/codemirror/tsconfig.lib.json"
},
{ {
"path": "../../packages/turndown-plugin-gfm/tsconfig.lib.json" "path": "../../packages/turndown-plugin-gfm/tsconfig.lib.json"
}, },

View File

@ -6,6 +6,9 @@
{ {
"path": "../../packages/ckeditor5" "path": "../../packages/ckeditor5"
}, },
{
"path": "../../packages/codemirror"
},
{ {
"path": "../../packages/turndown-plugin-gfm" "path": "../../packages/turndown-plugin-gfm"
}, },

View File

@ -1,17 +1,17 @@
import type { Extension } from '@codemirror/state'; import type { Extension } from '@codemirror/state';
export interface ThemeDefinition { export interface ThemeDefinition {
name: string; id: string;
load(): Promise<Extension>; load(): Promise<Extension>;
} }
const themes: ThemeDefinition[] = [ const themes: ThemeDefinition[] = [
{ {
name: "abyss", id: "abyss",
load: async () => (await import("@fsegurai/codemirror-theme-abyss")).abyss load: async () => (await import("@fsegurai/codemirror-theme-abyss")).abyss
}, },
{ {
name: "abcdef", id: "abcdef",
load: async () => (await import("@fsegurai/codemirror-theme-abcdef")).abcdef load: async () => (await import("@fsegurai/codemirror-theme-abcdef")).abcdef
} }
] ]

View File

@ -8,7 +8,7 @@ import byMimeType from "./syntax_highlighting.js";
import smartIndentWithTab from "./extensions/custom_tab.js"; import smartIndentWithTab from "./extensions/custom_tab.js";
import type { ThemeDefinition } from "./color_themes.js"; import type { ThemeDefinition } from "./color_themes.js";
export * from "./color_themes.js"; export { default as ColorThemes, type ThemeDefinition } from "./color_themes.js";
type ContentChangedListener = () => void; type ContentChangedListener = () => void;