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 refactorings
zadam358fd13c8dd2
diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xmlnew file mode 100644index 0000000000..d1d2927d2a--- /dev/null+++ b/.idea/jsLibraryMappings.xml@@ -0,0 +1,6 @@+<?xml version="1.0" encoding="UTF-8"?>+<project version="4">+ <component name="JavaScriptLibraryMappings">+ <file url="PROJECT" libraries="{@types/jquery}" />+ </component>+</project>\ No newline at end of filediff --git a/package-lock.json b/package-lock.jsonindex 4ba4a0cb56..033bd02805 100644--- a/package-lock.json+++ b/package-lock.json@@ -13037,9 +13037,9 @@}},"ws": {- "version": "7.1.2",- "resolved": "https://registry.npmjs.org/ws/-/ws-7.1.2.tgz",- "integrity": "sha512-gftXq3XI81cJCgkUiAVixA0raD9IVmXqsylCrjRygw4+UOOGzPoxnQ6r/CnVL9i+mDncJo94tSkyrtuuQVBmrg==",+ "version": "7.2.0",+ "resolved": "https://registry.npmjs.org/ws/-/ws-7.2.0.tgz",+ "integrity": "sha512-+SqNqFbwTm/0DC18KYzIsMTnEWpLwJsiasW/O17la4iDRRIO9uaHbvKiAS3AHgTiuuWerK/brj4O6MYZkei9xg==","requires": {"async-limiter": "^1.0.0"}diff --git a/package.json b/package.jsonindex d304752d58..c625c6dfbd 100644--- a/package.json+++ b/package.json@@ -74,7 +74,7 @@"turndown": "5.0.3","turndown-plugin-gfm": "1.0.2","unescape": "1.0.1",- "ws": "7.1.2",+ "ws": "7.2.0","xml2js": "0.4.22"},"devDependencies": {diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.jsindex c5af66e726..96b5e39e68 100644--- a/src/public/javascripts/services/note_detail.js+++ b/src/public/javascripts/services/note_detail.js@@ -90,6 +90,7 @@ async function activateOrOpenNote(noteId) {});}+/** @return {TabContext[]} */function getTabContexts() {return tabContexts;}@@ -119,12 +120,14 @@ function getActiveTabNote() {return activeContext ? activeContext.note : null;}+/** @return {string|null} */function getActiveTabNoteId() {const activeNote = getActiveTabNote();return activeNote ? activeNote.noteId : null;}+/** @return {string|null} */function getActiveTabNoteType() {const activeNote = getActiveTabNote();diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.jsindex 4ff366df8e..891e6b733e 100644--- a/src/public/javascripts/services/tree.js+++ b/src/public/javascripts/services/tree.js@@ -25,19 +25,26 @@ const $scrollToActiveNoteButton = $("#scroll-to-active-note-button");let setFrontendAsLoaded;const frontendLoaded = new Promise(resolve => { setFrontendAsLoaded = resolve; });-// focused & not active node can happen during multiselection where the node is selected but not activated-// (its content is not displayed in the detail)+/**+ * focused & not active node can happen during multiselection where the node is selected but not activated+ * (its content is not displayed in the detail)+ * @return {FancytreeNode|null}+ */function getFocusedNode() {const tree = $tree.fancytree("getTree");return tree.getFocusNode();}-// note that if you want to access data like noteId or isProtected, you need to go into "data" property+/**+ * note that if you want to access data like noteId or isProtected, you need to go into "data" property+ * @return {FancytreeNode|null}+ */function getActiveNode() {return $tree.fancytree("getActiveNode");}+/** @return {FancytreeNode[]} */async function getNodesByBranchId(branchId) {utils.assertArguments(branchId);@@ -46,6 +53,7 @@ async function getNodesByBranchId(branchId) {return getNodesByNoteId(branch.noteId).filter(node => node.data.branchId === branchId);}+/** @return {FancytreeNode[]} */function getNodesByNoteId(noteId) {utils.assertArguments(noteId);@@ -76,10 +84,12 @@ async function setNodeTitleWithPrefix(node) {node.setTitle(utils.escapeHtml(title));}+/** @return {FancytreeNode} */async function expandToNote(notePath, expandOpts) {return await getNodeFromPath(notePath, true, expandOpts);}+/** @return {FancytreeNode} */function findChildNode(parentNode, childNoteId) {let foundChildNode = null;@@ -89,13 +99,16 @@ function findChildNode(parentNode, childNoteId) {break;}}+return foundChildNode;}+/** @return {FancytreeNode} */async function getNodeFromPath(notePath, expand = false, expandOpts = {}) {utils.assertArguments(notePath);const hoistedNoteId = await hoistedNoteService.getHoistedNoteId();+ /** @var {FancytreeNode} */let parentNode = null;const runPath = await getRunPath(notePath);@@ -145,6 +158,7 @@ async function getNodeFromPath(notePath, expand = false, expandOpts = {}) {return parentNode;}+/** @return {FancytreeNode} */async function activateNote(notePath, noteLoadedListener) {utils.assertArguments(notePath);@@ -190,6 +204,7 @@ async function activateNote(notePath, noteLoadedListener) {/*** Accepts notePath which might or might not be valid and returns an existing path as close to the original* notePath as possible.+ * @return {string|null}*/async function resolveNotePath(notePath) {const runPath = await getRunPath(notePath);@@ -200,6 +215,8 @@ async function resolveNotePath(notePath) {/*** Accepts notePath and tries to resolve it. Part of the path might not be valid because of note moving (which causes* path change) or other corruption, in that case this will try to get some other valid path to the correct note.+ *+ * @return {string[]}*/async function getRunPath(notePath) {utils.assertArguments(notePath);@@ -313,10 +330,12 @@ async function setExpandedToServer(branchId, isExpanded) {await server.put('branches/' + branchId + '/expanded/' + expandedNum);}+/** @return {FancytreeNode[]} */function getSelectedNodes(stopOnParents = false) {return getTree().getSelectedNodes(stopOnParents);}+/** @return {FancytreeNode[]} */function getSelectedOrActiveNodes(node) {let notes = getSelectedNodes(true);@@ -506,6 +525,7 @@ function initFancyTree(tree) {});}+/** @return {Fancytree} */function getTree() {return $tree.fancytree('getTree');}@@ -759,27 +779,17 @@ ws.subscribeToMessages(message => {});ws.subscribeToOutsideSyncMessages(syncData => {- const noteIdsToRefresh = [];+ const noteIdsToRefresh = new Set();- for (const sync of syncData.filter(sync => sync.entityName === 'branches')) {- if (!noteIdsToRefresh.includes(sync.parentNoteId)) {- noteIdsToRefresh.push(sync.parentNoteId);- }- }+ // this has the problem that the former parentNoteId might not be invalidated+ // and the former location of the branch/note won't be removed.+ syncData.filter(sync => sync.entityName === 'branches').forEach(sync => noteIdsToRefresh.add(sync.parentNoteId));- for (const sync of syncData.filter(sync => sync.entityName === 'notes')) {- if (!noteIdsToRefresh.includes(sync.noteId)) {- noteIdsToRefresh.push(sync.noteId);- }- }+ syncData.filter(sync => sync.entityName === 'notes').forEach(sync => noteIdsToRefresh.add(sync.noteId));- for (const sync of syncData.filter(sync => sync.entityName === 'note_reordering')) {- if (!noteIdsToRefresh.includes(sync.entityId)) {- noteIdsToRefresh.push(sync.entityId);- }- }+ syncData.filter(sync => sync.entityName === 'note_reordering').forEach(sync => noteIdsToRefresh.add(sync.entityId));- reloadNotes(noteIdsToRefresh);+ reloadNotes(Array.from(noteIdsToRefresh));});utils.bindGlobalShortcut('ctrl+o', async () => {diff --git a/src/public/javascripts/services/tree_builder.js b/src/public/javascripts/services/tree_builder.jsindex 0fc55ba5d2..0480b480d7 100644--- a/src/public/javascripts/services/tree_builder.js+++ b/src/public/javascripts/services/tree_builder.js@@ -1,4 +1,3 @@-import noteDetailService from "./note_detail.js";import utils from "./utils.js";import Branch from "../entities/branch.js";import server from "./server.js";diff --git a/trilium.iml b/trilium.imlindex eb60d28180..6459dc93bc 100644--- a/trilium.iml+++ b/trilium.iml@@ -9,5 +9,6 @@</content><orderEntry type="inheritedJdk" /><orderEntry type="sourceFolder" forTests="false" />+ <orderEntry type="library" name="@types/jquery" level="application" /></component></module>\ No newline at end of file