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 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,34 +86,30 @@ 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.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();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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() {
 | 
			
		||||
        for (const clazz of Array.from(this.$widget[0].classList)) { // create copy to safely iterate over while removing classes
 | 
			
		||||
            if (clazz !== 'note-detail') {
 | 
			
		||||
@ -131,18 +136,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);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -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-tab
 | 
			
		||||
        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 attributeAutocompleteService from "../../services/attribute_autocomplete.js";
 | 
			
		||||
import TypeWidget from "./type_widget.js";
 | 
			
		||||
import appContext from "../../services/app_context.js";
 | 
			
		||||
 | 
			
		||||
const uniDirectionalOverlays = [
 | 
			
		||||
    [ "Arrow", {
 | 
			
		||||
 | 
			
		||||
@ -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();
 | 
			
		||||
 | 
			
		||||
@ -19,11 +19,14 @@ export default class TypeWidget extends TabAwareWidget {
 | 
			
		||||
                && (widgetType !== 'protected-session' || !note.isProtected))) {
 | 
			
		||||
            this.toggle(false);
 | 
			
		||||
 | 
			
		||||
            return;
 | 
			
		||||
            this.cleanup();
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            this.toggle(true);
 | 
			
		||||
 | 
			
		||||
            this.doRefresh(note);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    isActive() {
 | 
			
		||||
        return this.$widget.is(":visible");
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user