Skip to content

Commit 34c99ed

Browse files
fix: increase text area height on press enter and fix text widget embeding issue on finished button
1 parent 276fc97 commit 34c99ed

File tree

2 files changed

+128
-5
lines changed

2 files changed

+128
-5
lines changed

apps/OpenSign/src/components/pdf/PlaceholderType.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
getMonth,
44
getYear,
55
isMobile,
6+
onChangeHeightOfTextArea,
67
onChangeInput,
78
radioButtonWidget,
89
range,
@@ -285,6 +286,22 @@ function PlaceholderType(props) {
285286
};
286287
props.handleSaveDate(dateObj, isDateChange);
287288
};
289+
//handle height on enter press in text area
290+
const handleEnterPress = (e) => {
291+
const height = 15;
292+
if (e.key === "Enter") {
293+
//function to save height of text area
294+
onChangeHeightOfTextArea(
295+
height,
296+
props.pos.type,
297+
props.pos.key,
298+
props.xyPostion,
299+
props.index,
300+
props.setXyPostion,
301+
props.data && props.data?.Id
302+
);
303+
}
304+
};
288305
switch (type) {
289306
case "signature":
290307
return props.pos.SignUrl ? (
@@ -741,6 +758,7 @@ function PlaceholderType(props) {
741758
<textarea
742759
placeholder="Enter label"
743760
rows={1}
761+
onKeyDown={handleEnterPress}
744762
value={textValue}
745763
onBlur={handleInputBlur}
746764
onChange={(e) => {

apps/OpenSign/src/constant/Utils.js

Lines changed: 110 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,82 @@ export const onChangeInput = (
760760
}
761761
};
762762

763+
//function to increase height of text area on press enter
764+
export const onChangeHeightOfTextArea = (
765+
height,
766+
widgetType,
767+
signKey,
768+
xyPostion,
769+
index,
770+
setXyPostion,
771+
userId
772+
) => {
773+
const isSigners = xyPostion.some((data) => data.signerPtr);
774+
let filterSignerPos;
775+
if (isSigners) {
776+
if (userId) {
777+
filterSignerPos = xyPostion.filter((data) => data.Id === userId);
778+
}
779+
const getPlaceHolder = filterSignerPos[0]?.placeHolder;
780+
781+
const getPageNumer = getPlaceHolder.filter(
782+
(data) => data.pageNumber === index
783+
);
784+
if (getPageNumer.length > 0) {
785+
const getXYdata = getPageNumer[0].pos;
786+
const getPosData = getXYdata;
787+
const addSignPos = getPosData.map((position) => {
788+
if (position.key === signKey) {
789+
return {
790+
...position,
791+
Height: position.Height
792+
? position.Height + height
793+
: defaultWidthHeight(widgetType).height + height
794+
};
795+
}
796+
return position;
797+
});
798+
const newUpdateSignPos = getPlaceHolder.map((obj) => {
799+
if (obj.pageNumber === index) {
800+
return { ...obj, pos: addSignPos };
801+
}
802+
return obj;
803+
});
804+
805+
const newUpdateSigner = xyPostion.map((obj) => {
806+
if (obj.Id === userId) {
807+
return { ...obj, placeHolder: newUpdateSignPos };
808+
}
809+
return obj;
810+
});
811+
812+
setXyPostion(newUpdateSigner);
813+
}
814+
} else {
815+
let getXYdata = xyPostion[index].pos;
816+
817+
const updatePosition = getXYdata.map((position) => {
818+
if (position.key === signKey) {
819+
return {
820+
...position,
821+
Height: position.Height
822+
? position.Height + height
823+
: defaultWidthHeight(widgetType).height + height
824+
};
825+
}
826+
return position;
827+
});
828+
829+
const updatePlaceholder = xyPostion.map((obj, ind) => {
830+
if (ind === index) {
831+
return { ...obj, pos: updatePosition };
832+
}
833+
return obj;
834+
});
835+
setXyPostion(updatePlaceholder);
836+
}
837+
};
838+
763839
export const addInitialData = (signerPos, setXyPostion, value, userId) => {
764840
function widgetDataValue(type) {
765841
switch (type) {
@@ -1234,10 +1310,11 @@ export const multiSignEmbed = async (
12341310
} else if (position?.options?.defaultValue) {
12351311
textContent = position?.options?.defaultValue;
12361312
}
1237-
12381313
const fixedWidth = scaleWidth; // Set your fixed width
1314+
const isNewOnEnterLineExist = textContent.includes("\n");
1315+
12391316
// Function to break text into lines based on the fixed width
1240-
const breakTextIntoLines = (textContent, width) => {
1317+
const NewbreakTextIntoLines = (textContent, width) => {
12411318
const lines = [];
12421319
let currentLine = "";
12431320

@@ -1257,7 +1334,37 @@ export const multiSignEmbed = async (
12571334
lines.push(currentLine.trim());
12581335
return lines;
12591336
};
1260-
const lines = breakTextIntoLines(textContent, fixedWidth);
1337+
1338+
// Function to break text into lines based on when user go next line on press enter button
1339+
const breakTextIntoLines = (textContent, width) => {
1340+
const lines = [];
1341+
let currentLine = "";
1342+
1343+
for (const word of textContent.split("\n")) {
1344+
const lineWidth = font.widthOfTextAtSize(
1345+
`${currentLine} ${word}`,
1346+
fontSize
1347+
);
1348+
//checking string length to container width
1349+
//if string length is less then container width it means user press enter button
1350+
if (lineWidth <= width) {
1351+
lines.push(word);
1352+
}
1353+
//else adjust text content according to width and send it in new line
1354+
else {
1355+
const newLine = NewbreakTextIntoLines(word, width);
1356+
lines.push(...newLine);
1357+
}
1358+
}
1359+
1360+
return lines;
1361+
};
1362+
1363+
//check if text content have `\n` string it means user press enter to go next line and handle condition
1364+
//else auto adjust text content according to container width
1365+
const lines = isNewOnEnterLineExist
1366+
? breakTextIntoLines(textContent, fixedWidth)
1367+
: NewbreakTextIntoLines(textContent, fixedWidth);
12611368
// Set initial y-coordinate for the first line
12621369
const labelDefaultHeight = defaultWidthHeight(position.type).height;
12631370

@@ -1358,9 +1465,7 @@ export const multiSignEmbed = async (
13581465
}
13591466
});
13601467
}
1361-
13621468
const pdfBytes = await pdfDoc.saveAsBase64({ useObjectStreams: false });
1363-
13641469
return pdfBytes;
13651470
};
13661471

0 commit comments

Comments
 (0)