🔥 The free & Open Source DocuSign alternative
JavaScript digital-signaturedocument-signingdocusign-alternativedocusign-freee-signatureelectronic-signatureelectronic-signaturesesignesignaturehacktoberfestjavascriptlegaltechmongodbnodejsopen-sourcepdf-signpdf-signaturereactjsself-hostedsign-pdf-files
fix: increase text area height on press enter and fix text widget embeding issue on finished button
RaktimaNXG34c99edf1a01
diff --git a/apps/OpenSign/src/components/pdf/PlaceholderType.js b/apps/OpenSign/src/components/pdf/PlaceholderType.jsindex 03e79efb6..d61c8bbca 100644--- a/apps/OpenSign/src/components/pdf/PlaceholderType.js+++ b/apps/OpenSign/src/components/pdf/PlaceholderType.js@@ -3,6 +3,7 @@ import {getMonth,getYear,isMobile,+ onChangeHeightOfTextArea,onChangeInput,radioButtonWidget,range,@@ -285,6 +286,22 @@ function PlaceholderType(props) {};props.handleSaveDate(dateObj, isDateChange);};+ //handle height on enter press in text area+ const handleEnterPress = (e) => {+ const height = 15;+ if (e.key === "Enter") {+ //function to save height of text area+ onChangeHeightOfTextArea(+ height,+ props.pos.type,+ props.pos.key,+ props.xyPostion,+ props.index,+ props.setXyPostion,+ props.data && props.data?.Id+ );+ }+ };switch (type) {case "signature":return props.pos.SignUrl ? (@@ -741,6 +758,7 @@ function PlaceholderType(props) {<textareaplaceholder="Enter label"rows={1}+ onKeyDown={handleEnterPress}value={textValue}onBlur={handleInputBlur}onChange={(e) => {diff --git a/apps/OpenSign/src/constant/Utils.js b/apps/OpenSign/src/constant/Utils.jsindex 883238dea..67b1f9d7f 100644--- a/apps/OpenSign/src/constant/Utils.js+++ b/apps/OpenSign/src/constant/Utils.js@@ -760,6 +760,82 @@ export const onChangeInput = (}};+//function to increase height of text area on press enter+export const onChangeHeightOfTextArea = (+ height,+ widgetType,+ signKey,+ xyPostion,+ index,+ setXyPostion,+ userId+) => {+ const isSigners = xyPostion.some((data) => data.signerPtr);+ let filterSignerPos;+ if (isSigners) {+ if (userId) {+ filterSignerPos = xyPostion.filter((data) => data.Id === userId);+ }+ const getPlaceHolder = filterSignerPos[0]?.placeHolder;++ const getPageNumer = getPlaceHolder.filter(+ (data) => data.pageNumber === index+ );+ if (getPageNumer.length > 0) {+ const getXYdata = getPageNumer[0].pos;+ const getPosData = getXYdata;+ const addSignPos = getPosData.map((position) => {+ if (position.key === signKey) {+ return {+ ...position,+ Height: position.Height+ ? position.Height + height+ : defaultWidthHeight(widgetType).height + height+ };+ }+ return position;+ });+ const newUpdateSignPos = getPlaceHolder.map((obj) => {+ if (obj.pageNumber === index) {+ return { ...obj, pos: addSignPos };+ }+ return obj;+ });++ const newUpdateSigner = xyPostion.map((obj) => {+ if (obj.Id === userId) {+ return { ...obj, placeHolder: newUpdateSignPos };+ }+ return obj;+ });++ setXyPostion(newUpdateSigner);+ }+ } else {+ let getXYdata = xyPostion[index].pos;++ const updatePosition = getXYdata.map((position) => {+ if (position.key === signKey) {+ return {+ ...position,+ Height: position.Height+ ? position.Height + height+ : defaultWidthHeight(widgetType).height + height+ };+ }+ return position;+ });++ const updatePlaceholder = xyPostion.map((obj, ind) => {+ if (ind === index) {+ return { ...obj, pos: updatePosition };+ }+ return obj;+ });+ setXyPostion(updatePlaceholder);+ }+};+export const addInitialData = (signerPos, setXyPostion, value, userId) => {function widgetDataValue(type) {switch (type) {@@ -1234,10 +1310,11 @@ export const multiSignEmbed = async (} else if (position?.options?.defaultValue) {textContent = position?.options?.defaultValue;}-const fixedWidth = scaleWidth; // Set your fixed width+ const isNewOnEnterLineExist = textContent.includes("\n");+// Function to break text into lines based on the fixed width- const breakTextIntoLines = (textContent, width) => {+ const NewbreakTextIntoLines = (textContent, width) => {const lines = [];let currentLine = "";@@ -1257,7 +1334,37 @@ export const multiSignEmbed = async (lines.push(currentLine.trim());return lines;};- const lines = breakTextIntoLines(textContent, fixedWidth);++ // Function to break text into lines based on when user go next line on press enter button+ const breakTextIntoLines = (textContent, width) => {+ const lines = [];+ let currentLine = "";++ for (const word of textContent.split("\n")) {+ const lineWidth = font.widthOfTextAtSize(+ `${currentLine} ${word}`,+ fontSize+ );+ //checking string length to container width+ //if string length is less then container width it means user press enter button+ if (lineWidth <= width) {+ lines.push(word);+ }+ //else adjust text content according to width and send it in new line+ else {+ const newLine = NewbreakTextIntoLines(word, width);+ lines.push(...newLine);+ }+ }++ return lines;+ };++ //check if text content have `\n` string it means user press enter to go next line and handle condition+ //else auto adjust text content according to container width+ const lines = isNewOnEnterLineExist+ ? breakTextIntoLines(textContent, fixedWidth)+ : NewbreakTextIntoLines(textContent, fixedWidth);// Set initial y-coordinate for the first lineconst labelDefaultHeight = defaultWidthHeight(position.type).height;@@ -1358,9 +1465,7 @@ export const multiSignEmbed = async (}});}-const pdfBytes = await pdfDoc.saveAsBase64({ useObjectStreams: false });-return pdfBytes;};