2025-08-22 23:47:02 +03:00
|
|
|
import { TabContext } from "./ribbon-interface";
|
|
|
|
|
import NoteMapWidget from "../note_map";
|
|
|
|
|
import { useLegacyWidget } from "../react/hooks";
|
2025-08-23 10:47:46 +03:00
|
|
|
import ActionButton from "../react/ActionButton";
|
|
|
|
|
import { t } from "../../services/i18n";
|
|
|
|
|
import { useEffect, useRef, useState } from "preact/hooks";
|
|
|
|
|
|
|
|
|
|
const SMALL_SIZE_HEIGHT = "300px";
|
2025-08-22 23:47:02 +03:00
|
|
|
|
|
|
|
|
export default function NoteMapTab({ note, noteContext }: TabContext) {
|
2025-08-23 10:47:46 +03:00
|
|
|
const [ isExpanded, setExpanded ] = useState(false);
|
|
|
|
|
const [ height, setHeight ] = useState(SMALL_SIZE_HEIGHT);
|
|
|
|
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
|
|
|
|
|
const [ noteMapContainer, noteMapWidget ] = useLegacyWidget(() => new NoteMapWidget("ribbon"), {
|
2025-08-22 23:47:02 +03:00
|
|
|
noteContext,
|
|
|
|
|
containerClassName: "note-map-container"
|
|
|
|
|
});
|
|
|
|
|
|
2025-08-23 10:47:46 +03:00
|
|
|
useEffect(() => noteMapWidget.setDimensions(), [ height ]);
|
|
|
|
|
|
|
|
|
|
function toggleExpanded(newValue: boolean) {
|
|
|
|
|
setExpanded(newValue);
|
|
|
|
|
|
|
|
|
|
if (newValue && containerRef.current) {
|
|
|
|
|
const { top } = containerRef.current.getBoundingClientRect();
|
|
|
|
|
const height = window.innerHeight - top;
|
|
|
|
|
setHeight(height + "px");
|
|
|
|
|
} else {
|
|
|
|
|
setHeight(SMALL_SIZE_HEIGHT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-22 23:47:02 +03:00
|
|
|
return (
|
2025-08-23 10:47:46 +03:00
|
|
|
<div className="note-map-ribbon-widget" style={{ height }} ref={containerRef}>
|
|
|
|
|
{noteMapContainer}
|
|
|
|
|
|
|
|
|
|
{!isExpanded ? (
|
|
|
|
|
<ActionButton
|
|
|
|
|
icon="bx bx-arrow-to-bottom"
|
|
|
|
|
text={t("note_map.open_full")}
|
|
|
|
|
className="open-full-button"
|
|
|
|
|
onClick={() => toggleExpanded(true)}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<ActionButton
|
|
|
|
|
icon="bx bx-arrow-to-top"
|
|
|
|
|
text={t("note_map.collapse")}
|
|
|
|
|
className="collapse-button"
|
|
|
|
|
onClick={() => toggleExpanded(false)}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2025-08-22 23:47:02 +03:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|