mirror of
https://github.com/zadam/trilium.git
synced 2025-10-09 23:18:46 +08:00
refactor(mindmap): use proper way to detect direction
See https://github.com/SSShooter/mind-elixir-core/issues/150.
This commit is contained in:
parent
cf37549f19
commit
df9d481a93
1 changed files with 7 additions and 8 deletions
|
@ -136,22 +136,21 @@ function MindElixir({ content, containerProps, apiRef: externalApiRef, onChange,
|
||||||
|
|
||||||
// On change listener.
|
// On change listener.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!onChange) return;
|
const bus = apiRef.current?.bus;
|
||||||
|
if (!onChange || !bus) return;
|
||||||
|
|
||||||
const listener = (operation: Operation) => {
|
const operationListener = (operation: Operation) => {
|
||||||
if (operation.name !== "beginEdit") {
|
if (operation.name !== "beginEdit") {
|
||||||
onChange();
|
onChange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
apiRef.current?.bus.addListener("operation", listener);
|
|
||||||
|
|
||||||
// Direction change buttons don't report change, so we have to hook in manually.
|
bus.addListener("operation", operationListener);
|
||||||
const $container = refToJQuerySelector(containerRef);
|
bus.addListener("changeDirection", onChange);
|
||||||
$container.on("click", ".mind-elixir-toolbar.lt", onChange);
|
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
$container.off("click", ".mind-elixir-toolbar.lt", onChange);
|
bus.removeListener("operation", operationListener);
|
||||||
apiRef.current?.bus?.removeListener("operation", listener);
|
bus.removeListener("changeDirection", onChange);
|
||||||
};
|
};
|
||||||
}, [ onChange ]);
|
}, [ onChange ]);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue