2021-05-22 12:35:41 +02:00
|
|
|
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
2020-11-25 23:18:30 +01:00
|
|
|
import NoteListRenderer from "../services/note_list_renderer.js";
|
2025-01-28 14:13:21 +02:00
|
|
|
import type FNote from "../entities/fnote.js";
|
2025-04-13 21:18:43 +03:00
|
|
|
import type { CommandListener, CommandListenerData, EventData } from "../components/app_context.js";
|
2025-02-16 13:22:44 +02:00
|
|
|
import type ViewMode from "./view_widgets/view_mode.js";
|
2020-11-25 23:18:30 +01:00
|
|
|
|
2025-04-01 23:24:21 +03:00
|
|
|
const TPL = /*html*/`
|
2020-11-25 23:18:30 +01:00
|
|
|
<div class="note-list-widget">
|
2020-11-26 23:00:27 +01:00
|
|
|
<style>
|
|
|
|
.note-list-widget {
|
|
|
|
min-height: 0;
|
2020-12-13 20:13:57 +01:00
|
|
|
overflow: auto;
|
2020-11-26 23:00:27 +01:00
|
|
|
}
|
2025-01-28 14:13:21 +02:00
|
|
|
|
2020-12-13 23:27:42 +01:00
|
|
|
.note-list-widget .note-list {
|
|
|
|
padding: 10px;
|
|
|
|
}
|
2025-02-21 17:17:53 +02:00
|
|
|
|
|
|
|
.note-list-widget.full-height,
|
|
|
|
.note-list-widget.full-height .note-list-widget-content {
|
|
|
|
height: 100%;
|
|
|
|
}
|
2025-02-26 19:36:30 +02:00
|
|
|
|
|
|
|
.note-list-widget video {
|
|
|
|
height: 100%;
|
|
|
|
}
|
2020-11-26 23:00:27 +01:00
|
|
|
</style>
|
2025-01-28 14:13:21 +02:00
|
|
|
|
2020-11-26 23:00:27 +01:00
|
|
|
<div class="note-list-widget-content">
|
|
|
|
</div>
|
2020-11-25 23:18:30 +01:00
|
|
|
</div>`;
|
|
|
|
|
2021-05-22 12:35:41 +02:00
|
|
|
export default class NoteListWidget extends NoteContextAwareWidget {
|
2025-01-28 14:13:21 +02:00
|
|
|
|
|
|
|
private $content!: JQuery<HTMLElement>;
|
|
|
|
private isIntersecting?: boolean;
|
|
|
|
private noteIdRefreshed?: string;
|
|
|
|
private shownNoteId?: string | null;
|
2025-02-16 13:22:44 +02:00
|
|
|
private viewMode?: ViewMode | null;
|
2025-01-28 14:13:21 +02:00
|
|
|
|
2020-11-25 23:18:30 +01:00
|
|
|
isEnabled() {
|
2025-01-28 14:13:21 +02:00
|
|
|
return super.isEnabled() && this.noteContext?.hasNoteList();
|
2020-11-25 23:18:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
doRender() {
|
|
|
|
this.$widget = $(TPL);
|
2021-06-15 21:53:22 +02:00
|
|
|
this.contentSized();
|
2025-01-09 18:07:02 +02:00
|
|
|
this.$content = this.$widget.find(".note-list-widget-content");
|
2020-12-27 22:19:27 +01:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
const observer = new IntersectionObserver(
|
|
|
|
(entries) => {
|
|
|
|
this.isIntersecting = entries[0].isIntersecting;
|
2020-12-27 22:19:27 +01:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
this.checkRenderStatus();
|
|
|
|
},
|
|
|
|
{
|
|
|
|
rootMargin: "50px",
|
|
|
|
threshold: 0.1
|
|
|
|
}
|
|
|
|
);
|
2020-12-27 22:19:27 +01:00
|
|
|
|
2023-08-14 00:06:51 +02:00
|
|
|
// there seems to be a race condition on Firefox which triggers the observer only before the widget is visible
|
|
|
|
// (intersection is false). https://github.com/zadam/trilium/issues/4165
|
|
|
|
setTimeout(() => observer.observe(this.$widget[0]), 10);
|
2020-12-27 22:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
checkRenderStatus() {
|
2021-01-18 22:52:07 +01:00
|
|
|
// console.log("this.isIntersecting", this.isIntersecting);
|
|
|
|
// console.log(`${this.noteIdRefreshed} === ${this.noteId}`, this.noteIdRefreshed === this.noteId);
|
|
|
|
// console.log("this.shownNoteId !== this.noteId", this.shownNoteId !== this.noteId);
|
|
|
|
|
2025-01-28 14:13:21 +02:00
|
|
|
if (this.note && this.isIntersecting && this.noteIdRefreshed === this.noteId && this.shownNoteId !== this.noteId) {
|
2020-12-27 22:19:27 +01:00
|
|
|
this.shownNoteId = this.noteId;
|
|
|
|
this.renderNoteList(this.note);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-28 14:13:21 +02:00
|
|
|
async renderNoteList(note: FNote) {
|
2020-12-27 22:19:27 +01:00
|
|
|
const noteListRenderer = new NoteListRenderer(this.$content, note, note.getChildNoteIds());
|
2025-02-21 17:17:53 +02:00
|
|
|
this.$widget.toggleClass("full-height", noteListRenderer.isFullHeight);
|
2020-12-27 22:19:27 +01:00
|
|
|
await noteListRenderer.renderList();
|
2025-02-16 13:22:44 +02:00
|
|
|
this.viewMode = noteListRenderer.viewMode;
|
2020-11-25 23:18:30 +01:00
|
|
|
}
|
|
|
|
|
2021-02-05 23:19:43 +01:00
|
|
|
async refresh() {
|
|
|
|
this.shownNoteId = null;
|
|
|
|
|
|
|
|
await super.refresh();
|
|
|
|
}
|
|
|
|
|
2025-01-28 14:13:21 +02:00
|
|
|
async refreshNoteListEvent({ noteId }: EventData<"refreshNoteList">) {
|
|
|
|
if (this.isNote(noteId) && this.note) {
|
2021-09-29 13:19:21 +02:00
|
|
|
await this.renderNoteList(this.note);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-18 22:52:07 +01:00
|
|
|
/**
|
|
|
|
* We have this event so that we evaluate intersection only after note detail is loaded.
|
2023-06-30 11:18:34 +02:00
|
|
|
* If it's evaluated before note detail, then it's clearly intersected (visible) although after note detail load
|
2021-01-18 22:52:07 +01:00
|
|
|
* it is not intersected (visible) anymore.
|
|
|
|
*/
|
2025-01-28 14:13:21 +02:00
|
|
|
noteDetailRefreshedEvent({ ntxId }: EventData<"noteDetailRefreshed">) {
|
2021-05-22 12:42:34 +02:00
|
|
|
if (!this.isNoteContext(ntxId)) {
|
2020-12-27 22:19:27 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.noteIdRefreshed = this.noteId;
|
2020-11-25 23:18:30 +01:00
|
|
|
|
2020-12-27 22:19:27 +01:00
|
|
|
setTimeout(() => this.checkRenderStatus(), 100);
|
2020-11-25 23:18:30 +01:00
|
|
|
}
|
|
|
|
|
2025-01-28 14:13:21 +02:00
|
|
|
notesReloadedEvent({ noteIds }: EventData<"notesReloaded">) {
|
|
|
|
if (this.noteId && noteIds.includes(this.noteId)) {
|
2020-11-26 23:00:27 +01:00
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
}
|
2021-05-27 23:17:13 +02:00
|
|
|
|
2025-02-16 13:22:44 +02:00
|
|
|
entitiesReloadedEvent(e: EventData<"entitiesReloaded">) {
|
|
|
|
if (e.loadResults.getAttributeRows().find((attr) => attr.noteId === this.noteId && attr.name && ["viewType", "expanded", "pageSize"].includes(attr.name))) {
|
2025-02-16 19:17:15 +02:00
|
|
|
this.refresh();
|
2021-05-27 23:17:13 +02:00
|
|
|
this.checkRenderStatus();
|
|
|
|
}
|
2025-02-16 13:22:44 +02:00
|
|
|
|
2025-02-21 17:52:11 +02:00
|
|
|
// Inform the view mode of changes and refresh if needed.
|
|
|
|
if (this.viewMode && this.viewMode.onEntitiesReloaded(e)) {
|
|
|
|
this.refresh();
|
|
|
|
this.checkRenderStatus();
|
2025-02-16 13:22:44 +02:00
|
|
|
}
|
2021-05-27 23:17:13 +02:00
|
|
|
}
|
2025-04-13 21:18:43 +03:00
|
|
|
|
|
|
|
buildTouchBarCommand(data: CommandListenerData<"buildTouchBar">) {
|
|
|
|
if (this.viewMode && "buildTouchBarCommand" in this.viewMode) {
|
|
|
|
return (this.viewMode as CommandListener<"buildTouchBar">).buildTouchBarCommand(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-25 23:18:30 +01:00
|
|
|
}
|