mirror of
https://github.com/TriliumNext/Trilium.git
synced 2025-12-10 03:53:37 -06:00
chore(react/type_widget): save direction upon button press
This commit is contained in:
parent
143e6a556c
commit
3417e37f16
@ -8,13 +8,10 @@ import "mind-elixir/style";
|
|||||||
import "@mind-elixir/node-menu/dist/style.css";
|
import "@mind-elixir/node-menu/dist/style.css";
|
||||||
import "./MindMap.css";
|
import "./MindMap.css";
|
||||||
import { useEditorSpacedUpdate } from "../react/hooks";
|
import { useEditorSpacedUpdate } from "../react/hooks";
|
||||||
|
import { refToJQuerySelector } from "../react/react_utils";
|
||||||
|
|
||||||
const NEW_TOPIC_NAME = "";
|
const NEW_TOPIC_NAME = "";
|
||||||
|
|
||||||
interface MindmapModel extends MindElixirData {
|
|
||||||
direction: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface MindElixirProps {
|
interface MindElixirProps {
|
||||||
apiRef?: RefObject<MindElixirInstance>;
|
apiRef?: RefObject<MindElixirInstance>;
|
||||||
direction: number;
|
direction: number;
|
||||||
@ -33,7 +30,7 @@ export default function MindMap({ note }: TypeWidgetProps) {
|
|||||||
let newContent: MindElixirData;
|
let newContent: MindElixirData;
|
||||||
if (content) {
|
if (content) {
|
||||||
try {
|
try {
|
||||||
newContent = JSON.parse(content) as MindmapModel;
|
newContent = JSON.parse(content) as MindElixirData;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(e);
|
console.warn(e);
|
||||||
console.debug("Wrong JSON content: ", content);
|
console.debug("Wrong JSON content: ", content);
|
||||||
@ -76,7 +73,7 @@ export default function MindMap({ note }: TypeWidgetProps) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function MindElixir({ content, containerProps, direction, apiRef: externalApiRef, onChange }: MindElixirProps) {
|
function MindElixir({ content, containerProps, apiRef: externalApiRef, onChange }: MindElixirProps) {
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
const apiRef = useRef<MindElixirInstance>(null);
|
const apiRef = useRef<MindElixirInstance>(null);
|
||||||
|
|
||||||
@ -84,8 +81,7 @@ function MindElixir({ content, containerProps, direction, apiRef: externalApiRef
|
|||||||
if (!containerRef.current) return;
|
if (!containerRef.current) return;
|
||||||
|
|
||||||
const mind = new VanillaMindElixir({
|
const mind = new VanillaMindElixir({
|
||||||
el: containerRef.current,
|
el: containerRef.current
|
||||||
direction
|
|
||||||
});
|
});
|
||||||
|
|
||||||
mind.install(nodeMenu);
|
mind.install(nodeMenu);
|
||||||
@ -109,7 +105,15 @@ function MindElixir({ content, containerProps, direction, apiRef: externalApiRef
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
apiRef.current?.bus.addListener("operation", listener);
|
apiRef.current?.bus.addListener("operation", listener);
|
||||||
return () => apiRef.current?.bus?.removeListener("operation", listener);
|
|
||||||
|
// Direction change buttons don't report change, so we have to hook in manually.
|
||||||
|
const $container = refToJQuerySelector(containerRef);
|
||||||
|
$container.on("click", ".mind-elixir-toolbar.lt", onChange);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
$container.off("click", ".mind-elixir-toolbar.lt", onChange);
|
||||||
|
apiRef.current?.bus?.removeListener("operation", listener);
|
||||||
|
};
|
||||||
}, [ onChange ]);
|
}, [ onChange ]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -15,15 +15,6 @@ export default class MindMapWidget extends TypeWidget {
|
|||||||
return "mindMap";
|
return "mindMap";
|
||||||
}
|
}
|
||||||
|
|
||||||
doRender() {
|
|
||||||
// Save the mind map if the user changes the layout direction.
|
|
||||||
this.$content.on("click", ".mind-elixir-toolbar.lt", () => {
|
|
||||||
this.spacedUpdate.scheduleUpdate();
|
|
||||||
});
|
|
||||||
|
|
||||||
super.doRender();
|
|
||||||
}
|
|
||||||
|
|
||||||
async doRefresh(note: FNote) {
|
async doRefresh(note: FNote) {
|
||||||
if (this.triggeredByUserOperation) {
|
if (this.triggeredByUserOperation) {
|
||||||
this.triggeredByUserOperation = false;
|
this.triggeredByUserOperation = false;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user