mirror of
https://github.com/zadam/trilium.git
synced 2025-01-16 20:21:43 +08:00
remove appContext as copied dependency across components
This commit is contained in:
parent
2c3f07521d
commit
22c042e21f
14 changed files with 71 additions and 73 deletions
|
@ -35,7 +35,7 @@ async function setupActionsForElement(scope, $el, component) {
|
|||
|
||||
getActionsForScope("window").then(actions => {
|
||||
for (const action of actions) {
|
||||
for (const shortcut of action.effectiveShortcuts) {console.log(`Binding ${shortcut} for ${action.actionName}`);
|
||||
for (const shortcut of action.effectiveShortcuts) {
|
||||
utils.bindGlobalShortcut(shortcut, () => appContext.triggerCommand(action.actionName));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import protectedSessionHolder from "./protected_session_holder.js";
|
||||
import server from "./server.js";
|
||||
import bundleService from "./bundle.js";
|
||||
import utils from "./utils.js";
|
||||
import optionsService from "./options.js";
|
||||
import appContext from "./app_context.js";
|
||||
import treeService from "./tree.js";
|
||||
import Component from "../widgets/component.js";
|
||||
|
@ -11,11 +9,11 @@ import hoistedNoteService from "./hoisted_note.js";
|
|||
|
||||
class TabContext extends Component {
|
||||
/**
|
||||
* @param {AppContext} appContext
|
||||
* @param {Component} parent
|
||||
* @param {string|null} tabId
|
||||
*/
|
||||
constructor(appContext, tabId = null) {
|
||||
super(appContext, parent);
|
||||
constructor(parent, tabId = null) {
|
||||
super(parent);
|
||||
|
||||
this.tabId = tabId || utils.randomString(4);
|
||||
|
||||
|
@ -85,7 +83,7 @@ class TabContext extends Component {
|
|||
}
|
||||
|
||||
isActive() {
|
||||
return this.tabManager.activeTabId === this.tabId;
|
||||
return appContext.tabManager.activeTabId === this.tabId;
|
||||
}
|
||||
|
||||
getTabState() {
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
import utils from '../services/utils.js';
|
||||
import Mutex from "../services/mutex.js";
|
||||
import appContext from "../services/app_context.js";
|
||||
|
||||
export default class Component {
|
||||
/**
|
||||
* @param {AppContext} appContext
|
||||
* @param {Component} parent
|
||||
*/
|
||||
constructor(appContext, parent) {
|
||||
constructor(parent) {
|
||||
this.componentId = `comp-${this.constructor.name}-` + utils.randomString(6);
|
||||
/** @type AppContext */
|
||||
this.appContext = appContext;
|
||||
/** @type Component */
|
||||
this.parent = parent;
|
||||
/** @type TabManager */
|
||||
this.tabManager = appContext.tabManager;
|
||||
/** @type Component[] */
|
||||
this.children = [];
|
||||
this.initialized = Promise.resolve();
|
||||
|
@ -39,7 +35,7 @@ export default class Component {
|
|||
}
|
||||
|
||||
async trigger(name, data) {
|
||||
await this.appContext.trigger(name, data);
|
||||
await appContext.trigger(name, data);
|
||||
}
|
||||
|
||||
async triggerChildren(name, data) {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import BasicWidget from "./basic_widget.js";
|
||||
|
||||
export default class FlexContainer extends BasicWidget {
|
||||
constructor(appContext, parent, attrs, widgetFactories) {
|
||||
super(appContext, parent);
|
||||
constructor(parent, attrs, widgetFactories) {
|
||||
super(parent);
|
||||
|
||||
this.attrs = attrs;
|
||||
this.children = widgetFactories.map(wf => wf(this));
|
||||
|
|
|
@ -28,42 +28,42 @@ import SidePaneToggles from "./side_pane_toggles.js";
|
|||
|
||||
export default class Layout {
|
||||
getRootWidget(appContext) {
|
||||
return new FlexContainer(appContext, appContext, { 'flex-direction': 'column', 'height': '100vh' }, [
|
||||
parent => new FlexContainer(appContext, parent, { 'flex-direction': 'row' }, [
|
||||
parent => new GlobalMenuWidget(appContext, parent),
|
||||
parent => new TabRowWidget(appContext, parent),
|
||||
parent => new TitleBarButtonsWidget(appContext, parent)
|
||||
return new FlexContainer(appContext, { 'flex-direction': 'column', 'height': '100vh' }, [
|
||||
parent => new FlexContainer(parent, { 'flex-direction': 'row' }, [
|
||||
parent => new GlobalMenuWidget(parent),
|
||||
parent => new TabRowWidget(parent),
|
||||
parent => new TitleBarButtonsWidget(parent)
|
||||
]),
|
||||
parent => new StandardTopWidget(appContext, parent),
|
||||
parent => new FlexContainer(appContext, parent, { 'flex-direction': 'row', 'overflow': 'hidden' }, [
|
||||
parent => new SidePaneContainer(appContext, parent, 'left', [
|
||||
parent => new GlobalButtonsWidget(appContext, parent),
|
||||
parent => new SearchBoxWidget(appContext, parent),
|
||||
parent => new SearchResultsWidget(appContext, parent),
|
||||
parent => new NoteTreeWidget(appContext, parent)
|
||||
parent => new StandardTopWidget(parent),
|
||||
parent => new FlexContainer(parent, { 'flex-direction': 'row', 'overflow': 'hidden' }, [
|
||||
parent => new SidePaneContainer(parent, 'left', [
|
||||
parent => new GlobalButtonsWidget(parent),
|
||||
parent => new SearchBoxWidget(parent),
|
||||
parent => new SearchResultsWidget(parent),
|
||||
parent => new NoteTreeWidget(parent)
|
||||
]),
|
||||
parent => new FlexContainer(appContext, parent, { id: 'center-pane', 'flex-direction': 'column' }, [
|
||||
parent => new FlexContainer(appContext, parent, { 'flex-direction': 'row' }, [
|
||||
parent => new TabCachingWidget(appContext, parent, parent => new NotePathsWidget(appContext, parent)),
|
||||
parent => new NoteTitleWidget(appContext, parent),
|
||||
parent => new RunScriptButtonsWidget(appContext, parent),
|
||||
parent => new ProtectedNoteSwitchWidget(appContext, parent),
|
||||
parent => new NoteTypeWidget(appContext, parent),
|
||||
parent => new NoteActionsWidget(appContext, parent)
|
||||
parent => new FlexContainer(parent, { id: 'center-pane', 'flex-direction': 'column' }, [
|
||||
parent => new FlexContainer(parent, { 'flex-direction': 'row' }, [
|
||||
parent => new TabCachingWidget(parent, parent => new NotePathsWidget(parent)),
|
||||
parent => new NoteTitleWidget(parent),
|
||||
parent => new RunScriptButtonsWidget(parent),
|
||||
parent => new ProtectedNoteSwitchWidget(parent),
|
||||
parent => new NoteTypeWidget(parent),
|
||||
parent => new NoteActionsWidget(parent)
|
||||
]),
|
||||
parent => new TabCachingWidget(appContext, parent, parent => new PromotedAttributesWidget(appContext, parent)),
|
||||
parent => new TabCachingWidget(appContext, parent, parent => new NoteDetailWidget(appContext, parent))
|
||||
parent => new TabCachingWidget(parent, parent => new PromotedAttributesWidget(parent)),
|
||||
parent => new TabCachingWidget(parent, parent => new NoteDetailWidget(parent))
|
||||
]),
|
||||
parent => new SidePaneContainer(appContext, parent, 'right', [
|
||||
parent => new NoteInfoWidget(appContext, parent),
|
||||
parent => new TabCachingWidget(appContext, parent, parent => new CalendarWidget(appContext, parent)),
|
||||
parent => new TabCachingWidget(appContext, parent, parent => new AttributesWidget(appContext, parent)),
|
||||
parent => new TabCachingWidget(appContext, parent, parent => new LinkMapWidget(appContext, parent)),
|
||||
parent => new TabCachingWidget(appContext, parent, parent => new NoteRevisionsWidget(appContext, parent)),
|
||||
parent => new TabCachingWidget(appContext, parent, parent => new SimilarNotesWidget(appContext, parent)),
|
||||
parent => new TabCachingWidget(appContext, parent, parent => new WhatLinksHereWidget(appContext, parent))
|
||||
parent => new SidePaneContainer(parent, 'right', [
|
||||
parent => new NoteInfoWidget(parent),
|
||||
parent => new TabCachingWidget(parent, parent => new CalendarWidget(parent)),
|
||||
parent => new TabCachingWidget(parent, parent => new AttributesWidget(parent)),
|
||||
parent => new TabCachingWidget(parent, parent => new LinkMapWidget(parent)),
|
||||
parent => new TabCachingWidget(parent, parent => new NoteRevisionsWidget(parent)),
|
||||
parent => new TabCachingWidget(parent, parent => new SimilarNotesWidget(parent)),
|
||||
parent => new TabCachingWidget(parent, parent => new WhatLinksHereWidget(parent))
|
||||
]),
|
||||
parent => new SidePaneToggles(appContext, parent)
|
||||
parent => new SidePaneToggles(parent)
|
||||
])
|
||||
])
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ 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";
|
||||
import appContext from "../services/app_context.js";
|
||||
|
||||
const TPL = `
|
||||
<div class="note-detail">
|
||||
|
@ -39,8 +40,8 @@ const typeWidgetClasses = {
|
|||
};
|
||||
|
||||
export default class NoteDetailWidget extends TabAwareWidget {
|
||||
constructor(appContext, parent) {
|
||||
super(appContext, parent);
|
||||
constructor(parent) {
|
||||
super(parent);
|
||||
|
||||
this.typeWidgets = {};
|
||||
|
||||
|
@ -63,7 +64,7 @@ export default class NoteDetailWidget extends TabAwareWidget {
|
|||
this.$widget.on("dragleave", e => e.preventDefault());
|
||||
|
||||
this.$widget.on("drop", async e => {
|
||||
const activeNote = this.tabManager.getActiveTabNote();
|
||||
const activeNote = appContext.tabManager.getActiveTabNote();
|
||||
|
||||
if (!activeNote) {
|
||||
return;
|
||||
|
@ -98,7 +99,7 @@ export default class NoteDetailWidget extends TabAwareWidget {
|
|||
if (!(this.type in this.typeWidgets)) {
|
||||
const clazz = typeWidgetClasses[this.type];
|
||||
|
||||
const typeWidget = this.typeWidgets[this.type] = new clazz(this.appContext, this);
|
||||
const typeWidget = this.typeWidgets[this.type] = new clazz(this);
|
||||
typeWidget.spacedUpdate = this.spacedUpdate;
|
||||
|
||||
this.children.push(typeWidget);
|
||||
|
|
|
@ -12,6 +12,7 @@ import TabAwareWidget from "./tab_aware_widget.js";
|
|||
import server from "../services/server.js";
|
||||
import noteCreateService from "../services/note_create.js";
|
||||
import toastService from "../services/toast.js";
|
||||
import appContext from "../services/app_context.js";
|
||||
|
||||
const TPL = `
|
||||
<div class="tree">
|
||||
|
@ -51,7 +52,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
|||
const notePath = treeService.getNotePath(node);
|
||||
|
||||
if (notePath) {
|
||||
const tabContext = this.tabManager.openEmptyTab();
|
||||
const tabContext = appContext.tabManager.openEmptyTab();
|
||||
tabContext.setNote(notePath);
|
||||
}
|
||||
|
||||
|
@ -85,10 +86,10 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
|||
node.setFocus(true);
|
||||
}
|
||||
else if (event.ctrlKey) {
|
||||
const tabContext = this.tabManager.openEmptyTab();
|
||||
const tabContext = appContext.tabManager.openEmptyTab();
|
||||
const notePath = treeService.getNotePath(node);
|
||||
tabContext.setNote(notePath);
|
||||
this.tabManager.activateTab(tabContext.tabId);
|
||||
appContext.tabManager.activateTab(tabContext.tabId);
|
||||
}
|
||||
else {
|
||||
node.setActive();
|
||||
|
@ -105,7 +106,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
|||
|
||||
const notePath = treeService.getNotePath(data.node);
|
||||
|
||||
const activeTabContext = this.tabManager.getActiveTabContext();
|
||||
const activeTabContext = appContext.tabManager.getActiveTabContext();
|
||||
await activeTabContext.setNote(notePath);
|
||||
},
|
||||
expand: (event, data) => this.setExpandedToServer(data.node.data.branchId, true),
|
||||
|
@ -285,7 +286,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
|||
}
|
||||
|
||||
async scrollToActiveNoteListener() {
|
||||
const activeContext = this.tabManager.getActiveTabContext();
|
||||
const activeContext = appContext.tabManager.getActiveTabContext();
|
||||
|
||||
if (activeContext && activeContext.notePath) {
|
||||
this.tree.setFocus();
|
||||
|
@ -542,7 +543,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
|||
}
|
||||
|
||||
if (activeNotePath) {
|
||||
this.tabManager.getActiveTabContext().setNote(activeNotePath);
|
||||
appContext.tabManager.getActiveTabContext().setNote(activeNotePath);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@ import options from "../services/options.js";
|
|||
import FlexContainer from "./flex_container.js";
|
||||
|
||||
export default class SidePaneContainer extends FlexContainer {
|
||||
constructor(appContext, parent, side, widgetFactories) {
|
||||
super(appContext, parent, {id: side + '-pane', 'flex-direction': 'column', 'height': '100%'}, widgetFactories);
|
||||
constructor(parent, side, widgetFactories) {
|
||||
super(parent, {id: side + '-pane', 'flex-direction': 'column', 'height': '100%'}, widgetFactories);
|
||||
|
||||
this.side = side;
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ export default class StandardTopWidget extends BasicWidget {
|
|||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
|
||||
const historyNavigationWidget = new HistoryNavigationWidget(this.appContext);
|
||||
const historyNavigationWidget = new HistoryNavigationWidget(this);
|
||||
|
||||
this.$widget.prepend(historyNavigationWidget.render());
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import BasicWidget from "./basic_widget.js";
|
||||
import appContext from "../services/app_context.js";
|
||||
|
||||
export default class TabAwareWidget extends BasicWidget {
|
||||
setTabContextListener({tabContext}) {
|
||||
|
@ -68,7 +69,7 @@ export default class TabAwareWidget extends BasicWidget {
|
|||
refreshWithNote(note, notePath) {}
|
||||
|
||||
activeTabChangedListener() {
|
||||
this.tabContext = this.tabManager.getActiveTabContext();
|
||||
this.tabContext = appContext.tabManager.getActiveTabContext();
|
||||
|
||||
this.activeTabChanged();
|
||||
}
|
||||
|
@ -79,7 +80,7 @@ export default class TabAwareWidget extends BasicWidget {
|
|||
|
||||
lazyLoadedListener() {
|
||||
if (!this.tabContext) { // has not been loaded yet
|
||||
this.tabContext = this.tabManager.getActiveTabContext();
|
||||
this.tabContext = appContext.tabManager.getActiveTabContext();
|
||||
}
|
||||
|
||||
this.refresh();
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import TabAwareWidget from "./tab_aware_widget.js";
|
||||
|
||||
export default class TabCachingWidget extends TabAwareWidget {
|
||||
constructor(appContext, parent, widgetFactory) {
|
||||
super(appContext, parent);
|
||||
constructor(parent, widgetFactory) {
|
||||
super(parent);
|
||||
|
||||
this.widgetFactory = widgetFactory;
|
||||
this.widgets = {};
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,5 +1,4 @@
|
|||
import noteAutocompleteService from '../../services/note_autocomplete.js';
|
||||
import treeService from "../../services/tree.js";
|
||||
import TypeWidget from "./type_widget.js";
|
||||
import appContext from "../../services/app_context.js";
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ 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", {
|
||||
|
@ -195,7 +196,7 @@ export default class RelationMapTypeWidget extends TypeWidget {
|
|||
const noteId = this.idToNoteId($noteBox.prop("id"));
|
||||
|
||||
if (cmd === "open-in-new-tab") {
|
||||
const tabContext = this.tabManager.openEmptyTab();
|
||||
const tabContext = appContext.tabManager.openEmptyTab();
|
||||
tabContext.setNote(noteId);
|
||||
}
|
||||
else if (cmd === "remove") {
|
||||
|
|
Loading…
Reference in a new issue