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
wip
zadam368d3b1b970d
diff --git a/package-lock.json b/package-lock.jsonindex bbe770cdd5..56f5893fa3 100644--- a/package-lock.json+++ b/package-lock.json@@ -8875,17 +8875,17 @@"integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw=="},"rimraf": {- "version": "3.0.0",- "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.0.tgz",- "integrity": "sha512-NDGVxTsjqfunkds7CqsOiEnxln4Bo7Nddl3XhS4pXg5OzwkLqJ971ZVAAnB+DDLnF76N+VnDEiBHaVV8I06SUg==",+ "version": "3.0.1",+ "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.1.tgz",+ "integrity": "sha512-IQ4ikL8SjBiEDZfk+DFVwqRK8md24RWMEJkdSlgNLkyyAImcjf8SWvU1qFMDOb4igBClbTQ/ugPqXcRwdFTxZw==","requires": {"glob": "^7.1.3"},"dependencies": {"glob": {- "version": "7.1.4",- "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz",- "integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==",+ "version": "7.1.6",+ "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz",+ "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==","requires": {"fs.realpath": "^1.0.0","inflight": "^1.0.4",diff --git a/package.json b/package.jsonindex f6bf189ade..9cfe115237 100644--- a/package.json+++ b/package.json@@ -59,7 +59,7 @@"portscanner": "2.2.0","rand-token": "0.4.0","rcedit": "2.1.0",- "rimraf": "3.0.0",+ "rimraf": "3.0.1","sanitize-filename": "1.6.3","sax": "1.2.4","semver": "7.1.1",diff --git a/src/public/javascripts/services/app_context.js b/src/public/javascripts/services/app_context.jsindex 133786bffe..2412d4b9a8 100644--- a/src/public/javascripts/services/app_context.js+++ b/src/public/javascripts/services/app_context.js@@ -138,7 +138,6 @@ class AppContext {tabNoteSwitchedListener({tabId}) {if (tabId === this.activeTabId) {- this._setTitleBar();this._setCurrentNotePathToHash();}}@@ -151,23 +150,6 @@ class AppContext {}}- noteTitleChangedListener() {- this._setTitleBar();- }-- async _setTitleBar() {- document.title = "Trilium Notes";-- const activeTabContext = this.getActiveTabContext();-- if (activeTabContext && activeTabContext.notePath) {- const note = await treeCache.getNote(treeService.getNoteIdFromNotePath(activeTabContext.notePath));-- // it helps navigating in history if note title is included in the title- document.title += " - " + note.title;- }- }-/** @return {TabContext[]} */getTabContexts() {return this.tabContexts;diff --git a/src/public/javascripts/services/date_notes.js b/src/public/javascripts/services/date_notes.jsindex 34e76105e0..e5d6faf6b6 100644--- a/src/public/javascripts/services/date_notes.js+++ b/src/public/javascripts/services/date_notes.js@@ -8,21 +8,21 @@ async function getTodayNote() {/** @return {NoteShort} */async function getDateNote(date) {- const note = await server.get('date-notes/date/' + date, {'trilium-source-id': "date-note"});+ const note = await server.get('date-notes/date/' + date, "date-note");return await treeCache.getNote(note.noteId);}/** @return {NoteShort} */async function getMonthNote(month) {- const note = await server.get('date-notes/month/' + month, {'trilium-source-id': "date-note"});+ const note = await server.get('date-notes/month/' + month, "date-note");return await treeCache.getNote(note.noteId);}/** @return {NoteShort} */async function getYearNote(year) {- const note = await server.get('date-notes/year/' + year, {'trilium-source-id': "date-note"});+ const note = await server.get('date-notes/year/' + year, "date-note");return await treeCache.getNote(note.noteId);}diff --git a/src/public/javascripts/services/frontend_script_api.js b/src/public/javascripts/services/frontend_script_api.jsindex 0e32ae09d9..cc3d300cd2 100644--- a/src/public/javascripts/services/frontend_script_api.js+++ b/src/public/javascripts/services/frontend_script_api.js@@ -145,9 +145,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabContecurrentNoteId: currentNote.noteId,originEntityName: "notes", // currently there's no other entity on frontend which can trigger eventoriginEntityId: originEntity ? originEntity.noteId : null- }, {- 'trilium-source-id': "script"- });+ }, "script");if (ret.success) {// wait until all the changes done in the script has been synced to frontend before continuingdiff --git a/src/public/javascripts/services/load_results.js b/src/public/javascripts/services/load_results.jsindex ef0053194b..4d9506ad99 100644--- a/src/public/javascripts/services/load_results.js+++ b/src/public/javascripts/services/load_results.js@@ -4,7 +4,7 @@ export class LoadResults {this.sourceIdToNoteIds = {};}- add(noteId, sourceId) {+ addNote(noteId, sourceId) {this.noteIdToSync[noteId] = this.noteIdToSync[noteId] || [];if (!this.noteIdToSync[noteId].includes(sourceId)) {@@ -23,6 +23,10 @@ export class LoadResults {}isNoteReloaded(noteId, sourceId) {+ if (!noteId) {+ return false;+ }+const sourceIds = this.noteIdToSync[noteId];return sourceIds && !!sourceIds.find(sId => sId !== sourceId);}diff --git a/src/public/javascripts/services/server.js b/src/public/javascripts/services/server.jsindex b1c5f99493..8181ffc88b 100644--- a/src/public/javascripts/services/server.js+++ b/src/public/javascripts/services/server.js@@ -8,13 +8,16 @@ function getHeaders(headers) {// so hypothetical protectedSessionId becomes protectedsessionid on the backend// also avoiding using underscores instead of dashes since nginx filters them out by defaultconst allHeaders = {- ...{- 'trilium-source-id': glob.sourceId,- 'x-csrf-token': glob.csrfToken- },- ...headers+ 'trilium-source-id': glob.sourceId,+ 'x-csrf-token': glob.csrfToken};+ for (const headerName in headers) {+ if (headers[headerName]) {+ allHeaders[headerName] = headers[headerName];+ }+ }+if (utils.isElectron()) {// passing it explicitely here because of the electron HTTP bypassallHeaders.cookie = document.cookie;@@ -23,20 +26,20 @@ function getHeaders(headers) {return allHeaders;}-async function get(url, headers = {}) {- return await call('GET', url, null, headers);+async function get(url, sourceId) {+ return await call('GET', url, null, {'trilium-source-id': sourceId});}-async function post(url, data, headers = {}) {- return await call('POST', url, data, headers);+async function post(url, data, sourceId) {+ return await call('POST', url, data, {'trilium-source-id': sourceId});}-async function put(url, data, headers = {}) {- return await call('PUT', url, data, headers);+async function put(url, data, sourceId) {+ return await call('PUT', url, data, {'trilium-source-id': sourceId});}-async function remove(url, headers = {}) {- return await call('DELETE', url, null, headers);+async function remove(url, sourceId) {+ return await call('DELETE', url, null, {'trilium-source-id': sourceId});}let i = 1;diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.jsindex 97ad7d7201..0f7a985947 100644--- a/src/public/javascripts/services/tab_context.js+++ b/src/public/javascripts/services/tab_context.js@@ -112,6 +112,20 @@ class TabContext extends Component {this.trigger('tabNoteSwitched', {tabId: this.tabId});}}++ // FIXME+ async _setTitleBar() {+ document.title = "Trilium Notes";++ const activeTabContext = this.getActiveTabContext();++ if (activeTabContext && activeTabContext.notePath) {+ const note = await treeCache.getNote(treeService.getNoteIdFromNotePath(activeTabContext.notePath));++ // it helps navigating in history if note title is included in the title+ document.title += " - " + note.title;+ }+ }}export default TabContext;\ No newline at end of filediff --git a/src/public/javascripts/services/tree_cache.js b/src/public/javascripts/services/tree_cache.jsindex 8586506a58..dddaf19eb0 100644--- a/src/public/javascripts/services/tree_cache.js+++ b/src/public/javascripts/services/tree_cache.js@@ -235,20 +235,20 @@ class TreeCache {const branch = this.branches[sync.entityId];// we assume that the cache contains the old branch state and we add also the old parentNoteId// so that the old parent can also be updated- loadResults.add(branch.parentNoteId, sync.sourceId);+ loadResults.addNote(branch.parentNoteId, sync.sourceId);// this should then contain new parentNoteId for which we should also update the cache- loadResults.add(sync.parentNoteId, sync.sourceId);+ loadResults.addNote(sync.parentNoteId, sync.sourceId);- loadResults.add(sync.noteId, sync.sourceId);+ loadResults.addNote(sync.noteId, sync.sourceId);});- syncRows.filter(sync => sync.entityName === 'notes').forEach(sync => loadResults.add(sync.entityId, sync.sourceId));+ syncRows.filter(sync => sync.entityName === 'notes').forEach(sync => loadResults.addNote(sync.entityId, sync.sourceId));- syncRows.filter(sync => sync.entityName === 'note_reordering').forEach(sync => loadResults.add(sync.entityId, sync.sourceId));+ syncRows.filter(sync => sync.entityName === 'note_reordering').forEach(sync => loadResults.addNote(sync.entityId, sync.sourceId));// missing reloading the relation target note- syncRows.filter(sync => sync.entityName === 'attributes').forEach(sync => loadResults.add(sync.noteId, sync.sourceId));+ syncRows.filter(sync => sync.entityName === 'attributes').forEach(sync => loadResults.addNote(sync.noteId, sync.sourceId));await this.reloadNotes(loadResults.getNoteIds());diff --git a/src/public/javascripts/widgets/note_detail.js b/src/public/javascripts/widgets/note_detail.jsindex 023379f566..7b8c78fba8 100644--- a/src/public/javascripts/widgets/note_detail.js+++ b/src/public/javascripts/widgets/note_detail.js@@ -43,7 +43,7 @@ export default class NoteDetailWidget extends TabAwareWidget {const dto = note.dto;dto.content = noteFull.content = this.getTypeWidget().getContent();- const resp = await server.put('notes/' + noteId, dto);+ const resp = await server.put('notes/' + noteId, dto, this.componentId);// FIXME: minor - does not propagate to other tab contexts with this note thoughnoteFull.dateModified = resp.dateModified;@@ -220,9 +220,9 @@ export default class NoteDetailWidget extends TabAwareWidget {this.refresh();}- notesReloadedListener({loadResults}) {- if (loadResults.isNoteReloaded(this.noteId, this.componentId)) {- this.refresh();- }+ notesReloadedListener(data) {+ super.notesReloadedListener(data);++ return false; // stop propagation to children}}\ No newline at end of filediff --git a/src/public/javascripts/widgets/note_info.js b/src/public/javascripts/widgets/note_info.jsindex 3d5c3dd8e7..4d87caac4a 100644--- a/src/public/javascripts/widgets/note_info.js+++ b/src/public/javascripts/widgets/note_info.js@@ -69,10 +69,8 @@ class NoteInfoWidget extends StandardWidget {// this is interesting for this widget since dateModified had to change after updatenoteChangesSavedListener({noteId}) {- const note = this.tabContext.note;-- if (note && note.noteId === noteId) {- this.refreshWithNote(note);+ if (this.isNote(noteId)) {+ this.refreshWithNote(this.note, this.notePath);}}diff --git a/src/public/javascripts/widgets/note_title.js b/src/public/javascripts/widgets/note_title.jsindex 1bd0a57294..29c26cc5a5 100644--- a/src/public/javascripts/widgets/note_title.js+++ b/src/public/javascripts/widgets/note_title.js@@ -78,17 +78,6 @@ export default class NoteTitleWidget extends TabAwareWidget {});}- noteTitleChangedListener({tabId, title, noteId}) {- if (tabId === this.tabContext.tabId- || !this.tabContext.note- || this.tabContext.note.noteId !== noteId) {-- return;- }-- this.$noteTitle.val(title);- }-async refreshWithNote(note) {this.$noteTitle.val(note.title);diff --git a/src/public/javascripts/widgets/note_tree.js b/src/public/javascripts/widgets/note_tree.jsindex 50fff927b8..8bb3ee6e3c 100644--- a/src/public/javascripts/widgets/note_tree.js+++ b/src/public/javascripts/widgets/note_tree.js@@ -427,16 +427,11 @@ export default class NoteTreeWidget extends TabAwareWidget {}}- async notesReloadedListener({ noteIds, activateNotePath }) {- if (!activateNotePath) {- const activeNode = this.getActiveNode();-- if (activeNode) {- activateNotePath = await treeService.getNotePath(activeNode);- }- }+ async notesReloadedListener({loadResults}) {+ const activeNode = this.getActiveNode();+ const activateNotePath = activeNode ? await treeService.getNotePath(activeNode) : null;- for (const noteId of noteIds) {+ for (const noteId of loadResults.getNoteIds()) {for (const node of this.getNodesByNoteId(noteId)) {const branch = treeCache.getBranch(node.data.branchId, true);@@ -460,12 +455,6 @@ export default class NoteTreeWidget extends TabAwareWidget {}}- noteTitleChangedListener({noteId}) {- for (const node of this.getNodesByNoteId(noteId)) {- treeService.setNodeTitleWithPrefix(node);- }- }-async createNoteAfterListener() {const node = this.getActiveNode();const parentNoteId = node.data.parentNoteId;diff --git a/src/public/javascripts/widgets/tab_aware_widget.js b/src/public/javascripts/widgets/tab_aware_widget.jsindex 6bba19c588..e259718b3f 100644--- a/src/public/javascripts/widgets/tab_aware_widget.js+++ b/src/public/javascripts/widgets/tab_aware_widget.js@@ -24,6 +24,10 @@ export default class TabAwareWidget extends BasicWidget {return this.note && this.note.noteId;}+ get notePath() {+ return this.tabContext && this.tabContext.notePath;+ }+tabNoteSwitchedListener({tabId}) {if (this.isTab(tabId)) {this.noteSwitched();@@ -39,20 +43,26 @@ export default class TabAwareWidget extends BasicWidget {}refresh() {- if (this.tabContext && this.tabContext.note) {+ if (this.note) {this.toggle(true);- this.refreshWithNote(this.tabContext.note, this.tabContext.notePath);+ this.refreshWithNote(this.note, this.notePath);}else {this.toggle(false);}}- refreshWithNote(note) {}+ refreshWithNote(note, notePath) {}activeTabChangedListener() {this.tabContext = this.appContext.getActiveTabContext();this.activeTabChanged();}++ notesReloadedListener({loadResults}) {+ if (loadResults.isNoteReloaded(this.noteId, this.componentId)) {+ this.refreshWithNote(this.note, this.notePath);+ }+ }}\ No newline at end of filediff --git a/src/public/javascripts/widgets/tab_row.js b/src/public/javascripts/widgets/tab_row.jsindex edb4634812..3f216dbc39 100644--- a/src/public/javascripts/widgets/tab_row.js+++ b/src/public/javascripts/widgets/tab_row.js@@ -498,13 +498,6 @@ export default class TabRowWidget extends BasicWidget {return this.$widget.find(`[data-tab-id='${tabId}']`);}- noteTitleChangedListener({title, noteId}) {- this.appContext.getTabContexts()- .filter(tc => tc.note && tc.note.noteId === noteId)- .map(tc => this.getTabById(tc.tabId))- .forEach($el => $el.find('.note-tab-title').text(title));- }-tabRemovedListener({tabId}) {this.removeTab(tabId);}