mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
refactor(server): remove dependency on codemirror project
This commit is contained in:
parent
36009307d1
commit
ac49c0f59b
@ -4,6 +4,7 @@ import server from "../../../../services/server";
|
|||||||
import CodeMirror, { getThemeById } from "@triliumnext/codemirror";
|
import CodeMirror, { getThemeById } from "@triliumnext/codemirror";
|
||||||
import { DEFAULT_PREFIX } from "../../abstract_code_type_widget";
|
import { DEFAULT_PREFIX } from "../../abstract_code_type_widget";
|
||||||
import { t } from "../../../../services/i18n";
|
import { t } from "../../../../services/i18n";
|
||||||
|
import { ColorThemes } from "@triliumnext/codemirror";
|
||||||
|
|
||||||
// TODO: Deduplicate
|
// TODO: Deduplicate
|
||||||
interface Theme {
|
interface Theme {
|
||||||
@ -129,6 +130,15 @@ export default class CodeTheme extends OptionsWidget {
|
|||||||
const newTheme = String(this.$themeSelect.val());
|
const newTheme = String(this.$themeSelect.val());
|
||||||
await server.put(`options/codeNoteTheme/${newTheme}`);
|
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.$sampleEl = this.$widget.find(".note-detail-readonly-code-content");
|
||||||
this.$lineWrapEnabled = this.$widget.find(".word-wrap");
|
this.$lineWrapEnabled = this.$widget.find(".word-wrap");
|
||||||
this.$lineWrapEnabled.on("change", () => this.updateCheckboxOption("codeLineWrapEnabled", this.$lineWrapEnabled));
|
this.$lineWrapEnabled.on("change", () => this.updateCheckboxOption("codeLineWrapEnabled", this.$lineWrapEnabled));
|
||||||
@ -155,14 +165,6 @@ export default class CodeTheme extends OptionsWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async optionsLoaded(options: OptionMap) {
|
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.$themeSelect.val(options.codeNoteTheme);
|
||||||
this.#setupPreview(options);
|
this.#setupPreview(options);
|
||||||
this.setCheckboxState(this.$lineWrapEnabled, options.codeLineWrapEnabled);
|
this.setCheckboxState(this.$lineWrapEnabled, options.codeLineWrapEnabled);
|
||||||
|
@ -8,7 +8,6 @@ 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>([
|
||||||
@ -195,13 +194,6 @@ function getSyntaxHighlightingThemes() {
|
|||||||
return listSyntaxHighlightingThemes();
|
return listSyntaxHighlightingThemes();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCodeNoteThemes() {
|
|
||||||
return ColorThemes.map((theme) => ({
|
|
||||||
val: `default:${theme.id}`,
|
|
||||||
title: theme.name
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
function getSupportedLocales() {
|
function getSupportedLocales() {
|
||||||
return getLocales();
|
return getLocales();
|
||||||
}
|
}
|
||||||
@ -219,6 +211,5 @@ export default {
|
|||||||
updateOptions,
|
updateOptions,
|
||||||
getUserThemes,
|
getUserThemes,
|
||||||
getSyntaxHighlightingThemes,
|
getSyntaxHighlightingThemes,
|
||||||
getCodeNoteThemes,
|
|
||||||
getSupportedLocales
|
getSupportedLocales
|
||||||
};
|
};
|
||||||
|
@ -245,7 +245,6 @@ 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);
|
||||||
|
@ -36,9 +36,6 @@
|
|||||||
{
|
{
|
||||||
"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"
|
||||||
},
|
},
|
||||||
|
@ -6,9 +6,6 @@
|
|||||||
{
|
{
|
||||||
"path": "../../packages/ckeditor5"
|
"path": "../../packages/ckeditor5"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"path": "../../packages/codemirror"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"path": "../../packages/turndown-plugin-gfm"
|
"path": "../../packages/turndown-plugin-gfm"
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user