refactor(mindmap): use proper way to detect direction

See https://github.com/SSShooter/mind-elixir-core/issues/150.
This commit is contained in:
Elian Doran 2025-10-04 19:17:13 +03:00
parent cf37549f19
commit df9d481a93
No known key found for this signature in database

View file

@ -136,22 +136,21 @@ function MindElixir({ content, containerProps, apiRef: externalApiRef, onChange,
// On change listener.
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") {
onChange();
}
}
apiRef.current?.bus.addListener("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);
bus.addListener("operation", operationListener);
bus.addListener("changeDirection", onChange);
return () => {
$container.off("click", ".mind-elixir-toolbar.lt", onChange);
apiRef.current?.bus?.removeListener("operation", listener);
bus.removeListener("operation", operationListener);
bus.removeListener("changeDirection", onChange);
};
}, [ onChange ]);