@@ -7,12 +7,13 @@ import {
77 OnZoomingHandler ,
88 OnPointerMoveHandler ,
99 OnPointerDownHandler ,
10+ OnDragHandler ,
1011} from "../canvas-event-target" ;
1112import { get_hovering_target , centerOf } from "../math" ;
1213import { utils } from "@design-sdk/core" ;
1314import { LazyFrame } from "@code-editor/canvas/lazy-frame" ;
1415import { HudCustomRenderers , HudSurface } from "./hud-surface" ;
15- import type { Box , XY , CanvasTransform } from "../types" ;
16+ import type { Box , XY , CanvasTransform , XYWH } from "../types" ;
1617import type { FrameOptimizationFactors } from "../frame" ;
1718const designq = utils . query ;
1819
@@ -117,6 +118,8 @@ export function Canvas({
117118 ? [ offset [ 0 ] / zoom , offset [ 1 ] / zoom ]
118119 : [ 0 , 0 ] ;
119120 const [ isPanning , setIsPanning ] = useState ( false ) ;
121+ const [ marquee , setMarquee ] = useState < XYWH > ( null ) ;
122+
120123 const cvtransform : CanvasTransform = {
121124 scale : zoom ,
122125 xy : offset ,
@@ -207,6 +210,29 @@ export function Canvas({
207210 setOffset ( [ newx , newy ] ) ;
208211 } ;
209212
213+ const onDrag : OnDragHandler = ( s ) => {
214+ const [ x1 , y1 ] = s . initial ;
215+ const [ x2 , y2 ] = [
216+ // @ts -ignore
217+ s . event . clientX ,
218+ // @ts -ignore
219+ s . event . clientY ,
220+ ] ;
221+
222+ const [ ox , oy ] = offset ;
223+ const [ x , y , w , h ] = [
224+ x1 - ox ,
225+ y1 - oy ,
226+ x2 - x1 , // w
227+ y2 - y1 , // h
228+ ] ;
229+ setMarquee ( [ x , y , w , h ] ) ;
230+ } ;
231+
232+ const onDragEnd : OnDragHandler = ( s ) => {
233+ setMarquee ( null ) ;
234+ } ;
235+
210236 const is_canvas_transforming = isPanning || isZooming ;
211237 const selected_nodes = selectedNodes
212238 ?. map ( ( id ) => designq . find_node_by_id_under_inpage_nodes ( id , nodes ) )
@@ -257,12 +283,16 @@ export function Canvas({
257283 onPointerMoveStart = { ( ) => { } }
258284 onPointerMoveEnd = { ( ) => { } }
259285 onPointerDown = { onPointerDown }
286+ onDrag = { onDrag }
287+ onDragStart = { ( ) => { } } // TODO:
288+ onDragEnd = { onDragEnd }
260289 >
261290 < HudSurface
262291 offset = { nonscaled_offset }
263292 zoom = { zoom }
264293 hide = { is_canvas_transforming }
265294 readonly = { readonly }
295+ marquee = { marquee }
266296 labelDisplayNodes = { nodes }
267297 selectedNodes = { selected_nodes }
268298 highlights = {
0 commit comments