@verdocs/js-sdk 6.4.4 → 6.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1781,13 +1781,11 @@ function sortFields(fields) {
1781
1781
  if (aPage !== bPage) {
1782
1782
  return aPage - bPage;
1783
1783
  }
1784
- // NOTE: Logic looks a little strange X vs Y. It's because we go top down,
1785
- // left to right. But Y coordinates are inverted in PDFs. The reason for
1786
- // the division is because no human makes perfect templates and frequently
1787
- // two fields on the "same line" will be slightly offset vertically.
1788
1784
  const divaY = Math.floor(aY / 5);
1789
1785
  const divbY = Math.floor(bY / 5);
1790
1786
  if (divaY !== divbY) {
1787
+ // Unlike the other properties, Y coordinates have 0,0 at the BOTTOM LEFT corner, so
1788
+ // we need to sort descending (b first) on this one.
1791
1789
  return divbY - divaY;
1792
1790
  }
1793
1791
  return aX - bX;
@@ -1799,17 +1797,16 @@ function sortFields(fields) {
1799
1797
  * NOTE: This function mutates the input array.
1800
1798
  */
1801
1799
  function sortDocuments(documents) {
1802
- return documents.sort((a, b) =>
1803
1800
  // The Date conversion is unnecessary 90% of the time but is safer, and this isn't something
1804
1801
  // we do much of so in reality it has almmost no impact.
1805
- a.order !== b.order ? a.order - b.order : new Date(a.created_at).getTime() - new Date(b.created_at).getTime());
1802
+ return documents.sort((a, b) => a.order - b.order || new Date(a.created_at).getTime() - new Date(b.created_at).getTime());
1806
1803
  }
1807
1804
  /**
1808
1805
  * Utility function to sort documents by their order, falling back to created_at.
1809
1806
  * NOTE: This function mutates the input array.
1810
1807
  */
1811
1808
  function sortRecipients(recipients) {
1812
- return recipients?.sort((a, b) => (a.sequence !== b.sequence ? b.sequence - a.sequence : b.order - a.order));
1809
+ return recipients?.sort((a, b) => a.sequence - b.sequence || a.order - b.order);
1813
1810
  }
1814
1811
 
1815
1812
  const canPerformTemplateAction = (profile, action, template) => {