mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	removed sidebar code
This commit is contained in:
		
							parent
							
								
									c9770573b2
								
							
						
					
					
						commit
						f852e1de81
					
				@ -27,7 +27,6 @@ import noteAutocompleteService from './services/note_autocomplete.js';
 | 
			
		||||
import macInit from './services/mac_init.js';
 | 
			
		||||
import cssLoader from './services/css_loader.js';
 | 
			
		||||
import dateNoteService from './services/date_notes.js';
 | 
			
		||||
import sidebarService from './services/sidebar.js';
 | 
			
		||||
import importService from './services/import.js';
 | 
			
		||||
import keyboardActionService from "./services/keyboard_actions.js";
 | 
			
		||||
import splitService from "./services/split.js";
 | 
			
		||||
@ -222,4 +221,40 @@ optionService.waitForOptions().then(options => {
 | 
			
		||||
            remote.BrowserWindow.getFocusedWindow().close();
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const rightPane = $("#right-pane");
 | 
			
		||||
 | 
			
		||||
const $showRightPaneButton = $("#show-right-pane-button");
 | 
			
		||||
const $hideRightPaneButton = $("#hide-right-pane-button");
 | 
			
		||||
 | 
			
		||||
optionService.waitForOptions().then(options => toggleSidebar(options.is('rightPaneVisible')));
 | 
			
		||||
 | 
			
		||||
function toggleSidebar(show) {
 | 
			
		||||
    rightPane.toggle(show);
 | 
			
		||||
    $showRightPaneButton.toggle(!show);
 | 
			
		||||
    $hideRightPaneButton.toggle(show);
 | 
			
		||||
 | 
			
		||||
    if (show) {
 | 
			
		||||
        splitService.setupSplitWithSidebar();
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        splitService.setupSplitWithoutSidebar();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
$hideRightPaneButton.on('click', () => {
 | 
			
		||||
    toggleSidebar(false);
 | 
			
		||||
 | 
			
		||||
    server.put('options/rightPaneVisible/false');
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
$showRightPaneButton.on('click', async () => {
 | 
			
		||||
    toggleSidebar(true);
 | 
			
		||||
 | 
			
		||||
    await server.put('options/rightPaneVisible/true');
 | 
			
		||||
 | 
			
		||||
    const {sidebar} = appContext.getActiveTabContext();
 | 
			
		||||
    await sidebar.noteLoaded();
 | 
			
		||||
    sidebar.show();
 | 
			
		||||
});
 | 
			
		||||
@ -1,172 +0,0 @@
 | 
			
		||||
import bundleService from "./bundle.js";
 | 
			
		||||
import ws from "./ws.js";
 | 
			
		||||
import optionsService from "./options.js";
 | 
			
		||||
import splitService from "./split.js";
 | 
			
		||||
import optionService from "./options.js";
 | 
			
		||||
import server from "./server.js";
 | 
			
		||||
import noteDetailService from "./note_detail.js";
 | 
			
		||||
 | 
			
		||||
const $sidebar = $("#right-pane");
 | 
			
		||||
const $sidebarContainer = $('#sidebar-container');
 | 
			
		||||
 | 
			
		||||
const $showSidebarButton = $("#show-sidebar-button");
 | 
			
		||||
const $hideSidebarButton = $("#hide-sidebar-button");
 | 
			
		||||
 | 
			
		||||
optionService.waitForOptions().then(options => toggleSidebar(options.is('rightPaneVisible')));
 | 
			
		||||
 | 
			
		||||
function toggleSidebar(show) {
 | 
			
		||||
    $sidebar.toggle(show);
 | 
			
		||||
    $showSidebarButton.toggle(!show);
 | 
			
		||||
    $hideSidebarButton.toggle(show);
 | 
			
		||||
 | 
			
		||||
    if (show) {
 | 
			
		||||
        splitService.setupSplitWithSidebar();
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        splitService.setupSplitWithoutSidebar();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
$hideSidebarButton.on('click', () => {
 | 
			
		||||
    toggleSidebar(false);
 | 
			
		||||
 | 
			
		||||
    server.put('options/rightPaneVisible/false');
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
$showSidebarButton.on('click', async () => {
 | 
			
		||||
    toggleSidebar(true);
 | 
			
		||||
 | 
			
		||||
    await server.put('options/rightPaneVisible/true');
 | 
			
		||||
 | 
			
		||||
    const {sidebar} = appContext.getActiveTabContext();
 | 
			
		||||
    await sidebar.noteLoaded();
 | 
			
		||||
    sidebar.show();
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
class Sidebar {
 | 
			
		||||
    /**
 | 
			
		||||
     * @param {TabContext} ctx
 | 
			
		||||
     * @param {object} state
 | 
			
		||||
     */
 | 
			
		||||
    constructor(ctx, state = {}) {
 | 
			
		||||
        /** @property {TabContext} */
 | 
			
		||||
        this.ctx = ctx;
 | 
			
		||||
        this.state = Object.assign({
 | 
			
		||||
            widgets: []
 | 
			
		||||
        }, state);
 | 
			
		||||
        this.widgets = [];
 | 
			
		||||
 | 
			
		||||
        this.$widgetContainer = $sidebar.find(`.sidebar-widget-container[data-tab-id=${this.ctx.tabId}]`);
 | 
			
		||||
 | 
			
		||||
        if (this.$widgetContainer.length === 0) {
 | 
			
		||||
            this.$widgetContainer = $(`<div class="sidebar-widget-container">`).attr('data-tab-id', this.ctx.tabId);
 | 
			
		||||
 | 
			
		||||
            $sidebarContainer.append(this.$widgetContainer);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    isVisible() {
 | 
			
		||||
        return $sidebar.css("display") !== "none";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    getSidebarState() {
 | 
			
		||||
        return {
 | 
			
		||||
            visible: this.isVisible(),
 | 
			
		||||
            widgets: this.widgets.map(w => w.getWidgetState())
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async noteLoaded() {
 | 
			
		||||
        if (!this.isVisible() || !this.ctx.note) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        const widgetClasses = (await Promise.all([
 | 
			
		||||
            import("../widgets/note_info.js"),
 | 
			
		||||
            import("../widgets/link_map.js"),
 | 
			
		||||
            import("../widgets/note_revisions.js"),
 | 
			
		||||
            import("../widgets/attributes.js"),
 | 
			
		||||
            import("../widgets/what_links_here.js"),
 | 
			
		||||
            import("../widgets/similar_notes.js"),
 | 
			
		||||
            import("../widgets/edited_notes.js"),
 | 
			
		||||
            import("../widgets/calendar.js")
 | 
			
		||||
        ])).map(m => m.default);
 | 
			
		||||
 | 
			
		||||
        const options = await optionsService.waitForOptions();
 | 
			
		||||
 | 
			
		||||
        const widgetRelations = await this.ctx.note.getRelations('widget');
 | 
			
		||||
 | 
			
		||||
        for (const widgetRelation of widgetRelations) {
 | 
			
		||||
            const widgetClass = await bundleService.getAndExecuteBundle(widgetRelation.value, this.ctx.note);
 | 
			
		||||
 | 
			
		||||
            widgetClasses.push(widgetClass);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        const widgets = [];
 | 
			
		||||
 | 
			
		||||
        for (const widgetClass of widgetClasses) {
 | 
			
		||||
            try {
 | 
			
		||||
                const widget = new widgetClass(this.ctx, options, this.state);
 | 
			
		||||
 | 
			
		||||
                if (await widget.isEnabled()) {
 | 
			
		||||
                    widgets.push(widget);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            catch (e) {
 | 
			
		||||
                ws.logError(`Error while creating widget ${widgetClass.name}: ${e.message}`);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        this.renderWidgets(widgets);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    show() {
 | 
			
		||||
        $sidebarContainer.find('.sidebar-widget-container').each((i, el) => {
 | 
			
		||||
            $(el).toggle($(el).attr('data-tab-id') === this.ctx.tabId);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // it's important that this method is sync so that the whole render-update is atomic
 | 
			
		||||
    // otherwise we could get race issues (doubled widgets etc.)
 | 
			
		||||
    renderWidgets(widgets) {
 | 
			
		||||
        // cleanup old widgets
 | 
			
		||||
        for (const widget of this.widgets) {
 | 
			
		||||
            if (widget.cleanup) {
 | 
			
		||||
                widget.cleanup();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        this.widgets = widgets;
 | 
			
		||||
        this.widgets.sort((a, b) => a.getPosition() < b.getPosition() ? -1 : 1);
 | 
			
		||||
 | 
			
		||||
        const widgetsToAppend = [];
 | 
			
		||||
 | 
			
		||||
        for (const widget of this.widgets) {
 | 
			
		||||
            try {
 | 
			
		||||
                const $el = widget.render();
 | 
			
		||||
                widgetsToAppend.push($el);
 | 
			
		||||
            } catch (e) {
 | 
			
		||||
                ws.logError(`Error while rendering widget ${widget.widgetName}: ${e.message}`);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // update at once to reduce flickering
 | 
			
		||||
        this.$widgetContainer.empty().append(...widgetsToAppend);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    remove() {
 | 
			
		||||
        if (this.$widgetContainer) {
 | 
			
		||||
            this.$widgetContainer.remove();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    eventReceived(name, data) {
 | 
			
		||||
        for (const widget of this.widgets) {
 | 
			
		||||
            if (widget.eventReceived) {
 | 
			
		||||
                widget.eventReceived(name, data);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default Sidebar;
 | 
			
		||||
@ -175,7 +175,7 @@ body {
 | 
			
		||||
    border-color: var(--button-border-color);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#hide-sidebar-button, #show-sidebar-button {
 | 
			
		||||
#hide-right-pane-button, #show-right-pane-button {
 | 
			
		||||
    position: fixed;
 | 
			
		||||
    bottom: 10px;
 | 
			
		||||
    right: 10px;
 | 
			
		||||
 | 
			
		||||
@ -138,8 +138,8 @@
 | 
			
		||||
 | 
			
		||||
        <div id="center-pane"></div>
 | 
			
		||||
 | 
			
		||||
        <button id="hide-sidebar-button" class="btn btn-sm icon-button bx bx-chevrons-right hide-in-zen-mode" title="Hide sidebar"></button>
 | 
			
		||||
        <button id="show-sidebar-button" class="btn btn-sm icon-button bx bx-chevrons-left hide-in-zen-mode" title="Show sidebar"></button>
 | 
			
		||||
        <button id="hide-right-pane-button" class="btn btn-sm icon-button bx bx-chevrons-right hide-in-zen-mode" title="Hide sidebar"></button>
 | 
			
		||||
        <button id="show-right-pane-button" class="btn btn-sm icon-button bx bx-chevrons-left hide-in-zen-mode" title="Show sidebar"></button>
 | 
			
		||||
 | 
			
		||||
        <div id="right-pane" class="hide-in-zen-mode">
 | 
			
		||||
            <div id="sidebar-container"></div>
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user