mirror of
https://github.com/zadam/trilium.git
synced 2025-11-11 17:08:58 +01:00
chore(react): reintroduce map type toggles
This commit is contained in:
parent
c127e19cfa
commit
20dcbff68f
@ -13,11 +13,6 @@ import type FNote from "../entities/fnote.js";
|
|||||||
const esc = utils.escapeHtml;
|
const esc = utils.escapeHtml;
|
||||||
|
|
||||||
const TPL = /*html*/`<div class="note-map-widget">
|
const TPL = /*html*/`<div class="note-map-widget">
|
||||||
<div class="btn-group btn-group-sm map-type-switcher content-floating-buttons top-left" role="group">
|
|
||||||
<button type="button" class="btn bx bx-network-chart tn-tool-button" title="${t("note-map.button-link-map")}" data-type="link"></button>
|
|
||||||
<button type="button" class="btn bx bx-sitemap tn-tool-button" title="${t("note-map.button-tree-map")}" data-type="tree"></button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- UI for dragging Notes and link force -->
|
<!-- UI for dragging Notes and link force -->
|
||||||
|
|
||||||
<div class="btn-group-sm fixnodes-type-switcher content-floating-buttons bottom-left" role="group">
|
<div class="btn-group-sm fixnodes-type-switcher content-floating-buttons bottom-left" role="group">
|
||||||
@ -63,12 +58,6 @@ export default class NoteMapWidget extends NoteContextAwareWidget {
|
|||||||
|
|
||||||
new ResizeObserver(() => this.setDimensions()).observe(this.$container[0]);
|
new ResizeObserver(() => this.setDimensions()).observe(this.$container[0]);
|
||||||
|
|
||||||
this.$widget.find(".map-type-switcher button").on("click", async (e) => {
|
|
||||||
const type = $(e.target).closest("button").attr("data-type");
|
|
||||||
|
|
||||||
await attributeService.setLabel(this.noteId ?? "", "mapType", type);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Reading the status of the Drag nodes Ui element. Changing it´s color when activated.
|
// Reading the status of the Drag nodes Ui element. Changing it´s color when activated.
|
||||||
// Reading Force value of the link distance.
|
// Reading Force value of the link distance.
|
||||||
this.$fixNodesButton.on("click", async (event) => {
|
this.$fixNodesButton.on("click", async (event) => {
|
||||||
|
|||||||
@ -7,6 +7,8 @@ import { useElementSize, useNoteContext, useNoteLabel } from "../react/hooks";
|
|||||||
import ForceGraph, { LinkObject, NodeObject } from "force-graph";
|
import ForceGraph, { LinkObject, NodeObject } from "force-graph";
|
||||||
import { loadNotesAndRelations, NotesAndRelationsData } from "./data";
|
import { loadNotesAndRelations, NotesAndRelationsData } from "./data";
|
||||||
import { CssData, setupRendering } from "./rendering";
|
import { CssData, setupRendering } from "./rendering";
|
||||||
|
import ActionButton from "../react/ActionButton";
|
||||||
|
import { t } from "../../services/i18n";
|
||||||
|
|
||||||
interface NoteMapProps {
|
interface NoteMapProps {
|
||||||
note: FNote;
|
note: FNote;
|
||||||
@ -19,8 +21,7 @@ type MapType = "tree" | "link";
|
|||||||
export default function NoteMap({ note, widgetMode, parentRef }: NoteMapProps) {
|
export default function NoteMap({ note, widgetMode, parentRef }: NoteMapProps) {
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
const styleResolverRef = useRef<HTMLDivElement>(null);
|
const styleResolverRef = useRef<HTMLDivElement>(null);
|
||||||
const [ cssData, setCssData ] = useState<CssData>();
|
const [ mapTypeRaw, setMapType ] = useNoteLabel(note, "mapType");
|
||||||
const [ mapTypeRaw ] = useNoteLabel(note, "mapType");
|
|
||||||
const mapType: MapType = mapTypeRaw === "tree" ? "tree" : "link";
|
const mapType: MapType = mapTypeRaw === "tree" ? "tree" : "link";
|
||||||
|
|
||||||
const graphRef = useRef<ForceGraph<NodeObject, LinkObject<NodeObject>>>();
|
const graphRef = useRef<ForceGraph<NodeObject, LinkObject<NodeObject>>>();
|
||||||
@ -35,7 +36,6 @@ export default function NoteMap({ note, widgetMode, parentRef }: NoteMapProps) {
|
|||||||
graphRef.current = graph;
|
graphRef.current = graph;
|
||||||
|
|
||||||
const mapRootId = getMapRootNoteId(note.noteId, note, widgetMode);
|
const mapRootId = getMapRootNoteId(note.noteId, note, widgetMode);
|
||||||
console.log("Map root ID ", mapRootId);
|
|
||||||
if (!mapRootId) return;
|
if (!mapRootId) return;
|
||||||
|
|
||||||
const labelValues = (name: string) => note.getLabels(name).map(l => l.value) ?? [];
|
const labelValues = (name: string) => note.getLabels(name).map(l => l.value) ?? [];
|
||||||
@ -56,7 +56,7 @@ export default function NoteMap({ note, widgetMode, parentRef }: NoteMapProps) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return () => container.replaceChildren();
|
return () => container.replaceChildren();
|
||||||
}, [ note ]);
|
}, [ note, mapType ]);
|
||||||
|
|
||||||
// React to container size
|
// React to container size
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -66,6 +66,24 @@ export default function NoteMap({ note, widgetMode, parentRef }: NoteMapProps) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="note-map-widget">
|
<div className="note-map-widget">
|
||||||
|
<div className="btn-group btn-group-sm map-type-switcher content-floating-buttons top-left" role="group">
|
||||||
|
<ActionButton
|
||||||
|
icon="bx bx-network-chart"
|
||||||
|
text={t("note-map.button-link-map")}
|
||||||
|
disabled={mapType === "link"}
|
||||||
|
onClick={() => setMapType("link")}
|
||||||
|
frame
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ActionButton
|
||||||
|
icon="bx bx-sitemap"
|
||||||
|
text={t("note-map.button-tree-map")}
|
||||||
|
disabled={mapType === "tree"}
|
||||||
|
onClick={() => setMapType("tree")}
|
||||||
|
frame
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div ref={styleResolverRef} class="style-resolver" />
|
<div ref={styleResolverRef} class="style-resolver" />
|
||||||
<div ref={containerRef} className="note-map-container" />
|
<div ref={containerRef} className="note-map-container" />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -12,9 +12,10 @@ export interface ActionButtonProps {
|
|||||||
triggerCommand?: CommandNames;
|
triggerCommand?: CommandNames;
|
||||||
noIconActionClass?: boolean;
|
noIconActionClass?: boolean;
|
||||||
frame?: boolean;
|
frame?: boolean;
|
||||||
|
disabled?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ActionButton({ text, icon, className, onClick, triggerCommand, titlePosition, noIconActionClass, frame }: ActionButtonProps) {
|
export default function ActionButton({ text, icon, className, onClick, triggerCommand, titlePosition, noIconActionClass, frame, disabled }: ActionButtonProps) {
|
||||||
const buttonRef = useRef<HTMLButtonElement>(null);
|
const buttonRef = useRef<HTMLButtonElement>(null);
|
||||||
const [ keyboardShortcut, setKeyboardShortcut ] = useState<string[]>();
|
const [ keyboardShortcut, setKeyboardShortcut ] = useState<string[]>();
|
||||||
|
|
||||||
@ -32,8 +33,9 @@ export default function ActionButton({ text, icon, className, onClick, triggerCo
|
|||||||
|
|
||||||
return <button
|
return <button
|
||||||
ref={buttonRef}
|
ref={buttonRef}
|
||||||
class={`${className ?? ""} ${!noIconActionClass ? "icon-action" : "btn"} ${icon} ${frame ? "btn btn-primary" : ""}`}
|
class={`${className ?? ""} ${!noIconActionClass ? "icon-action" : "btn"} ${icon} ${frame ? "btn btn-primary" : ""} ${disabled ? "disabled" : ""}`}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
data-trigger-command={triggerCommand}
|
data-trigger-command={triggerCommand}
|
||||||
|
disabled={disabled}
|
||||||
/>;
|
/>;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user