mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	components now track their parent
This commit is contained in:
		| @@ -47,7 +47,7 @@ class AppContext { | ||||
|         ]; | ||||
|  | ||||
|         if (utils.isElectron()) { | ||||
|             this.components.push(new ZoomService(this)); | ||||
|             this.components.push(new ZoomService(this, this)); | ||||
|  | ||||
|             import("./spell_check.js").then(spellCheckService => spellCheckService.initSpellCheck()); | ||||
|         } | ||||
|   | ||||
| @@ -8,8 +8,8 @@ import appContext from "./app_context.js"; | ||||
| import Component from "../widgets/component.js"; | ||||
|  | ||||
| export default class Entrypoints extends Component { | ||||
|     constructor(appContext) { | ||||
|         super(appContext); | ||||
|     constructor(appContext, parent) { | ||||
|         super(appContext, parent); | ||||
|  | ||||
|         // hot keys are active also inside inputs and content editables | ||||
|         jQuery.hotkeys.options.filterInputAcceptingElements = false; | ||||
|   | ||||
| @@ -15,7 +15,7 @@ class TabContext extends Component { | ||||
|      * @param {string|null} tabId | ||||
|      */ | ||||
|     constructor(appContext, tabId = null) { | ||||
|         super(appContext); | ||||
|         super(appContext, parent); | ||||
|  | ||||
|         this.tabId = tabId || utils.randomString(4); | ||||
|  | ||||
|   | ||||
| @@ -8,8 +8,8 @@ import utils from "./utils.js"; | ||||
| import TabContext from "./tab_context.js"; | ||||
|  | ||||
| export default class TabManager extends Component { | ||||
|     constructor(appContext) { | ||||
|         super(appContext); | ||||
|     constructor(appContext, parent) { | ||||
|         super(appContext, parent); | ||||
|  | ||||
|         this.activeTabId = null; | ||||
|  | ||||
|   | ||||
| @@ -5,8 +5,8 @@ const MIN_ZOOM = 0.5; | ||||
| const MAX_ZOOM = 2.0; | ||||
|  | ||||
| export default class ZoomService extends Component { | ||||
|     constructor(appContext) { | ||||
|         super(appContext); | ||||
|     constructor(appContext, parent) { | ||||
|         super(appContext, parent); | ||||
|  | ||||
|         this.setZoomFactor(options.getFloat('zoomFactor')); | ||||
|     } | ||||
|   | ||||
| @@ -2,11 +2,16 @@ import utils from '../services/utils.js'; | ||||
| import Mutex from "../services/mutex.js"; | ||||
|  | ||||
| export default class Component { | ||||
|     /** @param {AppContext} appContext */ | ||||
|     constructor(appContext) { | ||||
|     /** | ||||
|      * @param {AppContext} appContext | ||||
|      * @param {Component} parent | ||||
|      */ | ||||
|     constructor(appContext, 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[] */ | ||||
| @@ -59,4 +64,8 @@ export default class Component { | ||||
|  | ||||
|         await Promise.all(promises); | ||||
|     } | ||||
|  | ||||
|     triggerCommand(name, data) { | ||||
|  | ||||
|     } | ||||
| } | ||||
| @@ -1,11 +1,11 @@ | ||||
| import BasicWidget from "./basic_widget.js"; | ||||
|  | ||||
| export default class FlexContainer extends BasicWidget { | ||||
|     constructor(appContext, attrs, widgets) { | ||||
|         super(appContext); | ||||
|     constructor(appContext, parent, attrs, widgetFactories) { | ||||
|         super(appContext, parent); | ||||
|  | ||||
|         this.attrs = attrs; | ||||
|         this.children = widgets; | ||||
|         this.children = widgetFactories.map(wf => wf(this)); | ||||
|     } | ||||
|  | ||||
|     doRender() { | ||||
|   | ||||
| @@ -28,42 +28,42 @@ import SidePaneToggles from "./side_pane_toggles.js"; | ||||
|  | ||||
| export default class Layout { | ||||
|     getRootWidget(appContext) { | ||||
|         return new FlexContainer(appContext, { 'flex-direction': 'column', 'height': '100vh' }, [ | ||||
|             new FlexContainer(appContext, { 'flex-direction': 'row' }, [ | ||||
|                 new GlobalMenuWidget(appContext), | ||||
|                 new TabRowWidget(appContext), | ||||
|                 new TitleBarButtonsWidget(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) | ||||
|             ]), | ||||
|             new StandardTopWidget(appContext), | ||||
|             new FlexContainer(appContext, { 'flex-direction': 'row', 'overflow': 'hidden' }, [ | ||||
|                 new SidePaneContainer(appContext, 'left', [ | ||||
|                     new GlobalButtonsWidget(appContext), | ||||
|                     new SearchBoxWidget(appContext), | ||||
|                     new SearchResultsWidget(appContext), | ||||
|                     new NoteTreeWidget(appContext) | ||||
|             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) | ||||
|                 ]), | ||||
|                 new FlexContainer(appContext, { id: 'center-pane', 'flex-direction': 'column' }, [ | ||||
|                     new FlexContainer(appContext, { 'flex-direction': 'row' }, [ | ||||
|                         new TabCachingWidget(appContext, () => new NotePathsWidget(appContext)), | ||||
|                         new NoteTitleWidget(appContext), | ||||
|                         new RunScriptButtonsWidget(appContext), | ||||
|                         new ProtectedNoteSwitchWidget(appContext), | ||||
|                         new NoteTypeWidget(appContext), | ||||
|                         new NoteActionsWidget(appContext) | ||||
|                 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) | ||||
|                     ]), | ||||
|                     new TabCachingWidget(appContext, () => new PromotedAttributesWidget(appContext)), | ||||
|                     new TabCachingWidget(appContext, () => new NoteDetailWidget(appContext)) | ||||
|                     parent => new TabCachingWidget(appContext, parent, parent => new PromotedAttributesWidget(appContext, parent)), | ||||
|                     parent => new TabCachingWidget(appContext, parent, parent => new NoteDetailWidget(appContext, parent)) | ||||
|                 ]), | ||||
|                 new SidePaneContainer(appContext, 'right', [ | ||||
|                     new NoteInfoWidget(appContext), | ||||
|                     new TabCachingWidget(appContext, () => new CalendarWidget(appContext)), | ||||
|                     new TabCachingWidget(appContext, () => new AttributesWidget(appContext)), | ||||
|                     new TabCachingWidget(appContext, () => new LinkMapWidget(appContext)), | ||||
|                     new TabCachingWidget(appContext, () => new NoteRevisionsWidget(appContext)), | ||||
|                     new TabCachingWidget(appContext, () => new SimilarNotesWidget(appContext)), | ||||
|                     new TabCachingWidget(appContext, () => new WhatLinksHereWidget(appContext)) | ||||
|                 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)) | ||||
|                 ]), | ||||
|                 new SidePaneToggles(appContext) | ||||
|                 parent => new SidePaneToggles(appContext, parent) | ||||
|             ]) | ||||
|         ]) | ||||
|     } | ||||
|   | ||||
| @@ -39,8 +39,8 @@ const typeWidgetClasses = { | ||||
| }; | ||||
|  | ||||
| export default class NoteDetailWidget extends TabAwareWidget { | ||||
|     constructor(appContext) { | ||||
|         super(appContext); | ||||
|     constructor(appContext, parent) { | ||||
|         super(appContext, parent); | ||||
|  | ||||
|         this.typeWidgets = {}; | ||||
|  | ||||
|   | ||||
| @@ -25,8 +25,8 @@ const TPL = ` | ||||
| </div>`; | ||||
|  | ||||
| export default class NoteTitleWidget extends TabAwareWidget { | ||||
|     constructor(appContext) { | ||||
|         super(appContext); | ||||
|     constructor(appContext, parent) { | ||||
|         super(appContext, parent); | ||||
|  | ||||
|         this.spacedUpdate = new SpacedUpdate(async () => { | ||||
|             const title = this.$noteTitle.val(); | ||||
|   | ||||
| @@ -29,8 +29,8 @@ const TPL = ` | ||||
| `; | ||||
|  | ||||
| export default class NoteTreeWidget extends TabAwareWidget { | ||||
|     constructor(appContext) { | ||||
|         super(appContext); | ||||
|     constructor(appContext, parent) { | ||||
|         super(appContext, parent); | ||||
|  | ||||
|         window.glob.cutIntoNote = () => this.cutIntoNoteListener(); | ||||
|  | ||||
|   | ||||
| @@ -2,11 +2,10 @@ import options from "../services/options.js"; | ||||
| import FlexContainer from "./flex_container.js"; | ||||
|  | ||||
| export default class SidePaneContainer extends FlexContainer { | ||||
|     constructor(appContext, side, widgets) { | ||||
|         super(appContext, {id: side + '-pane', 'flex-direction': 'column', 'height': '100%'}, widgets); | ||||
|     constructor(appContext, parent, side, widgetFactories) { | ||||
|         super(appContext, parent, {id: side + '-pane', 'flex-direction': 'column', 'height': '100%'}, widgetFactories); | ||||
|  | ||||
|         this.side = side; | ||||
|         this.children = widgets; | ||||
|     } | ||||
|  | ||||
|     isEnabled() { | ||||
|   | ||||
| @@ -29,8 +29,8 @@ const TPL = ` | ||||
| `; | ||||
|  | ||||
| export default class SidePaneToggles extends BasicWidget { | ||||
|     constructor(appContext) { | ||||
|         super(appContext); | ||||
|     constructor(appContext, parent) { | ||||
|         super(appContext, parent); | ||||
|  | ||||
|         this.paneVisible = {}; | ||||
|     } | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| import TabAwareWidget from "./tab_aware_widget.js"; | ||||
|  | ||||
| export default class TabCachingWidget extends TabAwareWidget { | ||||
|     constructor(appContext, widgetFactory) { | ||||
|         super(appContext); | ||||
|     constructor(appContext, parent, widgetFactory) { | ||||
|         super(appContext, parent); | ||||
|  | ||||
|         this.widgetFactory = widgetFactory; | ||||
|         this.widgets = {}; | ||||
| @@ -38,7 +38,7 @@ export default class TabCachingWidget extends TabAwareWidget { | ||||
|         let widget = this.widgets[this.tabContext.tabId]; | ||||
|  | ||||
|         if (!widget) { | ||||
|             widget = this.widgets[this.tabContext.tabId] = this.widgetFactory(); | ||||
|             widget = this.widgets[this.tabContext.tabId] = this.widgetFactory(this); | ||||
|             this.children.push(widget); | ||||
|             this.$widget.after(widget.render()); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user