feat(ui): remove dep on stage in mouse handlers

This commit is contained in:
psychedelicious 2024-04-17 17:10:34 +10:00 committed by Kent Keirsey
parent ff7aa2558a
commit ede8826757

View File

@ -1,7 +1,6 @@
import { getStore } from 'app/store/nanostores/store'; import { getStore } from 'app/store/nanostores/store';
import { useAppDispatch } from 'app/store/storeHooks'; import { useAppDispatch } from 'app/store/storeHooks';
import getScaledCursorPosition from 'features/canvas/util/getScaledCursorPosition'; import getScaledCursorPosition from 'features/canvas/util/getScaledCursorPosition';
import { $stage } from 'features/regionalPrompts/components/imperative/konvaApiDraft';
import { import {
$cursorPosition, $cursorPosition,
$isMouseDown, $isMouseDown,
@ -31,8 +30,8 @@ const syncCursorPos = (stage: Konva.Stage) => {
export const useMouseDown = () => { export const useMouseDown = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const onMouseDown = useCallback( const onMouseDown = useCallback(
(_e: KonvaEventObject<MouseEvent | TouchEvent>) => { (e: KonvaEventObject<MouseEvent | TouchEvent>) => {
const stage = $stage.get(); const stage = e.target.getStage();
if (!stage) { if (!stage) {
return; return;
} }
@ -54,8 +53,8 @@ export const useMouseDown = () => {
export const useMouseUp = () => { export const useMouseUp = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const onMouseUp = useCallback( const onMouseUp = useCallback(
(_e: KonvaEventObject<MouseEvent | TouchEvent>) => { (e: KonvaEventObject<MouseEvent | TouchEvent>) => {
const stage = $stage.get(); const stage = e.target.getStage();
if (!stage) { if (!stage) {
return; return;
} }
@ -78,8 +77,8 @@ export const useMouseUp = () => {
export const useMouseMove = () => { export const useMouseMove = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const onMouseMove = useCallback( const onMouseMove = useCallback(
(_e: KonvaEventObject<MouseEvent | TouchEvent>) => { (e: KonvaEventObject<MouseEvent | TouchEvent>) => {
const stage = $stage.get(); const stage = e.target.getStage();
if (!stage) { if (!stage) {
return; return;
} }
@ -98,8 +97,8 @@ export const useMouseMove = () => {
}; };
export const useMouseLeave = () => { export const useMouseLeave = () => {
const onMouseLeave = useCallback((_e: KonvaEventObject<MouseEvent | TouchEvent>) => { const onMouseLeave = useCallback((e: KonvaEventObject<MouseEvent | TouchEvent>) => {
const stage = $stage.get(); const stage = e.target.getStage();
if (!stage) { if (!stage) {
return; return;
} }
@ -114,7 +113,7 @@ export const useMouseEnter = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const onMouseEnter = useCallback( const onMouseEnter = useCallback(
(e: KonvaEventObject<MouseEvent>) => { (e: KonvaEventObject<MouseEvent>) => {
const stage = $stage.get(); const stage = e.target.getStage();
if (!stage) { if (!stage) {
return; return;
} }