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
feat(codemirror): add model for themes
Elian Doran36246104dd66
diff --git a/packages/codemirror/package.json b/packages/codemirror/package.jsonindex fa237956af..105126a340 100644--- a/packages/codemirror/package.json+++ b/packages/codemirror/package.json@@ -31,6 +31,8 @@"@codemirror/legacy-modes": "6.5.1","@codemirror/search": "6.5.10","@codemirror/view": "6.36.7",+ "@fsegurai/codemirror-theme-abcdef": "6.1.4",+ "@fsegurai/codemirror-theme-abyss": "6.1.4","@replit/codemirror-lang-nix": "6.0.1","@replit/codemirror-vim": "6.3.0","@ssddanbrown/codemirror-lang-smarty": "1.0.0",diff --git a/packages/codemirror/src/color_themes.ts b/packages/codemirror/src/color_themes.tsnew file mode 100644index 0000000000..1420e39ef5--- /dev/null+++ b/packages/codemirror/src/color_themes.ts@@ -0,0 +1,19 @@+import type { Extension } from '@codemirror/state';++export interface ThemeDefinition {+ name: string;+ load(): Promise<Extension>;+}++const themes: ThemeDefinition[] = [+ {+ name: "abyss",+ load: async () => (await import("@fsegurai/codemirror-theme-abyss")).abyss+ },+ {+ name: "abcdef",+ load: async () => (await import("@fsegurai/codemirror-theme-abcdef")).abcdef+ }+]++export default themes;diff --git a/packages/codemirror/src/index.ts b/packages/codemirror/src/index.tsindex 7307e9f88a..7ca0004024 100644--- a/packages/codemirror/src/index.ts+++ b/packages/codemirror/src/index.ts@@ -6,6 +6,9 @@ import { highlightSelectionMatches } from "@codemirror/search";import { vim } from "@replit/codemirror-vim";import byMimeType from "./syntax_highlighting.js";import smartIndentWithTab from "./extensions/custom_tab.js";+import type { ThemeDefinition } from "./color_themes.js";++export * from "./color_themes.js";type ContentChangedListener = () => void;@@ -23,10 +26,12 @@ export default class CodeMirror extends EditorView {private config: EditorConfig;private languageCompartment: Compartment;private historyCompartment: Compartment;+ private themeCompartment: Compartment;constructor(config: EditorConfig) {const languageCompartment = new Compartment();const historyCompartment = new Compartment();+ const themeCompartment = new Compartment();let extensions: Extension[] = [];@@ -38,6 +43,7 @@ export default class CodeMirror extends EditorView {...extensions,languageCompartment.of([]),syntaxHighlighting(defaultHighlightStyle, { fallback: true }),+ themeCompartment.of([]),highlightActiveLine(),highlightSelectionMatches(),bracketMatching(),@@ -78,6 +84,7 @@ export default class CodeMirror extends EditorView {this.config = config;this.languageCompartment = languageCompartment;this.historyCompartment = historyCompartment;+ this.themeCompartment = themeCompartment;}#onDocumentUpdated(v: ViewUpdate) {@@ -100,6 +107,10 @@ export default class CodeMirror extends EditorView {})}+ async setTheme(theme: ThemeDefinition) {+ this.themeCompartment.reconfigure(await theme.load());+ }+/*** Clears the history of undo/redo. Generally useful when changing to a new document.*/diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 14493dcadb..722ab32087 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -1187,6 +1187,12 @@ importers:'@codemirror/view':specifier: 6.36.7version: 6.36.7+ '@fsegurai/codemirror-theme-abcdef':+ specifier: 6.1.4+ version: 6.1.4(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])+ '@fsegurai/codemirror-theme-abyss':+ specifier: 6.1.4+ version: 6.1.4(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])'@replit/codemirror-lang-nix':specifier: 6.0.1version: 6.0.1(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])(@lezer/[email protected])(@lezer/[email protected])@@ -3095,6 +3101,22 @@ packages:'@floating-ui/[email protected]':resolution: {integrity: sha512-MDWhGtE+eHw5JW7lq4qhc5yRLS11ERl1c7Z6Xd0a58DozHES6EnNNwUWbMiG4J9Cgj053Bhk8zvlhFYKVhULwg==}+ '@fsegurai/[email protected]':+ resolution: {integrity: sha512-GN0+41KESPiMR87jwlNq7DTqNh7NlVe/DRZwXY1sfGoLGWFmFCmRshU44wfaW9BDMtLVdddFi9zhJyeEk3rfcw==}+ peerDependencies:+ '@codemirror/language': ^6.0.0+ '@codemirror/state': ^6.0.0+ '@codemirror/view': ^6.0.0+ '@lezer/highlight': ^1.0.0++ '@fsegurai/[email protected]':+ resolution: {integrity: sha512-Rr5LM7z3LSoeZobunHe3cxlpQ+FU+eo5hagxoAlW+UCl50VGK55h7M8tI/XF8Ry3H7G2PWwacGHjweYiRhhzlA==}+ peerDependencies:+ '@codemirror/language': ^6.0.0+ '@codemirror/state': ^6.0.0+ '@codemirror/view': ^6.0.0+ '@lezer/highlight': ^1.0.0+'@fullcalendar/[email protected]':resolution: {integrity: sha512-0W7lnIrv18ruJ5zeWBeNZXO8qCWlzxDdp9COFEsZnyNjiEhUVnrW/dPbjRKYpL0edGG0/Lhs0ghp1z/5ekt8ZA==}@@ -15327,27 +15349,23 @@ snapshots:- supports-color- utf-8-validate+ '@ckeditor/[email protected]':dependencies:'@ckeditor/ckeditor5-comments': 45.0.0'@ckeditor/ckeditor5-core': 45.0.0([email protected])([email protected])'@ckeditor/ckeditor5-icons': 45.0.0'@ckeditor/ckeditor5-theme-lark': 45.0.0([email protected])([email protected])- '@ckeditor/ckeditor5-track-changes': 45.0.0([email protected])([email protected])+ '@ckeditor/ckeditor5-track-changes': 45.0.0'@ckeditor/ckeditor5-ui': 45.0.0([email protected])([email protected])'@ckeditor/ckeditor5-utils': 45.0.0([email protected])([email protected])'@types/luxon': 3.4.2ckeditor5: 45.0.0(patch_hash=8331a09d41443b39ea1c784daaccfeb0da4f9065ed556e7de92e9c77edd9eb41)luxon: 3.5.0- transitivePeerDependencies:- - bufferutil- - supports-color- - utf-8-validate'@ckeditor/[email protected]':dependencies:'@ckeditor/ckeditor5-clipboard': 45.0.0([email protected])([email protected])- '@ckeditor/ckeditor5-collaboration-core': 45.0.0([email protected])([email protected])+ '@ckeditor/ckeditor5-collaboration-core': 45.0.0'@ckeditor/ckeditor5-core': 45.0.0([email protected])([email protected])'@ckeditor/ckeditor5-engine': 45.0.0([email protected])([email protected])'@ckeditor/ckeditor5-enter': 45.0.0([email protected])([email protected])@@ -15368,7 +15386,7 @@ snapshots:dependencies:'@ckeditor/ckeditor5-clipboard': 45.0.0([email protected])([email protected])- '@ckeditor/ckeditor5-collaboration-core': 45.0.0([email protected])([email protected])+ '@ckeditor/ckeditor5-collaboration-core': 45.0.0'@ckeditor/ckeditor5-core': 45.0.0([email protected])([email protected])'@ckeditor/ckeditor5-engine': 45.0.0([email protected])([email protected])'@ckeditor/ckeditor5-enter': 45.0.0([email protected])([email protected])@@ -15807,6 +15825,14 @@ snapshots:- supports-color- utf-8-validate+ '@ckeditor/[email protected]':+ dependencies:+ '@ckeditor/ckeditor5-core': 45.0.0([email protected])([email protected])+ '@ckeditor/ckeditor5-icons': 45.0.0+ '@ckeditor/ckeditor5-ui': 45.0.0([email protected])([email protected])+ '@ckeditor/ckeditor5-utils': 45.0.0([email protected])([email protected])+ ckeditor5: 45.0.0(patch_hash=8331a09d41443b39ea1c784daaccfeb0da4f9065ed556e7de92e9c77edd9eb41)+dependencies:'@ckeditor/ckeditor5-core': 45.0.0([email protected])([email protected])@@ -16189,7 +16215,7 @@ snapshots:'@ckeditor/ckeditor5-operations-compressor': 45.0.0'@ckeditor/ckeditor5-revision-history': 45.0.0'@ckeditor/ckeditor5-theme-lark': 45.0.0([email protected])([email protected])- '@ckeditor/ckeditor5-track-changes': 45.0.0([email protected])([email protected])+ '@ckeditor/ckeditor5-track-changes': 45.0.0'@ckeditor/ckeditor5-ui': 45.0.0([email protected])([email protected])'@ckeditor/ckeditor5-utils': 45.0.0([email protected])([email protected])ckeditor5: 45.0.0(patch_hash=8331a09d41443b39ea1c784daaccfeb0da4f9065ed556e7de92e9c77edd9eb41)@@ -16390,7 +16416,7 @@ snapshots:- supports-color- utf-8-validate+ '@ckeditor/[email protected]':dependencies:'@ckeditor/ckeditor5-clipboard': 45.0.0([email protected])([email protected])'@ckeditor/ckeditor5-code-block': 45.0.0(patch_hash=2361d8caad7d6b5bddacc3a3b4aa37dbfba260b1c1b22a450413a79c1bb1ce95)@@ -16402,7 +16428,7 @@ snapshots:'@ckeditor/ckeditor5-find-and-replace': 45.0.0'@ckeditor/ckeditor5-font': 45.0.0([email protected])([email protected])'@ckeditor/ckeditor5-heading': 45.0.0([email protected])([email protected])- '@ckeditor/ckeditor5-highlight': 45.0.0([email protected])([email protected])+ '@ckeditor/ckeditor5-highlight': 45.0.0'@ckeditor/ckeditor5-icons': 45.0.0'@ckeditor/ckeditor5-image': 45.0.0([email protected])([email protected])'@ckeditor/ckeditor5-link': 45.0.0([email protected])([email protected])@@ -16419,10 +16445,6 @@ snapshots:ckeditor5: 45.0.0(patch_hash=8331a09d41443b39ea1c784daaccfeb0da4f9065ed556e7de92e9c77edd9eb41)ckeditor5-collaboration: 45.0.0es-toolkit: 1.32.0- transitivePeerDependencies:- - bufferutil- - supports-color- - utf-8-validatedependencies:@@ -17551,6 +17573,20 @@ snapshots:'@floating-ui/[email protected]': {}+ '@fsegurai/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])':+ dependencies:+ '@codemirror/language': 6.11.0+ '@codemirror/state': 6.5.2+ '@codemirror/view': 6.36.7+ '@lezer/highlight': 1.2.1++ '@fsegurai/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])':+ dependencies:+ '@codemirror/language': 6.11.0+ '@codemirror/state': 6.5.2+ '@codemirror/view': 6.36.7+ '@lezer/highlight': 1.2.1+'@fullcalendar/[email protected]':dependencies:preact: 10.12.1@@ -21873,7 +21909,7 @@ snapshots:dependencies:- '@ckeditor/ckeditor5-collaboration-core': 45.0.0([email protected])([email protected])+ '@ckeditor/ckeditor5-collaboration-core': 45.0.0[email protected](patch_hash=8331a09d41443b39ea1c784daaccfeb0da4f9065ed556e7de92e9c77edd9eb41):dependencies:@@ -21904,7 +21940,7 @@ snapshots:'@ckeditor/ckeditor5-font': 45.0.0([email protected])([email protected])'@ckeditor/ckeditor5-fullscreen': 45.0.0([email protected])([email protected])'@ckeditor/ckeditor5-heading': 45.0.0([email protected])([email protected])- '@ckeditor/ckeditor5-highlight': 45.0.0([email protected])([email protected])+ '@ckeditor/ckeditor5-highlight': 45.0.0'@ckeditor/ckeditor5-horizontal-line': 45.0.0'@ckeditor/ckeditor5-html-embed': 45.0.0'@ckeditor/ckeditor5-html-support': 45.0.0