mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	changes in note detail handling
This commit is contained in:
		
							parent
							
								
									25553c9e67
								
							
						
					
					
						commit
						789f62267c
					
				@ -4,6 +4,16 @@ import protectedSessionHolder from "../services/protected_session_holder.js";
 | 
				
			|||||||
import SpacedUpdate from "../services/spaced_update.js";
 | 
					import SpacedUpdate from "../services/spaced_update.js";
 | 
				
			||||||
import server from "../services/server.js";
 | 
					import server from "../services/server.js";
 | 
				
			||||||
import libraryLoader from "../services/library_loader.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 = `
 | 
					const TPL = `
 | 
				
			||||||
<div class="note-detail">
 | 
					<div class="note-detail">
 | 
				
			||||||
@ -16,16 +26,16 @@ const TPL = `
 | 
				
			|||||||
`;
 | 
					`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const typeWidgetClasses = {
 | 
					const typeWidgetClasses = {
 | 
				
			||||||
    'empty': "./type_widgets/empty.js",
 | 
					    'empty': EmptyTypeWidget,
 | 
				
			||||||
    'text': "./type_widgets/text.js",
 | 
					    'text': TextTypeWidget,
 | 
				
			||||||
    'code': "./type_widgets/code.js",
 | 
					    'code': CodeTypeWidget,
 | 
				
			||||||
    'file': "./type_widgets/file.js",
 | 
					    'file': FileTypeWidget,
 | 
				
			||||||
    'image': "./type_widgets/image.js",
 | 
					    'image': ImageTypeWidget,
 | 
				
			||||||
    'search': "./type_widgets/search.js",
 | 
					    'search': SearchTypeWidget,
 | 
				
			||||||
    'render': "./type_widgets/render.js",
 | 
					    'render': RenderTypeWidget,
 | 
				
			||||||
    'relation-map': "./type_widgets/relation_map.js",
 | 
					    'relation-map': RelationMapTypeWidget,
 | 
				
			||||||
    'protected-session': "./type_widgets/protected_session.js",
 | 
					    'protected-session': ProtectedSessionTypeWidget,
 | 
				
			||||||
    'book': "./type_widgets/book.js"
 | 
					    'book': BookTypeWidget
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default class NoteDetailWidget extends TabAwareWidget {
 | 
					export default class NoteDetailWidget extends TabAwareWidget {
 | 
				
			||||||
@ -33,7 +43,6 @@ export default class NoteDetailWidget extends TabAwareWidget {
 | 
				
			|||||||
        super(appContext);
 | 
					        super(appContext);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.typeWidgets = {};
 | 
					        this.typeWidgets = {};
 | 
				
			||||||
        this.typeWidgetPromises = {};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.spacedUpdate = new SpacedUpdate(async () => {
 | 
					        this.spacedUpdate = new SpacedUpdate(async () => {
 | 
				
			||||||
            const {note} = this.tabContext;
 | 
					            const {note} = this.tabContext;
 | 
				
			||||||
@ -77,34 +86,30 @@ export default class NoteDetailWidget extends TabAwareWidget {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async refresh() {
 | 
					    async refresh() {
 | 
				
			||||||
        await this.initType();
 | 
					        if (!this.isEnabled()) {
 | 
				
			||||||
 | 
					            this.toggle(false);
 | 
				
			||||||
        for (const typeWidget of Object.values(this.typeWidgets)) {
 | 
					            return;
 | 
				
			||||||
            if (typeWidget.constructor.getType() !== this.type) {
 | 
					 | 
				
			||||||
                typeWidget.cleanup();
 | 
					 | 
				
			||||||
                typeWidget.toggle(false);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.getTypeWidget().toggle(true);
 | 
					        this.toggle(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        this.type = await this.getWidgetType();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!(this.type in this.typeWidgets)) {
 | 
				
			||||||
 | 
					            const clazz = typeWidgetClasses[this.type];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            const typeWidget = this.typeWidgets[this.type] = new clazz(this.appContext);
 | 
				
			||||||
 | 
					            typeWidget.spacedUpdate = this.spacedUpdate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            this.children.push(typeWidget);
 | 
				
			||||||
 | 
					            this.$widget.append(typeWidget.render());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            typeWidget.eventReceived('setTabContext', {tabContext: this.tabContext});
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.setupClasses();
 | 
					        this.setupClasses();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async initType() {
 | 
					 | 
				
			||||||
        let foundType;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        do {
 | 
					 | 
				
			||||||
            foundType = this.type = await this.getWidgetType();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (!(this.type in this.typeWidgetPromises)) {
 | 
					 | 
				
			||||||
                this.typeWidgetPromises[this.type] = this.initWidgetType(this.type);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            await this.typeWidgetPromises[this.type];
 | 
					 | 
				
			||||||
        } while (foundType !== await this.getWidgetType());
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    setupClasses() {
 | 
					    setupClasses() {
 | 
				
			||||||
        for (const clazz of Array.from(this.$widget[0].classList)) { // create copy to safely iterate over while removing classes
 | 
					        for (const clazz of Array.from(this.$widget[0].classList)) { // create copy to safely iterate over while removing classes
 | 
				
			||||||
            if (clazz !== 'note-detail') {
 | 
					            if (clazz !== 'note-detail') {
 | 
				
			||||||
@ -130,18 +135,6 @@ export default class NoteDetailWidget extends TabAwareWidget {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        return this.typeWidgets[this.type];
 | 
					        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() {
 | 
					    async getWidgetType() {
 | 
				
			||||||
        const note = this.note;
 | 
					        const note = this.note;
 | 
				
			||||||
@ -228,4 +221,11 @@ export default class NoteDetailWidget extends TabAwareWidget {
 | 
				
			|||||||
    autoBookDisabledListener() {
 | 
					    autoBookDisabledListener() {
 | 
				
			||||||
        this.refresh();
 | 
					        this.refresh();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    async triggerChildren(name, data) {
 | 
				
			||||||
 | 
					        // done manually in refresh()
 | 
				
			||||||
 | 
					        if (name !== 'setTabContext') {
 | 
				
			||||||
 | 
					            await super.triggerChildren(name, data);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -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
 | 
					        // stop propagation of the event to the children, individual tab widget should not know about tab switching
 | 
				
			||||||
        // since they are per-tab
 | 
					        // since they are per-tab
 | 
				
			||||||
        if (name !== 'activeTabChanged') {
 | 
					        if (name !== 'activeTabChanged') {
 | 
				
			||||||
            super.triggerChildren(name, data);
 | 
					            await super.triggerChildren(name, data);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -6,7 +6,6 @@ import contextMenuWidget from "../../services/context_menu.js";
 | 
				
			|||||||
import toastService from "../../services/toast.js";
 | 
					import toastService from "../../services/toast.js";
 | 
				
			||||||
import attributeAutocompleteService from "../../services/attribute_autocomplete.js";
 | 
					import attributeAutocompleteService from "../../services/attribute_autocomplete.js";
 | 
				
			||||||
import TypeWidget from "./type_widget.js";
 | 
					import TypeWidget from "./type_widget.js";
 | 
				
			||||||
import appContext from "../../services/app_context.js";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
const uniDirectionalOverlays = [
 | 
					const uniDirectionalOverlays = [
 | 
				
			||||||
    [ "Arrow", {
 | 
					    [ "Arrow", {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,4 @@
 | 
				
			|||||||
import libraryLoader from "../../services/library_loader.js";
 | 
					import libraryLoader from "../../services/library_loader.js";
 | 
				
			||||||
import treeService from '../../services/tree.js';
 | 
					 | 
				
			||||||
import noteAutocompleteService from '../../services/note_autocomplete.js';
 | 
					import noteAutocompleteService from '../../services/note_autocomplete.js';
 | 
				
			||||||
import mimeTypesService from '../../services/mime_types.js';
 | 
					import mimeTypesService from '../../services/mime_types.js';
 | 
				
			||||||
import TypeWidget from "./type_widget.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');
 | 
					        this.textEditor.isReadOnly = await note.hasLabel('readOnly');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const noteComplement = await this.tabContext.getNoteComplement();
 | 
					        const noteComplement = await this.tabContext.getNoteComplement();
 | 
				
			||||||
 | 
				
			|||||||
@ -19,10 +19,13 @@ export default class TypeWidget extends TabAwareWidget {
 | 
				
			|||||||
                && (widgetType !== 'protected-session' || !note.isProtected))) {
 | 
					                && (widgetType !== 'protected-session' || !note.isProtected))) {
 | 
				
			||||||
            this.toggle(false);
 | 
					            this.toggle(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return;
 | 
					            this.cleanup();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        else {
 | 
				
			||||||
 | 
					            this.toggle(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.doRefresh(note);
 | 
					            this.doRefresh(note);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    isActive() {
 | 
					    isActive() {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user