mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
♻️ createField (object) to editor features
This commit is contained in:
31
packages/features/editor/createField.ts
Normal file
31
packages/features/editor/createField.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { FieldType } from "@prisma/client";
|
||||
|
||||
export const createField = function addField(
|
||||
e: any,
|
||||
page: number,
|
||||
selectedRecipient: any,
|
||||
type: FieldType = FieldType.SIGNATURE
|
||||
): any {
|
||||
var rect = e.target.getBoundingClientRect();
|
||||
const fieldSize = { width: 192, height: 96 };
|
||||
var newFieldX = e.clientX - rect.left - fieldSize.width / 2; //x position within the element.
|
||||
var newFieldY = e.clientY - rect.top - fieldSize.height / 2; //y position within the element.
|
||||
if (newFieldX < 0) newFieldX = 0;
|
||||
if (newFieldY < 0) newFieldY = 0;
|
||||
|
||||
if (newFieldX + fieldSize.width > rect.width)
|
||||
newFieldX = rect.width - fieldSize.width;
|
||||
if (newFieldY + fieldSize.height > rect.height)
|
||||
newFieldY = rect.height - fieldSize.height;
|
||||
|
||||
const signatureField = {
|
||||
id: -1,
|
||||
page: page,
|
||||
type: type,
|
||||
positionX: newFieldX.toFixed(0),
|
||||
positionY: newFieldY.toFixed(0),
|
||||
Recipient: selectedRecipient,
|
||||
};
|
||||
|
||||
return signatureField;
|
||||
};
|
||||
1
packages/features/editor/index.ts
Normal file
1
packages/features/editor/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export { createField } from "./createField";
|
||||
Reference in New Issue
Block a user