@verdocs/web-sdk 2.3.86 → 2.3.88

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.
Files changed (73) hide show
  1. package/dist/cjs/{utils-13f8ed3f.js → utils-e2bd04bf.js} +2 -4
  2. package/dist/cjs/verdocs-contact-picker_2.cjs.entry.js +1 -1
  3. package/dist/cjs/verdocs-envelope-document-page.cjs.entry.js +1 -1
  4. package/dist/cjs/verdocs-envelopes-list.cjs.entry.js +1 -1
  5. package/dist/cjs/verdocs-field-attachment_15.cjs.entry.js +1 -1
  6. package/dist/cjs/verdocs-field-payment.cjs.entry.js +1 -1
  7. package/dist/cjs/verdocs-pagination_2.cjs.entry.js +1 -1
  8. package/dist/cjs/verdocs-preview_8.cjs.entry.js +1 -1
  9. package/dist/cjs/verdocs-settings-api-keys_4.cjs.entry.js +1 -1
  10. package/dist/cjs/verdocs-sign.cjs.entry.js +56 -34
  11. package/dist/cjs/verdocs-template-fields_4.cjs.entry.js +1 -1
  12. package/dist/cjs/verdocs-view.cjs.entry.js +1 -1
  13. package/dist/collection/components/embeds/verdocs-sign/verdocs-sign.js +55 -33
  14. package/dist/collection/components/embeds/verdocs-sign/verdocs-sign.stories.js +3 -3
  15. package/dist/collection/utils/utils.js +2 -4
  16. package/dist/components/utils.js +2 -4
  17. package/dist/components/verdocs-sign.js +55 -33
  18. package/dist/custom-elements.json +2147 -0
  19. package/dist/docs.json +1 -1
  20. package/dist/esm/{utils-a56ee5e9.js → utils-f35325fe.js} +2 -4
  21. package/dist/esm/verdocs-contact-picker_2.entry.js +1 -1
  22. package/dist/esm/verdocs-envelope-document-page.entry.js +1 -1
  23. package/dist/esm/verdocs-envelopes-list.entry.js +1 -1
  24. package/dist/esm/verdocs-field-attachment_15.entry.js +1 -1
  25. package/dist/esm/verdocs-field-payment.entry.js +1 -1
  26. package/dist/esm/verdocs-pagination_2.entry.js +1 -1
  27. package/dist/esm/verdocs-preview_8.entry.js +1 -1
  28. package/dist/esm/verdocs-settings-api-keys_4.entry.js +1 -1
  29. package/dist/esm/verdocs-sign.entry.js +56 -34
  30. package/dist/esm/verdocs-template-fields_4.entry.js +1 -1
  31. package/dist/esm/verdocs-view.entry.js +1 -1
  32. package/dist/esm-es5/{utils-a56ee5e9.js → utils-f35325fe.js} +1 -1
  33. package/dist/esm-es5/verdocs-contact-picker_2.entry.js +1 -1
  34. package/dist/esm-es5/verdocs-envelope-document-page.entry.js +1 -1
  35. package/dist/esm-es5/verdocs-envelopes-list.entry.js +1 -1
  36. package/dist/esm-es5/verdocs-field-attachment_15.entry.js +1 -1
  37. package/dist/esm-es5/verdocs-field-payment.entry.js +1 -1
  38. package/dist/esm-es5/verdocs-pagination_2.entry.js +1 -1
  39. package/dist/esm-es5/verdocs-preview_8.entry.js +1 -1
  40. package/dist/esm-es5/verdocs-settings-api-keys_4.entry.js +1 -1
  41. package/dist/esm-es5/verdocs-sign.entry.js +1 -1
  42. package/dist/esm-es5/verdocs-template-fields_4.entry.js +1 -1
  43. package/dist/esm-es5/verdocs-view.entry.js +1 -1
  44. package/dist/types/components/embeds/verdocs-sign/verdocs-sign.d.ts +2 -0
  45. package/dist/types/utils/utils.d.ts +1 -1
  46. package/dist/verdocs-web-sdk/{p-e63fe8b9.system.entry.js → p-078e5b77.system.entry.js} +1 -1
  47. package/dist/verdocs-web-sdk/{p-0ef04e14.system.entry.js → p-1a2d3a78.system.entry.js} +1 -1
  48. package/dist/verdocs-web-sdk/{p-dd9dba09.entry.js → p-1acb7da0.entry.js} +1 -1
  49. package/dist/verdocs-web-sdk/p-2ad3ba4f.entry.js +1 -0
  50. package/dist/verdocs-web-sdk/{p-bb983c03.entry.js → p-2b874610.entry.js} +1 -1
  51. package/dist/verdocs-web-sdk/{p-be7390d8.system.entry.js → p-33c284a7.system.entry.js} +1 -1
  52. package/dist/verdocs-web-sdk/{p-964f83ef.entry.js → p-43bdeda7.entry.js} +1 -1
  53. package/dist/verdocs-web-sdk/{p-5c67e9f6.system.entry.js → p-473926f1.system.entry.js} +1 -1
  54. package/dist/verdocs-web-sdk/{p-7f487279.entry.js → p-55e47f7d.entry.js} +1 -1
  55. package/dist/verdocs-web-sdk/{p-69422d8f.system.entry.js → p-621549c9.system.entry.js} +1 -1
  56. package/dist/verdocs-web-sdk/{p-b72328af.js → p-632bdc29.js} +1 -1
  57. package/dist/verdocs-web-sdk/{p-3dc2013b.system.entry.js → p-64974b4f.system.entry.js} +1 -1
  58. package/dist/verdocs-web-sdk/{p-1fa5ef9a.entry.js → p-683e778c.entry.js} +1 -1
  59. package/dist/verdocs-web-sdk/{p-1823e8cd.entry.js → p-81acd17f.entry.js} +1 -1
  60. package/dist/verdocs-web-sdk/{p-e1b527eb.entry.js → p-851737fb.entry.js} +1 -1
  61. package/dist/verdocs-web-sdk/{p-bb2b0122.entry.js → p-8a5ef117.entry.js} +1 -1
  62. package/dist/verdocs-web-sdk/{p-21294863.system.entry.js → p-907de1bb.system.entry.js} +1 -1
  63. package/dist/verdocs-web-sdk/{p-98c9b7d7.entry.js → p-9d8e63ea.entry.js} +1 -1
  64. package/dist/verdocs-web-sdk/{p-b55a122e.system.entry.js → p-a5499e42.system.entry.js} +1 -1
  65. package/dist/verdocs-web-sdk/{p-cf6a9502.entry.js → p-c0e43c7f.entry.js} +1 -1
  66. package/dist/verdocs-web-sdk/{p-8de34628.system.entry.js → p-d0a110f1.system.entry.js} +1 -1
  67. package/dist/verdocs-web-sdk/{p-0cafdb16.system.js → p-e041e991.system.js} +1 -1
  68. package/dist/verdocs-web-sdk/{p-04bef805.system.entry.js → p-ee408daa.system.entry.js} +1 -1
  69. package/dist/verdocs-web-sdk/p-f04bf956.system.js +1 -1
  70. package/dist/verdocs-web-sdk/{p-012d2533.system.entry.js → p-f461f285.system.entry.js} +1 -1
  71. package/dist/verdocs-web-sdk/verdocs-web-sdk.esm.js +1 -1
  72. package/package.json +1 -1
  73. package/dist/verdocs-web-sdk/p-a5f94a3f.entry.js +0 -1
