Notes/src/public/app/widgets/note_wrapper.ts

72 lines
2.1 KiB
TypeScript
Raw Normal View History

import FlexContainer from "./containers/flex_container.js";
import utils from "../services/utils.js";
import attributeService from "../services/attributes.js";
2025-02-08 21:42:12 +02:00
import type BasicWidget from "./basic_widget.js";
import type { EventData } from "../components/app_context.js";
import type NoteContext from "../components/note_context.js";
export default class NoteWrapperWidget extends FlexContainer<BasicWidget> {
private noteContext?: NoteContext;
constructor() {
2025-01-09 18:07:02 +02:00
super("column");
2025-01-09 18:07:02 +02:00
this.css("flex-grow", "1").collapsible();
}
2025-02-08 21:42:12 +02:00
setNoteContextEvent({ noteContext }: EventData<"setNoteContext">) {
this.noteContext = noteContext;
this.refresh();
}
noteSwitchedAndActivatedEvent() {
this.refresh();
}
noteSwitchedEvent() {
this.refresh();
}
activeContextChangedEvent() {
this.refresh();
}
refresh() {
2022-09-07 23:39:35 +02:00
const isHiddenExt = this.isHiddenExt(); // preserve through class reset
this.$widget.removeClass();
2022-09-07 23:39:35 +02:00
this.toggleExt(!isHiddenExt);
this.$widget.addClass("component note-split");
const note = this.noteContext?.note;
if (!note) {
return;
}
2025-01-20 18:45:56 +02:00
this.$widget.toggleClass("full-content-width", ["image", "mermaid", "book", "render", "canvas", "webView", "mindMap", "geoMap"].includes(note.type) || !!note?.isLabelTruthy("fullContentWidth"));
this.$widget.addClass(note.getCssClass());
this.$widget.addClass(utils.getNoteTypeClass(note.type));
this.$widget.addClass(utils.getMimeTypeClass(note.mime));
this.$widget.toggleClass("protected", note.isProtected);
}
2025-02-08 21:42:12 +02:00
async entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
// listening on changes of note.type and CSS class
const noteId = this.noteContext?.noteId;
2025-01-09 18:07:02 +02:00
if (
loadResults.isNoteReloaded(noteId) ||
loadResults.getAttributeRows().find((attr) => attr.type === "label" && attr.name === "cssClass" && attributeService.isAffecting(attr, this.noteContext?.note))
) {
this.refresh();
}
}
}