123 lines
3.3 KiB
JavaScript
Raw Normal View History

2021-05-28 23:19:11 +02:00
import NoteContextAwareWidget from "../note_context_aware_widget.js";
2021-09-22 22:25:39 +02:00
import NoteMapWidget from "../note_map.js";
import { t } from "../../services/i18n.js";
2021-05-28 23:19:11 +02:00
const TPL = `
<div class="note-map-ribbon-widget">
2021-05-28 23:52:42 +02:00
<style>
.note-map-ribbon-widget {
2021-05-28 23:52:42 +02:00
position: relative;
}
.note-map-ribbon-widget .note-map-container {
2021-05-30 23:21:34 +02:00
height: 300px;
}
2021-05-28 23:52:42 +02:00
2021-05-31 21:20:30 +02:00
.open-full-button, .collapse-button {
2021-05-28 23:52:42 +02:00
position: absolute;
2021-05-31 21:20:30 +02:00
right: 5px;
bottom: 5px;
2021-05-28 23:52:42 +02:00
z-index: 1000;
}
2021-06-02 21:23:40 +02:00
.style-resolver {
color: var(--muted-text-color);
display: none;
}
2021-05-28 23:52:42 +02:00
</style>
<button class="bx bx-arrow-to-bottom icon-action open-full-button" title="${t("note_map.open_full")}"></button>
<button class="bx bx-arrow-to-top icon-action collapse-button" style="display: none;" title="${t("note_map.collapse")}"></button>
2021-05-28 23:52:42 +02:00
<div class="note-map-container"></div>
2021-05-28 23:19:11 +02:00
</div>`;
export default class NoteMapRibbonWidget extends NoteContextAwareWidget {
2021-09-22 22:25:39 +02:00
constructor() {
super();
2025-01-09 18:07:02 +02:00
this.noteMapWidget = new NoteMapWidget("ribbon");
2021-09-22 22:25:39 +02:00
this.child(this.noteMapWidget);
}
2021-06-27 12:53:05 +02:00
get name() {
return "noteMap";
2021-06-27 12:53:05 +02:00
}
get toggleCommand() {
return "toggleRibbonTabNoteMap";
}
2021-05-28 23:19:11 +02:00
getTitle() {
return {
show: this.isEnabled(),
title: t("note_map.title"),
2025-01-09 18:07:02 +02:00
icon: "bx bxs-network-chart"
2021-05-28 23:19:11 +02:00
};
}
doRender() {
this.$widget = $(TPL);
2021-06-13 22:55:31 +02:00
this.contentSized();
this.$container = this.$widget.find(".note-map-container");
2021-09-22 22:25:39 +02:00
this.$container.append(this.noteMapWidget.render());
2021-05-31 21:20:30 +02:00
2025-01-09 18:07:02 +02:00
this.openState = "small";
2021-05-31 23:38:47 +02:00
2025-01-09 18:07:02 +02:00
this.$openFullButton = this.$widget.find(".open-full-button");
this.$openFullButton.on("click", () => {
2021-05-31 23:38:47 +02:00
this.setFullHeight();
2021-05-31 21:20:30 +02:00
this.$openFullButton.hide();
this.$collapseButton.show();
2021-05-31 23:38:47 +02:00
2025-01-09 18:07:02 +02:00
this.openState = "full";
2021-09-22 22:25:39 +02:00
this.noteMapWidget.setDimensions();
2021-05-31 21:20:30 +02:00
});
2025-01-09 18:07:02 +02:00
this.$collapseButton = this.$widget.find(".collapse-button");
this.$collapseButton.on("click", () => {
2021-05-31 23:38:47 +02:00
this.setSmallSize();
2021-05-31 21:20:30 +02:00
this.$openFullButton.show();
this.$collapseButton.hide();
2021-05-31 23:38:47 +02:00
2025-01-09 18:07:02 +02:00
this.openState = "small";
2021-06-02 21:23:40 +02:00
this.noteMapWidget.setDimensions();
2021-09-22 22:25:39 +02:00
});
2021-05-31 23:38:47 +02:00
2023-04-06 20:59:09 +08:00
const handleResize = () => {
2025-01-09 18:07:02 +02:00
if (!this.noteMapWidget.graph) {
// no graph has been even rendered
2021-05-31 23:38:47 +02:00
return;
}
2025-01-09 18:07:02 +02:00
if (this.openState === "full") {
2021-05-31 23:38:47 +02:00
this.setFullHeight();
2025-01-09 18:07:02 +02:00
} else if (this.openState === "small") {
2021-05-31 23:38:47 +02:00
this.setSmallSize();
}
2025-01-09 18:07:02 +02:00
};
2023-04-06 20:59:09 +08:00
new ResizeObserver(handleResize).observe(this.$widget[0]);
2021-05-31 23:38:47 +02:00
}
setSmallSize() {
const SMALL_SIZE_HEIGHT = 300;
const width = this.$widget.width();
2025-01-09 18:07:02 +02:00
this.$widget.find(".note-map-container").height(SMALL_SIZE_HEIGHT).width(width);
2021-05-31 23:38:47 +02:00
}
setFullHeight() {
2025-01-09 18:07:02 +02:00
const { top } = this.$widget[0].getBoundingClientRect();
2021-05-31 23:38:47 +02:00
const height = $(window).height() - top;
const width = this.$widget.width();
2025-01-09 18:07:02 +02:00
this.$widget.find(".note-map-container").height(height).width(width);
2021-05-28 23:19:11 +02:00
}
}