MCPcopy Index your code
hub / github.com/OpenSignLabs/OpenSign / handlePointerUp

Function handlePointerUp

apps/OpenSign/src/components/pdf/RenderPdf.jsx:547–624  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

545 };
546
547 const handlePointerUp = (e) => {
548 if (!isDrawingRef.current || !drawStartRef.current || !drawEndRef.current) {
549 isDrawingRef.current = false;
550 drawStartRef.current = null;
551 drawEndRef.current = null;
552 setIsDrawing(false);
553 return;
554 }
555
556 // Use page-relative coordinates for widget dimensions and position
557 const pageWidth = Math.abs(
558 drawEndRef.current.pageX - drawStartRef.current.pageX
559 );
560 const pageHeight = Math.abs(
561 drawEndRef.current.pageY - drawStartRef.current.pageY
562 );
563
564 // Only create widget if the drawn area is large enough (minimum 30x20 pixels)
565 if (pageWidth > 30 && pageHeight > 20) {
566 const drawPageNum = drawStartRef.current.pageNum;
567 const containerScale = getContainerScale(
568 props.pdfOriginalWH,
569 drawPageNum,
570 props.containerWH
571 );
572
573 const rectX = Math.min(
574 drawStartRef.current.pageX,
575 drawEndRef.current.pageX
576 );
577 const rectY = Math.min(
578 drawStartRef.current.pageY,
579 drawEndRef.current.pageY
580 );
581
582 // Convert pixel coordinates to PDF coordinates
583 const xPosition = rectX / (containerScale * props.scale);
584 const yPosition = rectY / (containerScale * props.scale);
585 const widgetWidth = pageWidth / (containerScale * props.scale);
586 const widgetHeight = pageHeight / (containerScale * props.scale);
587
588 // Create a Text Input widget at the drawn position
589 if (props.addPositionOfSignature) {
590 // If drawing on a different page, update pageNumber first
591 if (drawPageNum !== props.pageNumber && props.setPageNumber) {
592 props.setPageNumber(drawPageNum);
593 }
594 // Simulate dropping a text input widget
595 const type =
596 props?.roleName === "prefill" ? textWidget : textInputWidget;
597 const textInputItem = { text: type, type: "BOX" };
598
599 const monitor = {
600 type: type,
601 getClientOffset: () => ({ x: rectX, y: rectY }),
602 getSourceClientOffset: () => ({ x: rectX, y: rectY })
603 };
604

Callers 1

RenderPdfFunction · 0.85

Calls 1

getContainerScaleFunction · 0.90

Tested by

no test coverage detected