diff --git a/src/public/javascripts/services/keyboard_actions.js b/src/public/javascripts/services/keyboard_actions.js
index 8b473658a..4126c3ab2 100644
--- a/src/public/javascripts/services/keyboard_actions.js
+++ b/src/public/javascripts/services/keyboard_actions.js
@@ -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));
}
}
diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.js
index 43d7e6e68..edff6f6fd 100644
--- a/src/public/javascripts/services/tab_context.js
+++ b/src/public/javascripts/services/tab_context.js
@@ -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() {
diff --git a/src/public/javascripts/widgets/component.js b/src/public/javascripts/widgets/component.js
index 59d3fcdab..3b05a9bc1 100644
--- a/src/public/javascripts/widgets/component.js
+++ b/src/public/javascripts/widgets/component.js
@@ -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) {
diff --git a/src/public/javascripts/widgets/flex_container.js b/src/public/javascripts/widgets/flex_container.js
index cc8854f22..cfe56b697 100644
--- a/src/public/javascripts/widgets/flex_container.js
+++ b/src/public/javascripts/widgets/flex_container.js
@@ -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));
diff --git a/src/public/javascripts/widgets/layout.js b/src/public/javascripts/widgets/layout.js
index f3ee05afe..e2ed8254f 100644
--- a/src/public/javascripts/widgets/layout.js
+++ b/src/public/javascripts/widgets/layout.js
@@ -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)
])
])
}
diff --git a/src/public/javascripts/widgets/note_detail.js b/src/public/javascripts/widgets/note_detail.js
index 79ad4d414..f42708091 100644
--- a/src/public/javascripts/widgets/note_detail.js
+++ b/src/public/javascripts/widgets/note_detail.js
@@ -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 = `
@@ -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);
diff --git a/src/public/javascripts/widgets/note_tree.js b/src/public/javascripts/widgets/note_tree.js
index 59bcdf805..8dd54194a 100644
--- a/src/public/javascripts/widgets/note_tree.js
+++ b/src/public/javascripts/widgets/note_tree.js
@@ -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 = `
@@ -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);
}
}
diff --git a/src/public/javascripts/widgets/side_pane_container.js b/src/public/javascripts/widgets/side_pane_container.js
index e8c17b2df..7227d55a9 100644
--- a/src/public/javascripts/widgets/side_pane_container.js
+++ b/src/public/javascripts/widgets/side_pane_container.js
@@ -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;
}
diff --git a/src/public/javascripts/widgets/standard_top_widget.js b/src/public/javascripts/widgets/standard_top_widget.js
index 1c067fd79..5f6979437 100644
--- a/src/public/javascripts/widgets/standard_top_widget.js
+++ b/src/public/javascripts/widgets/standard_top_widget.js
@@ -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());
diff --git a/src/public/javascripts/widgets/tab_aware_widget.js b/src/public/javascripts/widgets/tab_aware_widget.js
index 0d6ac543e..c6eff4f1b 100644
--- a/src/public/javascripts/widgets/tab_aware_widget.js
+++ b/src/public/javascripts/widgets/tab_aware_widget.js
@@ -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();
diff --git a/src/public/javascripts/widgets/tab_caching_widget.js b/src/public/javascripts/widgets/tab_caching_widget.js
index af2b9a719..6dcc37f90 100644
--- a/src/public/javascripts/widgets/tab_caching_widget.js
+++ b/src/public/javascripts/widgets/tab_caching_widget.js
@@ -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 = {};
diff --git a/src/public/javascripts/widgets/tab_row.js b/src/public/javascripts/widgets/tab_row.js
index 258c8107d..851613fe4 100644
--- a/src/public/javascripts/widgets/tab_row.js
+++ b/src/public/javascripts/widgets/tab_row.js
@@ -9,6 +9,7 @@ import BasicWidget from "./basic_widget.js";
import contextMenuService from "../services/context_menu.js";
import utils from "../services/utils.js";
import keyboardActionService from "../services/keyboard_actions.js";
+import appContext from "../services/app_context.js";
!function(i, e){"function"==typeof define&&define.amd?define("jquery-bridget/jquery-bridget",["jquery"],function(t){return e(i,t)}):"object"==typeof module&&module.exports?module.exports=e(i,require("jquery")):i.jQueryBridget=e(i,i.jQuery)}(window,function(t, i){"use strict";var c=Array.prototype.slice,e=t.console,p=void 0===e?function(){}:function(t){e.error(t)};function n(d, o, u){(u=u||i||t.jQuery)&&(o.prototype.option||(o.prototype.option=function(t){u.isPlainObject(t)&&(this.options=u.extend(!0,this.options,t))}),u.fn[d]=function(t){if("string"==typeof t){var i=c.call(arguments,1);return s=i,a="$()."+d+'("'+(r=t)+'")',(e=this).each(function(t, i){var e=u.data(i,d);if(e){var n=e[r];if(n&&"_"!=r.charAt(0)){var o=n.apply(e,s);h=void 0===h?o:h}else p(a+" is not a valid method")}else p(d+" not initialized. Cannot call methods, i.e. "+a)}),void 0!==h?h:e}var e,r,s,h,a,n;return n=t,this.each(function(t, i){var e=u.data(i,d);e?(e.option(n),e._init()):(e=new o(i,n),u.data(i,d,e))}),this},r(u))}function r(t){!t||t&&t.bridget||(t.bridget=n)}return r(i||t.jQuery),n}),function(t, i){"use strict";"function"==typeof define&&define.amd?define("get-size/get-size",[],function(){return i()}):"object"==typeof module&&module.exports?module.exports=i():t.getSize=i()}(window,function(){"use strict";function m(t){var i=parseFloat(t);return-1==t.indexOf("%")&&!isNaN(i)&&i}var e="undefined"==typeof console?function(){}:function(t){console.error(t)},y=["paddingLeft","paddingRight","paddingTop","paddingBottom","marginLeft","marginRight","marginTop","marginBottom","borderLeftWidth","borderRightWidth","borderTopWidth","borderBottomWidth"],b=y.length;function E(t){var i=getComputedStyle(t);return i||e("Style returned "+i+". Are you running this code in a hidden iframe on Firefox? See http://bit.ly/getsizebug1"),i}var _,x=!1;function P(t){if(function(){if(!x){x=!0;var t=document.createElement("div");t.style.width="200px",t.style.padding="1px 2px 3px 4px",t.style.borderStyle="solid",t.style.borderWidth="1px 2px 3px 4px",t.style.boxSizing="border-box";var i=document.body||document.documentElement;i.appendChild(t);var e=E(t);P.isBoxSizeOuter=_=200==m(e.width),i.removeChild(t)}}(),"string"==typeof t&&(t=document.querySelector(t)),t&&"object"==typeof t&&t.nodeType){var i=E(t);if("none"==i.display)return function(){for(var t={width:0,height:0,innerWidth:0,innerHeight:0,outerWidth:0,outerHeight:0},i=0; i this.tabManager.removeTab($tab.attr('data-tab-id')));
+ .on('click', _ => appContext.tabManager.removeTab($tab.attr('data-tab-id')));
$tab.on('mousedown', e => {
if (e.which === 2) {
- this.tabManager.removeTab($tab.attr('data-tab-id'));
+ appContext.tabManager.removeTab($tab.attr('data-tab-id'));
return true; // event has been handled
}
@@ -410,7 +411,7 @@ export default class TabRowWidget extends BasicWidget {
}
activeTabChangedListener() {
- const newActiveTabId = this.tabManager.activeTabId;
+ const newActiveTabId = appContext.tabManager.activeTabId;
const tabEl = this.getTabById(newActiveTabId)[0];
const activeTabEl = this.activeTabEl;
@@ -482,7 +483,7 @@ export default class TabRowWidget extends BasicWidget {
this.draggabillies.push(draggabilly);
draggabilly.on('pointerDown', _ => {
- this.tabManager.activateTab(tabEl.getAttribute('data-tab-id'));
+ appContext.tabManager.activateTab(tabEl.getAttribute('data-tab-id'));
});
draggabilly.on('dragStart', _ => {
@@ -577,7 +578,7 @@ export default class TabRowWidget extends BasicWidget {
tabNoteSwitchedListener({tabId}) {
const $tab = this.getTabById(tabId);
- const {note} = this.tabManager.getTabContextById(tabId);
+ const {note} = appContext.tabManager.getTabContextById(tabId);
this.updateTab($tab, note);
}
@@ -601,7 +602,7 @@ export default class TabRowWidget extends BasicWidget {
}
async entitiesReloadedListener({loadResults}) {
- for (const tabContext of this.tabManager.tabContexts) {
+ for (const tabContext of appContext.tabManager.tabContexts) {
if (loadResults.isNoteReloaded(tabContext.noteId)) {
const $tab = this.getTabById(tabContext.tabId);
@@ -611,7 +612,7 @@ export default class TabRowWidget extends BasicWidget {
}
treeCacheReloadedListener() {
- for (const tabContext of this.tabManager.tabContexts) {
+ for (const tabContext of appContext.tabManager.tabContexts) {
const $tab = this.getTabById(tabContext.tabId);
this.updateTab($tab, tabContext.note);
diff --git a/src/public/javascripts/widgets/type_widgets/empty.js b/src/public/javascripts/widgets/type_widgets/empty.js
index 7ab1b6f8b..5316040b9 100644
--- a/src/public/javascripts/widgets/type_widgets/empty.js
+++ b/src/public/javascripts/widgets/type_widgets/empty.js
@@ -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";
diff --git a/src/public/javascripts/widgets/type_widgets/relation_map.js b/src/public/javascripts/widgets/type_widgets/relation_map.js
index 58299e625..5114d17b3 100644
--- a/src/public/javascripts/widgets/type_widgets/relation_map.js
+++ b/src/public/javascripts/widgets/type_widgets/relation_map.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") {