@@ -760,6 +760,82 @@ export const onChangeInput = (
760
760
}
761
761
} ;
762
762
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
+
763
839
export const addInitialData = ( signerPos , setXyPostion , value , userId ) => {
764
840
function widgetDataValue ( type ) {
765
841
switch ( type ) {
@@ -1234,10 +1310,11 @@ export const multiSignEmbed = async (
1234
1310
} else if ( position ?. options ?. defaultValue ) {
1235
1311
textContent = position ?. options ?. defaultValue ;
1236
1312
}
1237
-
1238
1313
const fixedWidth = scaleWidth ; // Set your fixed width
1314
+ const isNewOnEnterLineExist = textContent . includes ( "\n" ) ;
1315
+
1239
1316
// Function to break text into lines based on the fixed width
1240
- const breakTextIntoLines = ( textContent , width ) => {
1317
+ const NewbreakTextIntoLines = ( textContent , width ) => {
1241
1318
const lines = [ ] ;
1242
1319
let currentLine = "" ;
1243
1320
@@ -1257,7 +1334,37 @@ export const multiSignEmbed = async (
1257
1334
lines . push ( currentLine . trim ( ) ) ;
1258
1335
return lines ;
1259
1336
} ;
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 ) ;
1261
1368
// Set initial y-coordinate for the first line
1262
1369
const labelDefaultHeight = defaultWidthHeight ( position . type ) . height ;
1263
1370
@@ -1358,9 +1465,7 @@ export const multiSignEmbed = async (
1358
1465
}
1359
1466
} ) ;
1360
1467
}
1361
-
1362
1468
const pdfBytes = await pdfDoc . saveAsBase64 ( { useObjectStreams : false } ) ;
1363
-
1364
1469
return pdfBytes ;
1365
1470
} ;
1366
1471
0 commit comments