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
changes in note detail handling
zadam789f62267c19
diff --git a/src/public/javascripts/widgets/note_detail.js b/src/public/javascripts/widgets/note_detail.jsindex d284fbf4ee..0edcbcb0eb 100644--- a/src/public/javascripts/widgets/note_detail.js+++ b/src/public/javascripts/widgets/note_detail.js@@ -4,6 +4,16 @@ import protectedSessionHolder from "../services/protected_session_holder.js";import SpacedUpdate from "../services/spaced_update.js";import server from "../services/server.js";import libraryLoader from "../services/library_loader.js";+import EmptyTypeWidget from "./type_widgets/empty.js";+import TextTypeWidget from "./type_widgets/text.js";+import CodeTypeWidget from "./type_widgets/code.js";+import FileTypeWidget from "./type_widgets/file.js";+import ImageTypeWidget from "./type_widgets/image.js";+import SearchTypeWidget from "./type_widgets/search.js";+import RenderTypeWidget from "./type_widgets/render.js";+import RelationMapTypeWidget from "./type_widgets/relation_map.js";+import ProtectedSessionTypeWidget from "./type_widgets/protected_session.js";+import BookTypeWidget from "./type_widgets/book.js";const TPL = `<div class="note-detail">@@ -16,16 +26,16 @@ const TPL = ``;const typeWidgetClasses = {- 'empty': "./type_widgets/empty.js",- 'text': "./type_widgets/text.js",- 'code': "./type_widgets/code.js",- 'file': "./type_widgets/file.js",- 'image': "./type_widgets/image.js",- 'search': "./type_widgets/search.js",- 'render': "./type_widgets/render.js",- 'relation-map': "./type_widgets/relation_map.js",- 'protected-session': "./type_widgets/protected_session.js",- 'book': "./type_widgets/book.js"+ 'empty': EmptyTypeWidget,+ 'text': TextTypeWidget,+ 'code': CodeTypeWidget,+ 'file': FileTypeWidget,+ 'image': ImageTypeWidget,+ 'search': SearchTypeWidget,+ 'render': RenderTypeWidget,+ 'relation-map': RelationMapTypeWidget,+ 'protected-session': ProtectedSessionTypeWidget,+ 'book': BookTypeWidget};export default class NoteDetailWidget extends TabAwareWidget {@@ -33,7 +43,6 @@ export default class NoteDetailWidget extends TabAwareWidget {super(appContext);this.typeWidgets = {};- this.typeWidgetPromises = {};this.spacedUpdate = new SpacedUpdate(async () => {const {note} = this.tabContext;@@ -77,32 +86,28 @@ export default class NoteDetailWidget extends TabAwareWidget {}async refresh() {- await this.initType();-- for (const typeWidget of Object.values(this.typeWidgets)) {- if (typeWidget.constructor.getType() !== this.type) {- typeWidget.cleanup();- typeWidget.toggle(false);- }+ if (!this.isEnabled()) {+ this.toggle(false);+ return;}- this.getTypeWidget().toggle(true);+ this.toggle(true);- this.setupClasses();- }+ this.type = await this.getWidgetType();- async initType() {- let foundType;+ if (!(this.type in this.typeWidgets)) {+ const clazz = typeWidgetClasses[this.type];- do {- foundType = this.type = await this.getWidgetType();+ const typeWidget = this.typeWidgets[this.type] = new clazz(this.appContext);+ typeWidget.spacedUpdate = this.spacedUpdate;- if (!(this.type in this.typeWidgetPromises)) {- this.typeWidgetPromises[this.type] = this.initWidgetType(this.type);- }+ this.children.push(typeWidget);+ this.$widget.append(typeWidget.render());++ typeWidget.eventReceived('setTabContext', {tabContext: this.tabContext});+ }- await this.typeWidgetPromises[this.type];- } while (foundType !== await this.getWidgetType());+ this.setupClasses();}setupClasses() {@@ -130,18 +135,6 @@ export default class NoteDetailWidget extends TabAwareWidget {return this.typeWidgets[this.type];}-- async initWidgetType(type) {- const clazz = await import(typeWidgetClasses[type]);-- const typeWidget = this.typeWidgets[type] = new clazz.default(this.appContext);- typeWidget.spacedUpdate = this.spacedUpdate;-- this.children.push(typeWidget);- this.$widget.append(typeWidget.render());-- typeWidget.eventReceived('setTabContext', {tabContext: this.tabContext});- }async getWidgetType() {const note = this.note;@@ -228,4 +221,11 @@ export default class NoteDetailWidget extends TabAwareWidget {autoBookDisabledListener() {this.refresh();}++ async triggerChildren(name, data) {+ // done manually in refresh()+ if (name !== 'setTabContext') {+ await super.triggerChildren(name, data);+ }+ }}\ No newline at end of filediff --git a/src/public/javascripts/widgets/tab_caching_widget.js b/src/public/javascripts/widgets/tab_caching_widget.jsindex 8052f6123d..494f12cc50 100644--- a/src/public/javascripts/widgets/tab_caching_widget.js+++ b/src/public/javascripts/widgets/tab_caching_widget.js@@ -20,7 +20,7 @@ export default class TabCachingWidget extends TabAwareWidget {// stop propagation of the event to the children, individual tab widget should not know about tab switching// since they are per-tabif (name !== 'activeTabChanged') {- super.triggerChildren(name, data);+ await super.triggerChildren(name, data);}}diff --git a/src/public/javascripts/widgets/type_widgets/relation_map.js b/src/public/javascripts/widgets/type_widgets/relation_map.jsindex bca4c29c45..58299e6251 100644--- a/src/public/javascripts/widgets/type_widgets/relation_map.js+++ b/src/public/javascripts/widgets/type_widgets/relation_map.js@@ -6,7 +6,6 @@ import contextMenuWidget from "../../services/context_menu.js";import toastService from "../../services/toast.js";import attributeAutocompleteService from "../../services/attribute_autocomplete.js";import TypeWidget from "./type_widget.js";-import appContext from "../../services/app_context.js";const uniDirectionalOverlays = [[ "Arrow", {diff --git a/src/public/javascripts/widgets/type_widgets/text.js b/src/public/javascripts/widgets/type_widgets/text.jsindex b3de1207eb..71033ec134 100644--- a/src/public/javascripts/widgets/type_widgets/text.js+++ b/src/public/javascripts/widgets/type_widgets/text.js@@ -1,5 +1,4 @@import libraryLoader from "../../services/library_loader.js";-import treeService from '../../services/tree.js';import noteAutocompleteService from '../../services/note_autocomplete.js';import mimeTypesService from '../../services/mime_types.js';import TypeWidget from "./type_widget.js";@@ -137,7 +136,7 @@ export default class TextTypeWidget extends TypeWidget {}}- async doRefresh(note) {+ async doRefresh(note) {console.trace("UPDATE###" + this.componentId);this.textEditor.isReadOnly = await note.hasLabel('readOnly');const noteComplement = await this.tabContext.getNoteComplement();diff --git a/src/public/javascripts/widgets/type_widgets/type_widget.js b/src/public/javascripts/widgets/type_widgets/type_widget.jsindex 429da3d49d..c5edd622dc 100644--- a/src/public/javascripts/widgets/type_widgets/type_widget.js+++ b/src/public/javascripts/widgets/type_widgets/type_widget.js@@ -19,10 +19,13 @@ export default class TypeWidget extends TabAwareWidget {&& (widgetType !== 'protected-session' || !note.isProtected))) {this.toggle(false);- return;+ this.cleanup();}+ else {+ this.toggle(true);- this.doRefresh(note);+ this.doRefresh(note);+ }}isActive() {