@@ -181,11 +181,9 @@ const updateDocumentFieldValue = (field) => {
181
181
  existingField.setAttribute('disabled', false); // We need this to trigger a re-render
182
182
  }
183
183
  };
184
- const renderDocumentField = (field, docPage, fieldOptions) => {
184
+ const renderDocumentField = (field, docPage, fieldOptions, tabIndex = 1) => {
185
185
  var _a, _b;
186
- // console.log('rdf', field);
187
186
  const { disabled = false, editable = false, draggable = false, done = false } = fieldOptions;
188
- // console.log('[renderDocumentField]', field, docPage, roleIndex, fieldOptions);
189
187
  const controlsDiv = document.getElementById(docPage.containerId + '-controls');
190
188
  if (!controlsDiv) {
191
189
  console.log('[renderDocumentField] No controls DIV found', docPage.containerId + '-controls', docPage);
@@ -223,7 +221,7 @@ const renderDocumentField = (field, docPage, fieldOptions) => {
223
221
  el.setAttribute('disabled', true);
224
222
  }
225
223
  else {
226
- el.setAttribute('tabIndex', 1);
224
+ el.setAttribute('tabIndex', tabIndex);
227
225
  }
228
226
  if (editable) {
229
227
  el.setAttribute('editable', true);
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  const index = require('./index-5463795e.js');
6
6
  require('./Types-f89f9116.js');
7
7
  const VerdocsEndpoint = require('./VerdocsEndpoint-3036bbb7.js');
8
- const utils = require('./utils-13f8ed3f.js');
8
+ const utils = require('./utils-e2bd04bf.js');
9
9
  require('./_commonjsHelpers-0c557e26.js');
10
10
  require('./Envelopes-0b9deb2c.js');
11
11
  require('./Types-f83b8488.js');
@@ -6,7 +6,7 @@ const index = require('./index-5463795e.js');
6
6
  const Envelopes = require('./Envelopes-0b9deb2c.js');
7
7
  require('./Types-f89f9116.js');
8
8
  const VerdocsEndpoint = require('./VerdocsEndpoint-3036bbb7.js');
9
- const utils = require('./utils-13f8ed3f.js');
9
+ const utils = require('./utils-e2bd04bf.js');
10
10
  require('./_commonjsHelpers-0c557e26.js');
11
11
  require('./Types-f83b8488.js');
12
12
  require('./index-7c19ba1d.js');
@@ -8,7 +8,7 @@ const Permissions = require('./Permissions-1436f847.js');
8
8
  require('./Types-f89f9116.js');
9
9
  const VerdocsEndpoint = require('./VerdocsEndpoint-3036bbb7.js');
10
10
  const Primitives = require('./Primitives-a59870a2.js');
11
- const utils = require('./utils-13f8ed3f.js');
11
+ const utils = require('./utils-e2bd04bf.js');
12
12
  const Toast = require('./Toast-06880504.js');
13
13
  const errors = require('./errors-0396da3d.js');
14
14
  require('./_commonjsHelpers-0c557e26.js');
@@ -6,7 +6,7 @@ const index = require('./index-5463795e.js');
6
6
  const Colors = require('./Colors-e809dcc9.js');
7
7
  const TemplateRoleStore = require('./TemplateRoleStore-a7f2b586.js');
8
8
  const TemplateFieldStore = require('./TemplateFieldStore-3d25fc86.js');
9
- const utils = require('./utils-13f8ed3f.js');
9
+ const utils = require('./utils-e2bd04bf.js');
10
10
  const Icons = require('./Icons-3286d014.js');
11
11
  const _commonjsHelpers = require('./_commonjsHelpers-0c557e26.js');
12
12
  const Types = require('./Types-f83b8488.js');
@@ -6,7 +6,7 @@ const index = require('./index-5463795e.js');
6
6
  const Colors = require('./Colors-e809dcc9.js');
7
7
  const TemplateRoleStore = require('./TemplateRoleStore-a7f2b586.js');
8
8
  const TemplateFieldStore = require('./TemplateFieldStore-3d25fc86.js');
9
- const utils = require('./utils-13f8ed3f.js');
9
+ const utils = require('./utils-e2bd04bf.js');
10
10
  require('./index-f712049c.js');
11
11
  require('./_commonjsHelpers-0c557e26.js');
12
12
  require('./Envelopes-0b9deb2c.js');
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const index = require('./index-5463795e.js');
6
6
  const Primitives = require('./Primitives-a59870a2.js');
7
- const utils = require('./utils-13f8ed3f.js');
7
+ const utils = require('./utils-e2bd04bf.js');
8
8
  const popper = require('./popper-d7adcfc6.js');
9
9
  require('./_commonjsHelpers-0c557e26.js');
10
10
  require('./Envelopes-0b9deb2c.js');
@@ -8,7 +8,7 @@ const VerdocsEndpoint = require('./VerdocsEndpoint-3036bbb7.js');
8
8
  const TemplateFieldStore = require('./TemplateFieldStore-3d25fc86.js');
9
9
  const TemplateRoleStore = require('./TemplateRoleStore-a7f2b586.js');
10
10
  const TemplateStore = require('./TemplateStore-62c90f8c.js');
11
- const utils = require('./utils-13f8ed3f.js');
11
+ const utils = require('./utils-e2bd04bf.js');
12
12
  const errors = require('./errors-0396da3d.js');
13
13
  const Envelopes = require('./Envelopes-0b9deb2c.js');
14
14
  const Validators = require('./Validators-16e6d7d1.js');
@@ -10,7 +10,7 @@ const Toast = require('./Toast-06880504.js');
10
10
  const errors = require('./errors-0396da3d.js');
11
11
  const Profiles = require('./Profiles-1a26e4eb.js');
12
12
  const index$1 = require('./index-7c19ba1d.js');
13
- const utils = require('./utils-13f8ed3f.js');
13
+ const utils = require('./utils-e2bd04bf.js');
14
14
  require('./_commonjsHelpers-0c557e26.js');
15
15
  require('./Envelopes-0b9deb2c.js');
16
16
  require('./Types-f83b8488.js');
@@ -9,7 +9,7 @@ const Recipients = require('./Recipients-f3d6cf10.js');
9
9
  const VerdocsEndpoint = require('./VerdocsEndpoint-3036bbb7.js');
10
10
  const Validators = require('./Validators-16e6d7d1.js');
11
11
  const Primitives = require('./Primitives-a59870a2.js');
12
- const utils = require('./utils-13f8ed3f.js');
12
+ const utils = require('./utils-e2bd04bf.js');
13
13
  const TemplateFieldStore = require('./TemplateFieldStore-3d25fc86.js');
14
14
  const Toast = require('./Toast-06880504.js');
15
15
  const errors = require('./errors-0396da3d.js');
@@ -300,9 +300,8 @@ const VerdocsSign = class {
300
300
  break;
301
301
  }
302
302
  }
303
- isFieldValid(field) {
303
+ isFieldFilled(field) {
304
304
  var _a, _b, _c, _d, _e, _f, _g;
305
- const { required = false } = field;
306
305
  const { result = '', value = '', base64 = '' } = field.settings || {};
307
306
  switch (field.type) {
308
307
  case 'textbox':
@@ -312,25 +311,25 @@ const VerdocsSign = class {
312
311
  case 'phone':
313
312
  return Validators.isValidPhone(result);
314
313
  default:
315
- return !required || result !== '';
314
+ return result !== '';
316
315
  }
317
316
  case 'signature':
318
317
  case 'initial':
319
- return !required || base64 !== '';
318
+ return base64 !== '';
320
319
  // Timestamp fields get automatically filled when the envelope is submitted.
321
320
  case 'timestamp':
322
321
  return true;
323
322
  case 'textarea':
324
323
  case 'date':
325
324
  case 'attachment':
326
- return !required || result !== '';
325
+ return result !== '';
327
326
  case 'dropdown':
328
- return !required || value !== '';
327
+ return value !== '';
329
328
  case 'checkbox_group':
330
329
  const checkedCount = (((_c = (_b = field.settings) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.filter(option => option.checked)) || []).length;
331
- return !required || (checkedCount >= (((_d = field.settings) === null || _d === void 0 ? void 0 : _d.minimum_checked) || 0) && checkedCount <= (((_e = field.settings) === null || _e === void 0 ? void 0 : _e.maximum_checked) || 999));
330
+ return checkedCount >= (((_d = field.settings) === null || _d === void 0 ? void 0 : _d.minimum_checked) || 0) && checkedCount <= (((_e = field.settings) === null || _e === void 0 ? void 0 : _e.maximum_checked) || 999);
332
331
  case 'radio_button_group':
333
- return !required || (((_g = (_f = field.settings) === null || _f === void 0 ? void 0 : _f.options) === null || _g === void 0 ? void 0 : _g.filter(option => option.selected)) || []).length > 0;
332
+ return (((_g = (_f = field.settings) === null || _f === void 0 ? void 0 : _f.options) === null || _g === void 0 ? void 0 : _g.filter(option => option.selected)) || []).length > 0;
334
333
  // TODO
335
334
  // case 'checkbox':
336
335
  // return <verdocs-field-checkbox style={style} value={result || ''} id={id} />;
@@ -340,6 +339,28 @@ const VerdocsSign = class {
340
339
  return false;
341
340
  }
342
341
  }
342
+ isFieldValid(field) {
343
+ const { required = false } = field;
344
+ return !required || this.isFieldFilled(field);
345
+ }
346
+ getSortedFillableFields() {
347
+ const recipientFields = this.getRecipientFields().filter(field => field.type !== 'timestamp');
348
+ recipientFields.sort((a, b) => {
349
+ var _a, _b, _c, _d;
350
+ const aX = ((_a = a.settings) === null || _a === void 0 ? void 0 : _a.x) || 0;
351
+ const aY = ((_b = a.settings) === null || _b === void 0 ? void 0 : _b.y) || 0;
352
+ const bX = ((_c = b.settings) === null || _c === void 0 ? void 0 : _c.x) || 0;
353
+ const bY = ((_d = b.settings) === null || _d === void 0 ? void 0 : _d.y) || 0;
354
+ // NOTE: Logic looks a little strange X vs Y. It's because we go top down,
355
+ // left to right. But Y coordinates are inverted in PDFs. The reason for
356
+ // the division is because no human makes perfect templates and frequently
357
+ // two fields on the "same line" will be slightly offset vertically.
358
+ const divaY = Math.floor(aY / 5);
359
+ const divbY = Math.floor(bY / 5);
360
+ return divbY !== divaY ? divbY - divaY : aX - bX;
361
+ });
362
+ return recipientFields;
363
+ }
343
364
  async handleNext() {
344
365
  var _a, _b;
345
366
  if (this.nextSubmits) {
@@ -365,35 +386,39 @@ const VerdocsSign = class {
365
386
  this.submitting = false;
366
387
  return;
367
388
  }
368
- // Find and focus the next incomplete required field (that is fillable)
369
- const requiredFields = this.getRecipientFields()
370
- .filter(field => field.required)
371
- .filter(field => field.type !== 'timestamp');
372
- requiredFields.sort((a, b) => {
389
+ // Find and focus the next incomplete` field (that is fillable)
390
+ const emptyFields = this.getSortedFillableFields().filter(field => !this.isFieldFilled(field));
391
+ emptyFields.sort((a, b) => {
373
392
  var _a, _b, _c, _d;
374
393
  const aX = ((_a = a.settings) === null || _a === void 0 ? void 0 : _a.x) || 0;
375
394
  const aY = ((_b = a.settings) === null || _b === void 0 ? void 0 : _b.y) || 0;
376
395
  const bX = ((_c = b.settings) === null || _c === void 0 ? void 0 : _c.x) || 0;
377
396
  const bY = ((_d = b.settings) === null || _d === void 0 ? void 0 : _d.y) || 0;
378
- return bY !== aY ? bY - aY : bX - aX;
397
+ // NOTE: Logic looks a little strange X vs Y. It's because we go top down,
398
+ // left to right. But Y coordinates are inverted in PDFs. The reason for
399
+ // the division is because no human makes perfect templates and frequently
400
+ // two fields on the "same line" will be slightly offset vertically.
401
+ const divaY = Math.floor(aY / 5);
402
+ const divbY = Math.floor(bY / 5);
403
+ return divbY !== divaY ? divbY - divaY : aX - bX;
379
404
  });
380
- const focusedIndex = requiredFields.findIndex(field => field.name === this.focusedField);
405
+ const focusedIndex = emptyFields.findIndex(field => field.name === this.focusedField);
381
406
  let nextFocusedIndex = focusedIndex + 1;
382
- if (nextFocusedIndex >= requiredFields.length) {
407
+ if (nextFocusedIndex >= emptyFields.length) {
383
408
  nextFocusedIndex = 0;
384
409
  }
385
- let nextRequiredField = requiredFields[nextFocusedIndex];
410
+ let nextRequiredField = emptyFields[nextFocusedIndex];
386
411
  // Skip signature and initial fields that are already filled in. We have to count our "skips" just in case, to avoid infinite loops.
387
412
  let skips = 0;
388
- if (skips < requiredFields.length && ['signature', 'initial'].includes(nextRequiredField.type) && ((_b = nextRequiredField.settings) === null || _b === void 0 ? void 0 : _b.result) === 'signed') {
413
+ if (skips < emptyFields.length && ['signature', 'initial'].includes(nextRequiredField.type) && ((_b = nextRequiredField.settings) === null || _b === void 0 ? void 0 : _b.result) === 'signed') {
389
414
  skips++;
390
415
  nextFocusedIndex++;
391
- if (nextFocusedIndex >= requiredFields.length) {
416
+ if (nextFocusedIndex >= emptyFields.length) {
392
417
  nextFocusedIndex = 0;
393
418
  }
394
- nextRequiredField = requiredFields[nextFocusedIndex];
419
+ nextRequiredField = emptyFields[nextFocusedIndex];
395
420
  }
396
- if (skips >= requiredFields.length) {
421
+ if (skips >= emptyFields.length) {
397
422
  nextRequiredField = null;
398
423
  }
399
424
  if (nextRequiredField) {
@@ -457,22 +482,19 @@ const VerdocsSign = class {
457
482
  }
458
483
  handlePageRendered(e) {
459
484
  const pageInfo = e.detail;
460
- // const roleIndex = getRoleIndex(this.roleStore, this.recipient.role_name);
461
- // console.log(
462
- // 'hpr',
463
- // this.recipient,
464
- // this.envelope.fields.filter(field => field.recipient_role === this.recipient.role_name),
465
- // );
466
- const recipientFields = this.getRecipientFields().filter(field => field.page === pageInfo.pageNumber);
467
- // console.log('[SIGN] Page rendered, updating fields', {pageInfo, roleIndex, recipientFields});
485
+ // NOTE: We don't filter on pageNumber here because we need the position in the
486
+ // entire list to set the tabIndex.
487
+ const recipientFields = this.getSortedFillableFields();
488
+ // this.getRecipientFields().filter(field => field.page === pageInfo.pageNumber);
468
489
  // First render the fields for the signer
469
490
  // Also show field placeholders for other signers who have yet to act
470
491
  // In template list in Beta, show second date being sorted on
471
492
  // Sign top to bottom left to right
472
- recipientFields
473
- .filter(field => field.page === pageInfo.pageNumber)
474
- .forEach(field => {
475
- const el = utils.renderDocumentField(field, pageInfo, { disabled: false, editable: false, draggable: false, done: this.isDone });
493
+ recipientFields.forEach((field, tabIndex) => {
494
+ if (field.page !== pageInfo.pageNumber) {
495
+ return;
496
+ }
497
+ const el = utils.renderDocumentField(field, pageInfo, { disabled: false, editable: false, draggable: false, done: this.isDone }, tabIndex);
476
498
  if (!el) {
477
499
  return;
478
500
  }
@@ -9,7 +9,7 @@ const VerdocsEndpoint = require('./VerdocsEndpoint-3036bbb7.js');
9
9
  const Fields = require('./Fields-705a2168.js');
10
10
  const Primitives = require('./Primitives-a59870a2.js');
11
11
  const TemplateFieldStore = require('./TemplateFieldStore-3d25fc86.js');
12
- const utils = require('./utils-13f8ed3f.js');
12
+ const utils = require('./utils-e2bd04bf.js');
13
13
  const TemplateRoleStore = require('./TemplateRoleStore-a7f2b586.js');
14
14
  const TemplateStore = require('./TemplateStore-62c90f8c.js');
15
15
  const errors = require('./errors-0396da3d.js');
@@ -8,7 +8,7 @@ const Permissions = require('./Permissions-1436f847.js');
8
8
  require('./Types-f89f9116.js');
9
9
  const VerdocsEndpoint = require('./VerdocsEndpoint-3036bbb7.js');
10
10
  const Primitives = require('./Primitives-a59870a2.js');
11
- const utils = require('./utils-13f8ed3f.js');
11
+ const utils = require('./utils-e2bd04bf.js');
12
12
  const errors = require('./errors-0396da3d.js');
13
13
  require('./_commonjsHelpers-0c557e26.js');
14
14
  require('./Types-f83b8488.js');
@@ -277,9 +277,8 @@ export class VerdocsSign {
277
277
  break;
278
278
  }
279
279
  }
280
- isFieldValid(field) {
280
+ isFieldFilled(field) {
281
281
  var _a, _b, _c, _d, _e, _f, _g;
282
- const { required = false } = field;
283
282
  const { result = '', value = '', base64 = '' } = field.settings || {};
284
283
  switch (field.type) {
285
284
  case 'textbox':
@@ -289,25 +288,25 @@ export class VerdocsSign {
289
288
  case 'phone':
290
289
  return isValidPhone(result);
291
290
  default:
292
- return !required || result !== '';
291
+ return result !== '';
293
292
  }
294
293
  case 'signature':
295
294
  case 'initial':
296
- return !required || base64 !== '';
295
+ return base64 !== '';
297
296
  // Timestamp fields get automatically filled when the envelope is submitted.
298
297
  case 'timestamp':
299
298
  return true;
300
299
  case 'textarea':
301
300
  case 'date':
302
301
  case 'attachment':
303
- return !required || result !== '';
302
+ return result !== '';
304
303
  case 'dropdown':
305
- return !required || value !== '';
304
+ return value !== '';
306
305
  case 'checkbox_group':
307
306
  const checkedCount = (((_c = (_b = field.settings) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.filter(option => option.checked)) || []).length;
308
- return !required || (checkedCount >= (((_d = field.settings) === null || _d === void 0 ? void 0 : _d.minimum_checked) || 0) && checkedCount <= (((_e = field.settings) === null || _e === void 0 ? void 0 : _e.maximum_checked) || 999));
307
+ return checkedCount >= (((_d = field.settings) === null || _d === void 0 ? void 0 : _d.minimum_checked) || 0) && checkedCount <= (((_e = field.settings) === null || _e === void 0 ? void 0 : _e.maximum_checked) || 999);
309
308
  case 'radio_button_group':
310
- return !required || (((_g = (_f = field.settings) === null || _f === void 0 ? void 0 : _f.options) === null || _g === void 0 ? void 0 : _g.filter(option => option.selected)) || []).length > 0;
309
+ return (((_g = (_f = field.settings) === null || _f === void 0 ? void 0 : _f.options) === null || _g === void 0 ? void 0 : _g.filter(option => option.selected)) || []).length > 0;
311
310
  // TODO
312
311
  // case 'checkbox':
313
312
  // return <verdocs-field-checkbox style={style} value={result || ''} id={id} />;
@@ -317,6 +316,28 @@ export class VerdocsSign {
317
316
  return false;
318
317
  }
319
318
  }
319
+ isFieldValid(field) {
320
+ const { required = false } = field;
321
+ return !required || this.isFieldFilled(field);
322
+ }
323
+ getSortedFillableFields() {
324
+ const recipientFields = this.getRecipientFields().filter(field => field.type !== 'timestamp');
325
+ recipientFields.sort((a, b) => {
326
+ var _a, _b, _c, _d;
327
+ const aX = ((_a = a.settings) === null || _a === void 0 ? void 0 : _a.x) || 0;
328
+ const aY = ((_b = a.settings) === null || _b === void 0 ? void 0 : _b.y) || 0;
329
+ const bX = ((_c = b.settings) === null || _c === void 0 ? void 0 : _c.x) || 0;
330
+ const bY = ((_d = b.settings) === null || _d === void 0 ? void 0 : _d.y) || 0;
331
+ // NOTE: Logic looks a little strange X vs Y. It's because we go top down,
332
+ // left to right. But Y coordinates are inverted in PDFs. The reason for
333
+ // the division is because no human makes perfect templates and frequently
334
+ // two fields on the "same line" will be slightly offset vertically.
335
+ const divaY = Math.floor(aY / 5);
336
+ const divbY = Math.floor(bY / 5);
337
+ return divbY !== divaY ? divbY - divaY : aX - bX;
338
+ });
339
+ return recipientFields;
340
+ }
320
341
  async handleNext() {
321
342
  var _a, _b;
322
343
  if (this.nextSubmits) {
@@ -342,35 +363,39 @@ export class VerdocsSign {
342
363
  this.submitting = false;
343
364
  return;
344
365
  }
345
- // Find and focus the next incomplete required field (that is fillable)
346
- const requiredFields = this.getRecipientFields()
347
- .filter(field => field.required)
348
- .filter(field => field.type !== 'timestamp');
349
- requiredFields.sort((a, b) => {
366
+ // Find and focus the next incomplete` field (that is fillable)
367
+ const emptyFields = this.getSortedFillableFields().filter(field => !this.isFieldFilled(field));
368
+ emptyFields.sort((a, b) => {
350
369
  var _a, _b, _c, _d;
351
370
  const aX = ((_a = a.settings) === null || _a === void 0 ? void 0 : _a.x) || 0;
352
371
  const aY = ((_b = a.settings) === null || _b === void 0 ? void 0 : _b.y) || 0;
353
372
  const bX = ((_c = b.settings) === null || _c === void 0 ? void 0 : _c.x) || 0;
354
373
  const bY = ((_d = b.settings) === null || _d === void 0 ? void 0 : _d.y) || 0;
355
- return bY !== aY ? bY - aY : bX - aX;
374
+ // NOTE: Logic looks a little strange X vs Y. It's because we go top down,
375
+ // left to right. But Y coordinates are inverted in PDFs. The reason for
376
+ // the division is because no human makes perfect templates and frequently
377
+ // two fields on the "same line" will be slightly offset vertically.
378
+ const divaY = Math.floor(aY / 5);
379
+ const divbY = Math.floor(bY / 5);
380
+ return divbY !== divaY ? divbY - divaY : aX - bX;
356
381
  });
357
- const focusedIndex = requiredFields.findIndex(field => field.name === this.focusedField);
382
+ const focusedIndex = emptyFields.findIndex(field => field.name === this.focusedField);
358
383
  let nextFocusedIndex = focusedIndex + 1;
359
- if (nextFocusedIndex >= requiredFields.length) {
384
+ if (nextFocusedIndex >= emptyFields.length) {
360
385
  nextFocusedIndex = 0;
361
386
  }
362
- let nextRequiredField = requiredFields[nextFocusedIndex];
387
+ let nextRequiredField = emptyFields[nextFocusedIndex];
363
388
  // Skip signature and initial fields that are already filled in. We have to count our "skips" just in case, to avoid infinite loops.
364
389
  let skips = 0;
365
- if (skips < requiredFields.length && ['signature', 'initial'].includes(nextRequiredField.type) && ((_b = nextRequiredField.settings) === null || _b === void 0 ? void 0 : _b.result) === 'signed') {
390
+ if (skips < emptyFields.length && ['signature', 'initial'].includes(nextRequiredField.type) && ((_b = nextRequiredField.settings) === null || _b === void 0 ? void 0 : _b.result) === 'signed') {
366
391
  skips++;
367
392
  nextFocusedIndex++;
368
- if (nextFocusedIndex >= requiredFields.length) {
393
+ if (nextFocusedIndex >= emptyFields.length) {
369
394
  nextFocusedIndex = 0;
370
395
  }
371
- nextRequiredField = requiredFields[nextFocusedIndex];
396
+ nextRequiredField = emptyFields[nextFocusedIndex];
372
397
  }
373
- if (skips >= requiredFields.length) {
398
+ if (skips >= emptyFields.length) {
374
399
  nextRequiredField = null;
375
400
  }
376
401
  if (nextRequiredField) {
@@ -434,22 +459,19 @@ export class VerdocsSign {
434
459
  }
435
460
  handlePageRendered(e) {
436
461
  const pageInfo = e.detail;
437
- // const roleIndex = getRoleIndex(this.roleStore, this.recipient.role_name);
438
- // console.log(
439
- // 'hpr',
440
- // this.recipient,
441
- // this.envelope.fields.filter(field => field.recipient_role === this.recipient.role_name),
442
- // );
443
- const recipientFields = this.getRecipientFields().filter(field => field.page === pageInfo.pageNumber);
444
- // console.log('[SIGN] Page rendered, updating fields', {pageInfo, roleIndex, recipientFields});
462
+ // NOTE: We don't filter on pageNumber here because we need the position in the
463
+ // entire list to set the tabIndex.
464
+ const recipientFields = this.getSortedFillableFields();
465
+ // this.getRecipientFields().filter(field => field.page === pageInfo.pageNumber);
445
466
  // First render the fields for the signer
446
467
  // Also show field placeholders for other signers who have yet to act
447
468
  // In template list in Beta, show second date being sorted on
448
469
  // Sign top to bottom left to right
449
- recipientFields
450
- .filter(field => field.page === pageInfo.pageNumber)
451
- .forEach(field => {
452
- const el = renderDocumentField(field, pageInfo, { disabled: false, editable: false, draggable: false, done: this.isDone });
470
+ recipientFields.forEach((field, tabIndex) => {
471
+ if (field.page !== pageInfo.pageNumber) {
472
+ return;
473
+ }
474
+ const el = renderDocumentField(field, pageInfo, { disabled: false, editable: false, draggable: false, done: this.isDone }, tabIndex);
453
475
  if (!el) {
454
476
  return;
455
477
  }
@@ -3,9 +3,9 @@ export default {
3
3
  title: 'Embeds/Sign',
4
4
  component: 'verdocs-sign',
5
5
  args: {
6
- envelopeId: '',
7
- roleId: '',
8
- inviteCode: '',
6
+ envelopeId: 'f2de9204-c56f-4fe7-9348-0736bc14bbcd',
7
+ roleId: 'Recipient 1',
8
+ inviteCode: '817ce4e62d747611388276555afc0016',
9
9
  },
10
10
  argTypes: {
11
11
  envelopeId: {
@@ -116,11 +116,9 @@ export const updateDocumentFieldValue = (field) => {
116
116
  existingField.setAttribute('disabled', false); // We need this to trigger a re-render
117
117
  }
118
118
  };
119
- export const renderDocumentField = (field, docPage, fieldOptions) => {
119
+ export const renderDocumentField = (field, docPage, fieldOptions, tabIndex = 1) => {
120
120
  var _a, _b;
121
- // console.log('rdf', field);
122
121
  const { disabled = false, editable = false, draggable = false, done = false } = fieldOptions;
123
- // console.log('[renderDocumentField]', field, docPage, roleIndex, fieldOptions);
124
122
  const controlsDiv = document.getElementById(docPage.containerId + '-controls');
125
123
  if (!controlsDiv) {
126
124
  console.log('[renderDocumentField] No controls DIV found', docPage.containerId + '-controls', docPage);
@@ -158,7 +156,7 @@ export const renderDocumentField = (field, docPage, fieldOptions) => {
158
156
  el.setAttribute('disabled', true);
159
157
  }
160
158
  else {
161
- el.setAttribute('tabIndex', 1);
159
+ el.setAttribute('tabIndex', tabIndex);
162
160
  }
163
161
  if (editable) {
164
162
  el.setAttribute('editable', true);
@@ -137,11 +137,9 @@ const updateDocumentFieldValue = (field) => {
137
137
  existingField.setAttribute('disabled', false); // We need this to trigger a re-render
138
138
  }
139
139
  };
140
- const renderDocumentField = (field, docPage, fieldOptions) => {
140
+ const renderDocumentField = (field, docPage, fieldOptions, tabIndex = 1) => {
141
141
  var _a, _b;
142
- // console.log('rdf', field);
143
142
  const { disabled = false, editable = false, draggable = false, done = false } = fieldOptions;
144
- // console.log('[renderDocumentField]', field, docPage, roleIndex, fieldOptions);
145
143
  const controlsDiv = document.getElementById(docPage.containerId + '-controls');
146
144
  if (!controlsDiv) {
147
145
  console.log('[renderDocumentField] No controls DIV found', docPage.containerId + '-controls', docPage);
@@ -179,7 +177,7 @@ const renderDocumentField = (field, docPage, fieldOptions) => {
179
177
  el.setAttribute('disabled', true);
180
178
  }
181
179
  else {
182
- el.setAttribute('tabIndex', 1);
180
+ el.setAttribute('tabIndex', tabIndex);
183
181
  }
184
182
  if (editable) {
185
183
  el.setAttribute('editable', true);