mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
section widgets are updated lazily
This commit is contained in:
parent
aa901b67ed
commit
ef4bc13dd1
@ -20,8 +20,6 @@ const TPL = `
|
|||||||
}
|
}
|
||||||
|
|
||||||
.section-title {
|
.section-title {
|
||||||
padding-right: 10px;
|
|
||||||
padding-left: 10px;
|
|
||||||
color: var(--muted-text-color);
|
color: var(--muted-text-color);
|
||||||
border-bottom: 1px solid var(--main-border-color);
|
border-bottom: 1px solid var(--main-border-color);
|
||||||
}
|
}
|
||||||
@ -45,8 +43,13 @@ const TPL = `
|
|||||||
color: var(--main-text-color);
|
color: var(--main-text-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.section-title:first-of-type {
|
||||||
|
padding-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.section-title-empty {
|
.section-title-empty {
|
||||||
flex-basis: 20px;
|
flex-basis: 35px;
|
||||||
|
flex-shrink: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.section-title-empty:last-of-type {
|
.section-title-empty:last-of-type {
|
||||||
@ -152,6 +155,12 @@ export default class CollapsibleSectionContainer extends NoteContextAwareWidget
|
|||||||
|
|
||||||
this.lastActiveComponentId = sectionComponentId;
|
this.lastActiveComponentId = sectionComponentId;
|
||||||
|
|
||||||
|
const activeChild = this.getActiveChild();
|
||||||
|
|
||||||
|
if (activeChild) {
|
||||||
|
activeChild.handleEvent('noteSwitched', {noteContext: this.noteContext, notePath: this.notePath});
|
||||||
|
}
|
||||||
|
|
||||||
this.$titleContainer.find(`.section-title-real[data-section-component-id="${sectionComponentId}"]`).addClass("active");
|
this.$titleContainer.find(`.section-title-real[data-section-component-id="${sectionComponentId}"]`).addClass("active");
|
||||||
this.$bodyContainer.find(`.section-body[data-section-component-id="${sectionComponentId}"]`).addClass("active");
|
this.$bodyContainer.find(`.section-body[data-section-component-id="${sectionComponentId}"]`).addClass("active");
|
||||||
}
|
}
|
||||||
@ -211,6 +220,21 @@ export default class CollapsibleSectionContainer extends NoteContextAwareWidget
|
|||||||
this.refreshWithNote(this.note, true);
|
this.refreshWithNote(this.note, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async handleEventInChildren(name, data) {
|
||||||
|
if (['activeContextChanged', 'setNoteContext'].includes(name)) {
|
||||||
|
// won't trigger .refresh();
|
||||||
|
await super.handleEventInChildren('setNoteContext', data);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const activeChild = this.getActiveChild();
|
||||||
|
|
||||||
|
// forward events only to active section, inactive ones don't need to be updated
|
||||||
|
if (activeChild) {
|
||||||
|
await activeChild.handleEvent(name, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
entitiesReloadedEvent({loadResults}) {
|
entitiesReloadedEvent({loadResults}) {
|
||||||
if (loadResults.isNoteReloaded(this.noteId) && this.lastNoteType !== this.note.type) {
|
if (loadResults.isNoteReloaded(this.noteId) && this.lastNoteType !== this.note.type) {
|
||||||
// note type influences the list of available sections the most
|
// note type influences the list of available sections the most
|
||||||
@ -220,4 +244,8 @@ export default class CollapsibleSectionContainer extends NoteContextAwareWidget
|
|||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getActiveChild() {
|
||||||
|
return this.children.find(ch => ch.componentId === this.lastActiveComponentId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,22 +43,6 @@ export default class LinkMapWidget extends NoteContextAwareWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async refreshWithNote(note) {
|
async refreshWithNote(note) {
|
||||||
let shown = false;
|
|
||||||
|
|
||||||
const observer = new IntersectionObserver(entries => {
|
|
||||||
if (!shown && entries[0].isIntersecting) {
|
|
||||||
shown = true;
|
|
||||||
this.displayLinkMap(note);
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
rootMargin: '0px',
|
|
||||||
threshold: 0.1
|
|
||||||
});
|
|
||||||
|
|
||||||
observer.observe(this.$widget[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
async displayLinkMap(note) {
|
|
||||||
this.$widget.find(".link-map-container").empty();
|
this.$widget.find(".link-map-container").empty();
|
||||||
|
|
||||||
const $linkMapContainer = this.$widget.find('.link-map-container');
|
const $linkMapContainer = this.$widget.find('.link-map-container');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user