mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
fix: use div instead of rnd for preview fields
This commit is contained in:
@ -218,9 +218,9 @@ export const EditDocumentForm = ({
|
|||||||
<AddTitleFormPartial
|
<AddTitleFormPartial
|
||||||
key={recipients.length}
|
key={recipients.length}
|
||||||
documentFlow={documentFlow.title}
|
documentFlow={documentFlow.title}
|
||||||
|
document={document}
|
||||||
recipients={recipients}
|
recipients={recipients}
|
||||||
fields={fields}
|
fields={fields}
|
||||||
document={document}
|
|
||||||
onSubmit={onAddTitleFormSubmit}
|
onSubmit={onAddTitleFormSubmit}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import {
|
|||||||
DocumentFlowFormContainerHeader,
|
DocumentFlowFormContainerHeader,
|
||||||
DocumentFlowFormContainerStep,
|
DocumentFlowFormContainerStep,
|
||||||
} from './document-flow-root';
|
} from './document-flow-root';
|
||||||
|
import { ShowFieldItem } from './show-field-item';
|
||||||
import type { DocumentFlowStep } from './types';
|
import type { DocumentFlowStep } from './types';
|
||||||
|
|
||||||
export type AddTitleFormProps = {
|
export type AddTitleFormProps = {
|
||||||
@ -29,8 +30,8 @@ export type AddTitleFormProps = {
|
|||||||
|
|
||||||
export const AddTitleFormPartial = ({
|
export const AddTitleFormPartial = ({
|
||||||
documentFlow,
|
documentFlow,
|
||||||
recipients: _recipients,
|
recipients,
|
||||||
fields: _fields,
|
fields,
|
||||||
document,
|
document,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
}: AddTitleFormProps) => {
|
}: AddTitleFormProps) => {
|
||||||
@ -55,6 +56,10 @@ export const AddTitleFormPartial = ({
|
|||||||
description={documentFlow.description}
|
description={documentFlow.description}
|
||||||
/>
|
/>
|
||||||
<DocumentFlowFormContainerContent>
|
<DocumentFlowFormContainerContent>
|
||||||
|
{fields.map((field, index) => (
|
||||||
|
<ShowFieldItem key={index} field={field} recipients={recipients} />
|
||||||
|
))}
|
||||||
|
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<div className="flex flex-col gap-y-4">
|
<div className="flex flex-col gap-y-4">
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@ -1,12 +1,9 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useCallback, useEffect, useState } from 'react';
|
|
||||||
|
|
||||||
import type { Prisma } from '@prisma/client';
|
import type { Prisma } from '@prisma/client';
|
||||||
import { createPortal } from 'react-dom';
|
import { createPortal } from 'react-dom';
|
||||||
import { Rnd } from 'react-rnd';
|
|
||||||
|
|
||||||
import { PDF_VIEWER_PAGE_SELECTOR } from '@documenso/lib/constants/pdf-viewer';
|
import { useFieldPageCoords } from '@documenso/lib/client-only/hooks/use-field-page-coords';
|
||||||
|
|
||||||
import { cn } from '../../lib/utils';
|
import { cn } from '../../lib/utils';
|
||||||
import { Card, CardContent } from '../card';
|
import { Card, CardContent } from '../card';
|
||||||
@ -18,59 +15,20 @@ export type ShowFieldItemProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const ShowFieldItem = ({ field, recipients }: ShowFieldItemProps) => {
|
export const ShowFieldItem = ({ field, recipients }: ShowFieldItemProps) => {
|
||||||
const [coords, setCoords] = useState({
|
const coords = useFieldPageCoords(field);
|
||||||
pageX: Number(field.positionX),
|
|
||||||
pageY: Number(field.positionY),
|
|
||||||
pageHeight: Number(field.height),
|
|
||||||
pageWidth: Number(field.width),
|
|
||||||
});
|
|
||||||
|
|
||||||
const signerEmail =
|
const signerEmail =
|
||||||
recipients.find((recipient) => recipient.id === field.recipientId)?.email ?? '';
|
recipients.find((recipient) => recipient.id === field.recipientId)?.email ?? '';
|
||||||
|
|
||||||
const calculateCoords = useCallback(() => {
|
|
||||||
const $page = document.querySelector<HTMLElement>(
|
|
||||||
`${PDF_VIEWER_PAGE_SELECTOR}[data-page-number="${field.page}"]`,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!$page) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { height, width } = $page.getBoundingClientRect();
|
|
||||||
|
|
||||||
const top = $page.getBoundingClientRect().top + window.scrollY;
|
|
||||||
const left = $page.getBoundingClientRect().left + window.scrollX;
|
|
||||||
|
|
||||||
const pageX = (Number(field.positionX) / 100) * width + left;
|
|
||||||
const pageY = (Number(field.positionY) / 100) * height + top;
|
|
||||||
|
|
||||||
const pageHeight = (Number(field.height) / 100) * height;
|
|
||||||
const pageWidth = (Number(field.width) / 100) * width;
|
|
||||||
|
|
||||||
setCoords({
|
|
||||||
pageX: pageX,
|
|
||||||
pageY: pageY,
|
|
||||||
pageHeight: pageHeight,
|
|
||||||
pageWidth: pageWidth,
|
|
||||||
});
|
|
||||||
}, [field.page, field.positionX, field.positionY, field.height, field.width]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
calculateCoords();
|
|
||||||
}, [calculateCoords]);
|
|
||||||
|
|
||||||
return createPortal(
|
return createPortal(
|
||||||
<Rnd
|
<div
|
||||||
key={coords.pageX + coords.pageY + coords.pageHeight + coords.pageWidth}
|
className={cn('pointer-events-none absolute z-10 opacity-75')}
|
||||||
className={cn('pointer-events-none z-10 opacity-75')}
|
style={{
|
||||||
default={{
|
top: `${coords.y}px`,
|
||||||
x: coords.pageX,
|
left: `${coords.x}px`,
|
||||||
y: coords.pageY,
|
height: `${coords.height}px`,
|
||||||
height: coords.pageHeight,
|
width: `${coords.width}px`,
|
||||||
width: coords.pageWidth,
|
|
||||||
}}
|
}}
|
||||||
bounds={`${PDF_VIEWER_PAGE_SELECTOR}[data-page-number="${field.page}"]`}
|
|
||||||
>
|
>
|
||||||
<Card className={cn('bg-background h-full w-full')}>
|
<Card className={cn('bg-background h-full w-full')}>
|
||||||
<CardContent
|
<CardContent
|
||||||
@ -85,7 +43,7 @@ export const ShowFieldItem = ({ field, recipients }: ShowFieldItemProps) => {
|
|||||||
</p>
|
</p>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</Rnd>,
|
</div>,
|
||||||
document.body,
|
document.body,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user