MCPcopy Create free account
hub / github.com/TanStack/query / handleDragStart

Function handleDragStart

packages/query-devtools/src/Devtools.tsx:421–480  ·  view source on GitHub ↗
(
    event,
  )

Source from the content-addressed store, hash-verified

419 )
420
421 const handleDragStart: JSX.EventHandler<HTMLDivElement, MouseEvent> = (
422 event,
423 ) => {
424 const panelElement = event.currentTarget.parentElement
425 if (!panelElement) return
426 setIsResizing(true)
427 const { height, width } = panelElement.getBoundingClientRect()
428 const startX = event.clientX
429 const startY = event.clientY
430 let newSize = 0
431 const minHeight = convertRemToPixels(3.5)
432 const minWidth = convertRemToPixels(12)
433 const runDrag = (moveEvent: MouseEvent) => {
434 moveEvent.preventDefault()
435
436 if (position() === 'left' || position() === 'right') {
437 const valToAdd =
438 position() === 'right'
439 ? startX - moveEvent.clientX
440 : moveEvent.clientX - startX
441 newSize = Math.round(width + valToAdd)
442 if (newSize < minWidth) {
443 newSize = minWidth
444 }
445 props.setLocalStore('width', String(Math.round(newSize)))
446
447 const newWidth = panelElement.getBoundingClientRect().width
448 // If the panel size didn't decrease, this means we have reached the minimum width
449 // of the panel so we restore the original width in local storage
450 // Restoring the width helps in smooth open/close transitions
451 if (Number(props.localStore.width) < newWidth) {
452 props.setLocalStore('width', String(newWidth))
453 }
454 } else {
455 const valToAdd =
456 position() === 'bottom'
457 ? startY - moveEvent.clientY
458 : moveEvent.clientY - startY
459 newSize = Math.round(height + valToAdd)
460 // If the panel size is less than the minimum height,
461 // we set the size to the minimum height
462 if (newSize < minHeight) {
463 newSize = minHeight
464 setSelectedQueryHash(null)
465 }
466 props.setLocalStore('height', String(Math.round(newSize)))
467 }
468 }
469
470 const unsubscribe = () => {
471 if (isResizing()) {
472 setIsResizing(false)
473 }
474 document.removeEventListener('mousemove', runDrag, false)
475 document.removeEventListener('mouseup', unsubscribe, false)
476 }
477
478 document.addEventListener('mousemove', runDrag, false)

Callers

nothing calls this directly

Calls 1

convertRemToPixelsFunction · 0.90

Tested by

no test coverage detected