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
small cleanups
zadam9797942b8ed9
diff --git a/src/public/javascripts/desktop.js b/src/public/javascripts/desktop.jsindex f2fda36d42..9bb24fc2dd 100644--- a/src/public/javascripts/desktop.js+++ b/src/public/javascripts/desktop.js@@ -1,4 +1,3 @@-import cloning from './services/cloning.js';import contextMenu from './services/tree_context_menu.js';import link from './services/link.js';import ws from './services/ws.js';@@ -9,7 +8,7 @@ import FrontendScriptApi from './services/frontend_script_api.js';import ScriptContext from './services/script_context.js';import sync from './services/sync.js';import treeService from './services/tree.js';-import treeChanges from './services/branches.js';+import branchService from './services/branches.js';import utils from './services/utils.js';import server from './services/server.js';import Entrypoints from './services/entrypoints.js';@@ -22,7 +21,6 @@ import noteTypeService from './widgets/note_type.js';import linkService from './services/link.js';import noteAutocompleteService from './services/note_autocomplete.js';import macInit from './services/mac_init.js';-import cssLoader from './services/css_loader.js';import dateNoteService from './services/date_notes.js';import importService from './services/import.js';import keyboardActionService from "./services/keyboard_actions.js";@@ -76,7 +74,7 @@ window.onerror = function (msg, url, lineNo, columnNo, error) {};for (const appCssNoteId of window.appCssNoteIds) {- cssLoader.requireCss(`api/notes/download/${appCssNoteId}`);+ libraryLoader.requireCss(`api/notes/download/${appCssNoteId}`);}const wikiBaseUrl = "https://github.com/zadam/trilium/wiki/";diff --git a/src/public/javascripts/dialogs/clone_to.js b/src/public/javascripts/dialogs/clone_to.jsindex f570841e6e..eab144aac2 100644--- a/src/public/javascripts/dialogs/clone_to.js+++ b/src/public/javascripts/dialogs/clone_to.js@@ -1,9 +1,9 @@import noteAutocompleteService from "../services/note_autocomplete.js";import utils from "../services/utils.js";-import cloningService from "../services/cloning.js";import treeService from "../services/tree.js";import toastService from "../services/toast.js";import treeCache from "../services/tree_cache.js";+import branchService from "../services/branches.js";const $dialog = $("#clone-to-dialog");const $form = $("#clone-to-form");@@ -42,7 +42,7 @@ async function cloneNotesTo(notePath) {const targetNoteId = treeService.getNoteIdFromNotePath(notePath);for (const cloneNoteId of clonedNoteIds) {- await cloningService.cloneNoteTo(cloneNoteId, targetNoteId, $clonePrefix.val());+ await branchService.cloneNoteTo(cloneNoteId, targetNoteId, $clonePrefix.val());const clonedNote = await treeCache.getNote(cloneNoteId);const targetNote = await treeCache.getNote(targetNoteId);diff --git a/src/public/javascripts/dialogs/move_to.js b/src/public/javascripts/dialogs/move_to.jsindex aedadbe525..4dbc6bcca5 100644--- a/src/public/javascripts/dialogs/move_to.js+++ b/src/public/javascripts/dialogs/move_to.js@@ -2,8 +2,7 @@ import noteAutocompleteService from "../services/note_autocomplete.js";import utils from "../services/utils.js";import toastService from "../services/toast.js";import treeCache from "../services/tree_cache.js";-import treeChangesService from "../services/branches.js";-import appContext from "../services/app_context.js";+import branchService from "../services/branches.js";import treeService from "../services/tree.js";const $dialog = $("#move-to-dialog");@@ -34,7 +33,7 @@ export async function showDialog(branchIds) {}async function moveNotesTo(parentNoteId) {- await treeChangesService.moveToParentNote(movedBranchIds, parentNoteId);+ await branchService.moveToParentNote(movedBranchIds, parentNoteId);const parentNote = await treeCache.getNote(parentNoteId);diff --git a/src/public/javascripts/dialogs/options/appearance.js b/src/public/javascripts/dialogs/options/appearance.jsindex 372ed1e1fb..8d7b53d2db 100644--- a/src/public/javascripts/dialogs/options/appearance.js+++ b/src/public/javascripts/dialogs/options/appearance.js@@ -1,7 +1,7 @@import server from "../../services/server.js";import utils from "../../services/utils.js";-import cssLoader from "../../services/css_loader.js";import appContext from "../../services/app_context.js";+import libraryLoader from "../../services/library_loader.js";const TPL = `<p><strong>Settings on this options tab are saved automatically after each change.</strong></p>@@ -98,7 +98,7 @@ export default class ApperanceOptions {if (noteId) {// make sure the CSS is loaded// if the CSS has been loaded and then updated then the changes won't take effect though- cssLoader.requireCss(`api/notes/download/${noteId}`);+ libraryLoader.requireCss(`api/notes/download/${noteId}`);}this.$body.addClass("theme-" + newTheme);diff --git a/src/public/javascripts/mobile.js b/src/public/javascripts/mobile.jsindex 1c91a9d8cb..fb4638dcb4 100644--- a/src/public/javascripts/mobile.js+++ b/src/public/javascripts/mobile.js@@ -2,7 +2,7 @@ import treeService from "./services/tree.js";import treeCache from "./services/tree_cache.js";import treeBuilder from "./services/tree_builder.js";import contextMenuWidget from "./services/context_menu.js";-import treeChangesService from "./services/branches.js";+import branchService from "./services/branches.js";import utils from "./services/utils.js";import appContext from "./services/app_context.js";import noteCreateService from "./services/note_create.js";@@ -123,7 +123,7 @@ $detail.on("click", ".note-menu-button", async e => {noteCreateService.createNote(node.data.noteId);}else if (cmd === "delete") {- if (await treeChangesService.deleteNotes([node])) {+ if (await branchService.deleteNotes([node])) {// move to the treetogglePanes();}diff --git a/src/public/javascripts/services/branches.js b/src/public/javascripts/services/branches.jsindex 5234941425..7be5da5e2f 100644--- a/src/public/javascripts/services/branches.js+++ b/src/public/javascripts/services/branches.js@@ -198,10 +198,31 @@ ws.subscribeToMessages(async message => {}});+async function cloneNoteTo(childNoteId, parentNoteId, prefix) {+ const resp = await server.put('notes/' + childNoteId + '/clone-to/' + parentNoteId, {+ prefix: prefix+ });++ if (!resp.success) {+ alert(resp.message);+ }+}++// beware that first arg is noteId and second is branchId!+async function cloneNoteAfter(noteId, afterBranchId) {+ const resp = await server.put('notes/' + noteId + '/clone-after/' + afterBranchId);++ if (!resp.success) {+ alert(resp.message);+ }+}+export default {moveBeforeBranch,moveAfterBranch,moveToParentNote,deleteNotes,- moveNodeUpInHierarchy+ moveNodeUpInHierarchy,+ cloneNoteAfter,+ cloneNoteTo};\ No newline at end of filediff --git a/src/public/javascripts/services/clipboard.js b/src/public/javascripts/services/clipboard.jsindex eac84ab3ad..5b09f05704 100644--- a/src/public/javascripts/services/clipboard.js+++ b/src/public/javascripts/services/clipboard.js@@ -1,5 +1,4 @@-import treeChangesService from "./branches.js";-import cloningService from "./cloning.js";+import branchService from "./branches.js";import toastService from "./toast.js";import hoistedNoteService from "./hoisted_note.js";import treeCache from "./tree_cache.js";@@ -13,7 +12,7 @@ async function pasteAfter(afterBranchId) {}if (clipboardMode === 'cut') {- await treeChangesService.moveAfterBranch(clipboardBranchIds, afterBranchId);+ await branchService.moveAfterBranch(clipboardBranchIds, afterBranchId);clipboardBranchIds = [];clipboardMode = null;@@ -24,7 +23,7 @@ async function pasteAfter(afterBranchId) {for (const clipboardBranch of clipboardBranches) {const clipboardNote = await clipboardBranch.getNote();- await cloningService.cloneNoteAfter(clipboardNote.noteId, afterBranchId);+ await branchService.cloneNoteAfter(clipboardNote.noteId, afterBranchId);}// copy will keep clipboardBranchIds and clipboardMode so it's possible to paste into multiple places@@ -40,7 +39,7 @@ async function pasteInto(parentNoteId) {}if (clipboardMode === 'cut') {- await treeChangesService.moveToParentNote(clipboardBranchIds, parentNoteId);+ await branchService.moveToParentNote(clipboardBranchIds, parentNoteId);clipboardBranchIds = [];clipboardMode = null;@@ -51,7 +50,7 @@ async function pasteInto(parentNoteId) {for (const clipboardBranch of clipboardBranches) {const clipboardNote = await clipboardBranch.getNote();- await cloningService.cloneNoteTo(clipboardNote.noteId, parentNoteId);+ await branchService.cloneNoteTo(clipboardNote.noteId, parentNoteId);}// copy will keep clipboardBranchIds and clipboardMode so it's possible to paste into multiple placesdiff --git a/src/public/javascripts/services/cloning.js b/src/public/javascripts/services/cloning.jsdeleted file mode 100644index 2012108290..0000000000--- a/src/public/javascripts/services/cloning.js+++ /dev/null@@ -1,30 +0,0 @@-import treeCache from './tree_cache.js';-import server from './server.js';-import appContext from "./app_context.js";--async function cloneNoteTo(childNoteId, parentNoteId, prefix) {- const resp = await server.put('notes/' + childNoteId + '/clone-to/' + parentNoteId, {- prefix: prefix- });-- if (!resp.success) {- alert(resp.message);- }-}--// beware that first arg is noteId and second is branchId!-async function cloneNoteAfter(noteId, afterBranchId) {- const resp = await server.put('notes/' + noteId + '/clone-after/' + afterBranchId);-- if (!resp.success) {- alert(resp.message);- return;- }-- const afterBranch = treeCache.getBranch(afterBranchId);-}--export default {- cloneNoteAfter,- cloneNoteTo-};\ No newline at end of filediff --git a/src/public/javascripts/services/css_loader.js b/src/public/javascripts/services/css_loader.jsdeleted file mode 100644index 8f9bba3f49..0000000000--- a/src/public/javascripts/services/css_loader.js+++ /dev/null@@ -1,13 +0,0 @@-async function requireCss(url) {- const cssLinks = Array- .from(document.querySelectorAll('link'))- .map(el => el.href);-- if (!cssLinks.some(l => l.endsWith(url))) {- $('head').append($('<link rel="stylesheet" type="text/css" />').attr('href', url));- }-}--export default {- requireCss-}\ No newline at end of filediff --git a/src/public/javascripts/services/import.js b/src/public/javascripts/services/import.jsindex 8e3695ecb1..c3085a3143 100644--- a/src/public/javascripts/services/import.js+++ b/src/public/javascripts/services/import.js@@ -1,5 +1,4 @@import toastService from "./toast.js";-import treeService from "./tree.js";import server from "./server.js";import ws from "./ws.js";import utils from "./utils.js";diff --git a/src/public/javascripts/services/keys.js b/src/public/javascripts/services/keys.jsdeleted file mode 100644index 64517f91be..0000000000--- a/src/public/javascripts/services/keys.js+++ /dev/null@@ -1,16 +0,0 @@-class Actions {- constructor() {- this.JUMP_TO = "";- }-}--const actions = new Actions();--function bind() {--}--export default {- actions,- bind-};\ No newline at end of filediff --git a/src/public/javascripts/services/library_loader.js b/src/public/javascripts/services/library_loader.jsindex 5d0b81aef5..8579dc5932 100644--- a/src/public/javascripts/services/library_loader.js+++ b/src/public/javascripts/services/library_loader.js@@ -1,5 +1,3 @@-import cssLoader from './css_loader.js';-const CKEDITOR = {"js": ["libraries/ckeditor/ckeditor.js"]};const CODE_MIRROR = {@@ -55,7 +53,7 @@ const CALENDAR_WIDGET = {css: ["stylesheets/calendar.css"]};async function requireLibrary(library) {if (library.css) {- library.css.map(cssUrl => cssLoader.requireCss(cssUrl));+ library.css.map(cssUrl => requireCss(cssUrl));}if (library.js) {@@ -80,7 +78,18 @@ async function requireScript(url) {await loadedScriptPromises[url];}+async function requireCss(url) {+ const cssLinks = Array+ .from(document.querySelectorAll('link'))+ .map(el => el.href);++ if (!cssLinks.some(l => l.endsWith(url))) {+ $('head').append($('<link rel="stylesheet" type="text/css" />').attr('href', url));+ }+}+export default {+ requireCss,requireLibrary,CKEDITOR,CODE_MIRROR,diff --git a/src/public/javascripts/widgets/note_tree.js b/src/public/javascripts/widgets/note_tree.jsindex 89578b46db..c34e735234 100644--- a/src/public/javascripts/widgets/note_tree.js+++ b/src/public/javascripts/widgets/note_tree.js@@ -5,7 +5,7 @@ import contextMenuWidget from "../services/context_menu.js";import treeCache from "../services/tree_cache.js";import treeBuilder from "../services/tree_builder.js";import TreeContextMenu from "../services/tree_context_menu.js";-import treeChangesService from "../services/branches.js";+import branchService from "../services/branches.js";import ws from "../services/ws.js";import TabAwareWidget from "./tab_aware_widget.js";import server from "../services/server.js";@@ -167,11 +167,11 @@ export default class NoteTreeWidget extends TabAwareWidget {const selectedBranchIds = this.getSelectedNodes().map(node => node.data.branchId);if (data.hitMode === "before") {- treeChangesService.moveBeforeBranch(selectedBranchIds, node.data.branchId);+ branchService.moveBeforeBranch(selectedBranchIds, node.data.branchId);} else if (data.hitMode === "after") {- treeChangesService.moveAfterBranch(selectedBranchIds, node.data.branchId);+ branchService.moveAfterBranch(selectedBranchIds, node.data.branchId);} else if (data.hitMode === "over") {- treeChangesService.moveToParentNote(selectedBranchIds, node.data.noteId);+ branchService.moveToParentNote(selectedBranchIds, node.data.noteId);} else {throw new Error("Unknown hitMode=" + data.hitMode);}@@ -661,7 +661,7 @@ export default class NoteTreeWidget extends TabAwareWidget {async deleteNotesCommand({node}) {const branchIds = this.getSelectedOrActiveBranchIds(node);- await treeChangesService.deleteNotes(branchIds);+ await branchService.deleteNotes(branchIds);this.clearSelectedNodes();}@@ -670,26 +670,26 @@ export default class NoteTreeWidget extends TabAwareWidget {const beforeNode = node.getPrevSibling();if (beforeNode !== null) {- treeChangesService.moveBeforeBranch([node.data.branchId], beforeNode.data.branchId);+ branchService.moveBeforeBranch([node.data.branchId], beforeNode.data.branchId);}}moveNoteDownCommand({node}) {const afterNode = node.getNextSibling();if (afterNode !== null) {- treeChangesService.moveAfterBranch([node.data.branchId], afterNode.data.branchId);+ branchService.moveAfterBranch([node.data.branchId], afterNode.data.branchId);}}moveNoteUpInHierarchyCommand({node}) {- treeChangesService.moveNodeUpInHierarchy(node);+ branchService.moveNodeUpInHierarchy(node);}moveNoteDownInHierarchyCommand({node}) {const toNode = node.getPrevSibling();if (toNode !== null) {- treeChangesService.moveToParentNote([node.data.branchId], toNode.data.noteId);+ branchService.moveToParentNote([node.data.branchId], toNode.data.noteId);}}