diff --git a/src/core/providers/canvas/canvas.model.ts b/src/core/providers/canvas/canvas.model.ts index f25f22a0..5400eddf 100644 --- a/src/core/providers/canvas/canvas.model.ts +++ b/src/core/providers/canvas/canvas.model.ts @@ -2,12 +2,7 @@ import { ShapeModel, ShapeRefs, ShapeType } from '@/core/model'; import Konva from 'konva'; import { Node, NodeConfig } from 'konva/lib/Node'; -export interface CanvasContextModel { - shapes: ShapeModel[]; - setShapes: React.Dispatch>; - scale: number; - setScale: React.Dispatch>; - +export interface SelectionInfo { transformerRef: React.RefObject; shapeRefs: React.MutableRefObject; handleSelected: (id: string, type: ShapeType) => void; @@ -20,3 +15,12 @@ export interface CanvasContextModel { selectedShapeId: string; selectedShapeType: ShapeType | null; } + +export interface CanvasContextModel { + shapes: ShapeModel[]; + setShapes: React.Dispatch>; + scale: number; + setScale: React.Dispatch>; + + selectionInfo: SelectionInfo; +} diff --git a/src/core/providers/canvas/canvas.provider.tsx b/src/core/providers/canvas/canvas.provider.tsx index eccd1f9e..c1071658 100644 --- a/src/core/providers/canvas/canvas.provider.tsx +++ b/src/core/providers/canvas/canvas.provider.tsx @@ -12,15 +12,7 @@ export const CanvasProvider: React.FC = props => { const [shapes, setShapes] = React.useState([]); const [scale, setScale] = React.useState(1); - const { - shapeRefs, - transformerRef, - handleSelected, - handleClearSelection, - selectedShapeRef, - selectedShapeId, - selectedShapeType, - } = useSelection(shapes); + const selectionInfo = useSelection(shapes); return ( = props => { setShapes, scale, setScale, - shapeRefs, - transformerRef, - handleSelected, - handleClearSelection, - selectedShapeRef, - selectedShapeId, - selectedShapeType, + selectionInfo, }} > {children} diff --git a/src/core/providers/canvas/use-selection.hook.ts b/src/core/providers/canvas/use-selection.hook.ts index ee6344eb..1e873be3 100644 --- a/src/core/providers/canvas/use-selection.hook.ts +++ b/src/core/providers/canvas/use-selection.hook.ts @@ -1,8 +1,9 @@ import { useEffect, useRef, useState } from 'react'; import Konva from 'konva'; import { ShapeModel, ShapeRefs, ShapeType } from '@/core/model'; +import { SelectionInfo } from './canvas.model'; -export const useSelection = (shapes: ShapeModel[]) => { +export const useSelection = (shapes: ShapeModel[]): SelectionInfo => { const transformerRef = useRef(null); const shapeRefs = useRef({}); const selectedShapeRef = useRef(null); diff --git a/src/pods/canvas/canvas.pod.tsx b/src/pods/canvas/canvas.pod.tsx index e9b054f9..a0af0265 100644 --- a/src/pods/canvas/canvas.pod.tsx +++ b/src/pods/canvas/canvas.pod.tsx @@ -16,10 +16,9 @@ import { import { ShapeModel } from '@/core/model'; export const CanvasPod = () => { + const { shapes, setShapes, scale, selectionInfo } = useCanvasContext(); + const { - shapes, - setShapes, - scale, shapeRefs, transformerRef, handleSelected, @@ -27,7 +26,7 @@ export const CanvasPod = () => { selectedShapeRef, selectedShapeId, selectedShapeType, - } = useCanvasContext(); + } = selectionInfo; const { isDraggedOver, dropRef } = useDropShape(); const { stageRef } = useMonitorShape(dropRef, setShapes);