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