@hubsync/esign-web-sdk 6.5.4 → 6.5.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.
@@ -388,6 +388,8 @@ const VerdocsSign = class {
388
388
  if (e.detail === null) {
389
389
  console.log('[SIGN] Clearing initial');
390
390
  const updateResult = await updateEnvelopeField(this.endpoint, this.envelopeId, this.roleId, field.name, null, false);
391
+ updateResult.value = null;
392
+ this.initialId = null;
391
393
  return this.updateRecipientFieldValue(field.name, updateResult);
392
394
  }
393
395
  // If we already have an initials block, apply it
@@ -428,6 +430,8 @@ const VerdocsSign = class {
428
430
  if (e.detail === null) {
429
431
  console.log('[SIGN] Clearing signature');
430
432
  const updateResult = await updateEnvelopeField(this.endpoint, this.envelopeId, this.roleId, field.name, null, false);
433
+ updateResult.value = null;
434
+ this.signatureId = null;
431
435
  return this.updateRecipientFieldValue(field.name, updateResult);
432
436
  }
433
437
  // If we already have a signature block, apply it
@@ -497,13 +501,13 @@ const VerdocsSign = class {
497
501
  }
498
502
  return;
499
503
  }
500
- const nextRequiredField = this.getNextRequiredField();
501
- if (nextRequiredField) {
502
- const id = getFieldId(nextRequiredField);
504
+ const nextField = this.getNextFieldInOrder();
505
+ if (nextField) {
506
+ const id = getFieldId(nextField);
503
507
  const el = document.getElementById(id);
504
508
  el === null || el === void 0 ? void 0 : el.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'center' });
505
509
  el === null || el === void 0 ? void 0 : el.focusField();
506
- this.focusedField = nextRequiredField.name;
510
+ this.focusedField = nextField.name;
507
511
  }
508
512
  }
509
513
  getRecipientFields() {
@@ -525,24 +529,36 @@ const VerdocsSign = class {
525
529
  }
526
530
  this.updateAllFlags();
527
531
  }
528
- getNextRequiredField() {
529
- // Find and focus the next incomplete field (that is fillable)
530
- const emptyFields = this.getSortedFillableFields().filter(field => field.required && !isFieldFilled(field, this.getRecipientFields()));
531
- sortFields(emptyFields);
532
- // console.log(
533
- // '[SIGN] Pending fields',
534
- // emptyFields.map(f => `${f.name} (${f.type}) req=${f.required}`),
535
- // );
536
- if (emptyFields.length === 0) {
537
- const allUnfilled = this.getSortedFillableFields().filter(field => !isFieldFilled(field, this.getRecipientFields()));
538
- sortFields(allUnfilled);
539
- if (allUnfilled.length > 0) {
540
- // If we are here, there are no required fields left, but there are optional ones.
541
- return this.getNextFieldFromList(allUnfilled);
542
- }
532
+ getNextFieldInOrder() {
533
+ // Find the next incomplete field in overall order (required + optional).
534
+ const fields = this.getSortedFillableFields();
535
+ if (fields.length === 0)
543
536
  return null;
537
+ const recipientFields = this.getRecipientFields();
538
+ const focusedIndex = fields.findIndex(field => field.name === this.focusedField);
539
+ const startIndex = focusedIndex >= 0 ? focusedIndex + 1 : 0;
540
+ for (let i = 0; i < fields.length; i++) {
541
+ const idx = (startIndex + i) % fields.length;
542
+ const field = fields[idx];
543
+ if (!this.isFieldFilledForNav(field, recipientFields)) {
544
+ return field;
545
+ }
546
+ }
547
+ return null;
548
+ }
549
+ isFieldFilledForNav(field, recipientFields) {
550
+ if (field.type === 'signature' || field.type === 'initial') {
551
+ const value = typeof field.value === 'string' ? field.value.trim() : field.value;
552
+ if (!value)
553
+ return false;
554
+ if (value === 'signed' || value === 'initialed')
555
+ return false;
556
+ return true;
557
+ }
558
+ if (field.type === 'dropdown') {
559
+ return isFieldFilled(field, recipientFields) && !!field.value;
544
560
  }
545
- return this.getNextFieldFromList(emptyFields);
561
+ return isFieldFilled(field, recipientFields);
546
562
  }
547
563
  getNextFieldFromList(fields) {
548
564
  const focusedIndex = fields.findIndex(field => field.name === this.focusedField);
@@ -580,12 +596,12 @@ const VerdocsSign = class {
580
596
  // Remove existing flags
581
597
  const existingFlags = controlsDiv.querySelectorAll('.verdocs-flag-instance');
582
598
  existingFlags.forEach(el => el.remove());
583
- let nextField = this.getNextRequiredField();
599
+ let nextField = this.getNextFieldInOrder();
584
600
  const focusedFieldObj = this.getRecipientFields().find(f => f.name === this.focusedField);
585
601
  // If the currently focused field is unfilled, we should point the flag to IT, not the next one.
586
- // getNextRequiredField() is designed for the "Next" button (skipping current), but the visual flag
602
+ // getNextFieldInOrder() is designed for the "Next" button (skipping current), but the visual flag
587
603
  // should guide the user to the current task if it's incomplete.
588
- if (focusedFieldObj && !isFieldFilled(focusedFieldObj, this.getRecipientFields())) {
604
+ if (focusedFieldObj && !this.isFieldFilledForNav(focusedFieldObj, this.getRecipientFields())) {
589
605
  nextField = focusedFieldObj;
590
606
  }
591
607
  if (nextField && nextField.page === pageInfo.pageNumber && nextField.document_id === pageInfo.documentId) {