mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	refactor(client/ts): port two containers
This commit is contained in:
		
							parent
							
								
									13f7129717
								
							
						
					
					
						commit
						44811f4f4b
					
				@ -211,6 +211,9 @@ export type CommandMappings = {
 | 
			
		||||
 | 
			
		||||
    reEvaluateRightPaneVisibility: CommandData;
 | 
			
		||||
    runActiveNote: CommandData;
 | 
			
		||||
    scrollContainerToCommand: CommandData & {
 | 
			
		||||
        position: number;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    // Geomap
 | 
			
		||||
    deleteFromMap: { noteId: string },
 | 
			
		||||
 | 
			
		||||
@ -20,7 +20,7 @@ export default class RightPaneContainer extends FlexContainer<RightPanelWidget>
 | 
			
		||||
        return super.isEnabled() && !this.rightPaneHidden && this.children.length > 0 && !!this.children.find((ch) => ch.isEnabled() && ch.canBeShown());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    handleEventInChildren<T extends EventNames>(name: T, data: EventData<T>): Promise<unknown[] | unknown> | null {
 | 
			
		||||
    async handleEventInChildren<T extends EventNames>(name: T, data: EventData<T>) {
 | 
			
		||||
        const promise = super.handleEventInChildren(name, data);
 | 
			
		||||
 | 
			
		||||
        if (["activeContextChanged", "noteSwitchedAndActivated", "noteSwitched"].includes(name)) {
 | 
			
		||||
 | 
			
		||||
@ -1,50 +0,0 @@
 | 
			
		||||
import Container from "./container.js";
 | 
			
		||||
 | 
			
		||||
export default class ScrollingContainer extends Container {
 | 
			
		||||
    constructor() {
 | 
			
		||||
        super();
 | 
			
		||||
 | 
			
		||||
        this.class("scrolling-container");
 | 
			
		||||
        this.css("overflow", "auto");
 | 
			
		||||
        this.css("scroll-behavior", "smooth");
 | 
			
		||||
        this.css("position", "relative");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    setNoteContextEvent({ noteContext }) {
 | 
			
		||||
        /** @var {NoteContext} */
 | 
			
		||||
        this.noteContext = noteContext;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async noteSwitchedEvent({ noteContext, notePath }) {
 | 
			
		||||
        this.$widget.scrollTop(0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async noteSwitchedAndActivatedEvent({ noteContext, notePath }) {
 | 
			
		||||
        this.noteContext = noteContext;
 | 
			
		||||
 | 
			
		||||
        this.$widget.scrollTop(0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async activeContextChangedEvent({ noteContext }) {
 | 
			
		||||
        this.noteContext = noteContext;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    handleEventInChildren(name, data) {
 | 
			
		||||
        if (name === "readOnlyTemporarilyDisabled" && this.noteContext && this.noteContext.ntxId === data.noteContext.ntxId) {
 | 
			
		||||
            const scrollTop = this.$widget.scrollTop();
 | 
			
		||||
 | 
			
		||||
            const promise = super.handleEventInChildren(name, data);
 | 
			
		||||
 | 
			
		||||
            // there seems to be some asynchronicity, and we need to wait a bit before scrolling
 | 
			
		||||
            promise.then(() => setTimeout(() => this.$widget.scrollTop(scrollTop), 500));
 | 
			
		||||
 | 
			
		||||
            return promise;
 | 
			
		||||
        } else {
 | 
			
		||||
            return super.handleEventInChildren(name, data);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    scrollContainerToCommand({ position }) {
 | 
			
		||||
        this.$widget.scrollTop(position);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										57
									
								
								src/public/app/widgets/containers/scrolling_container.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								src/public/app/widgets/containers/scrolling_container.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,57 @@
 | 
			
		||||
import type { CommandListenerData, EventData, EventNames } from "../../components/app_context.js";
 | 
			
		||||
import type NoteContext from "../../components/note_context.js";
 | 
			
		||||
import type BasicWidget from "../basic_widget.js";
 | 
			
		||||
import Container from "./container.js";
 | 
			
		||||
 | 
			
		||||
export default class ScrollingContainer extends Container<BasicWidget> {
 | 
			
		||||
 | 
			
		||||
    private noteContext?: NoteContext;
 | 
			
		||||
 | 
			
		||||
    constructor() {
 | 
			
		||||
        super();
 | 
			
		||||
 | 
			
		||||
        this.class("scrolling-container");
 | 
			
		||||
        this.css("overflow", "auto");
 | 
			
		||||
        this.css("scroll-behavior", "smooth");
 | 
			
		||||
        this.css("position", "relative");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    setNoteContextEvent({ noteContext }: EventData<"setNoteContext">) {
 | 
			
		||||
        this.noteContext = noteContext;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async noteSwitchedEvent({ noteContext, notePath }: EventData<"noteSwitched">) {
 | 
			
		||||
        this.$widget.scrollTop(0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async noteSwitchedAndActivatedEvent({ noteContext, notePath }: EventData<"noteSwitchedAndActivatedEvent">) {
 | 
			
		||||
        this.noteContext = noteContext;
 | 
			
		||||
 | 
			
		||||
        this.$widget.scrollTop(0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async activeContextChangedEvent({ noteContext }: EventData<"activeContextChanged">) {
 | 
			
		||||
        this.noteContext = noteContext;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async handleEventInChildren<T extends EventNames>(name: T, data: EventData<T>) {
 | 
			
		||||
        if (name === "readOnlyTemporarilyDisabled" && this.noteContext && "noteContext" in data && this.noteContext.ntxId === data.noteContext?.ntxId) {
 | 
			
		||||
            const scrollTop = this.$widget.scrollTop() ?? 0;
 | 
			
		||||
 | 
			
		||||
            const promise = super.handleEventInChildren(name, data);
 | 
			
		||||
 | 
			
		||||
            // there seems to be some asynchronicity, and we need to wait a bit before scrolling
 | 
			
		||||
            if (promise) {
 | 
			
		||||
                promise.then(() => setTimeout(() => this.$widget.scrollTop(scrollTop), 500));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return promise;
 | 
			
		||||
        } else {
 | 
			
		||||
            return super.handleEventInChildren(name, data);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    scrollContainerToCommand({ position }: CommandListenerData<"scrollContainerToCommand">) {
 | 
			
		||||
        this.$widget.scrollTop(position);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user