@hubsync/esign-web-sdk 6.5.3 → 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.
@@ -411,6 +411,8 @@ export class VerdocsSign {
411
411
  if (e.detail === null) {
412
412
  console.log('[SIGN] Clearing initial');
413
413
  const updateResult = await updateEnvelopeField(this.endpoint, this.envelopeId, this.roleId, field.name, null, false);
414
+ updateResult.value = null;
415
+ this.initialId = null;
414
416
  return this.updateRecipientFieldValue(field.name, updateResult);
415
417
  }
416
418
  // If we already have an initials block, apply it
@@ -451,6 +453,8 @@ export class VerdocsSign {
451
453
  if (e.detail === null) {
452
454
  console.log('[SIGN] Clearing signature');
453
455
  const updateResult = await updateEnvelopeField(this.endpoint, this.envelopeId, this.roleId, field.name, null, false);
456
+ updateResult.value = null;
457
+ this.signatureId = null;
454
458
  return this.updateRecipientFieldValue(field.name, updateResult);
455
459
  }
456
460
  // If we already have a signature block, apply it
@@ -520,13 +524,13 @@ export class VerdocsSign {
520
524
  }
521
525
  return;
522
526
  }
523
- const nextRequiredField = this.getNextRequiredField();
524
- if (nextRequiredField) {
525
- const id = getFieldId(nextRequiredField);
527
+ const nextField = this.getNextFieldInOrder();
528
+ if (nextField) {
529
+ const id = getFieldId(nextField);
526
530
  const el = document.getElementById(id);
527
531
  el === null || el === void 0 ? void 0 : el.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'center' });
528
532
  el === null || el === void 0 ? void 0 : el.focusField();
529
- this.focusedField = nextRequiredField.name;
533
+ this.focusedField = nextField.name;
530
534
  }
531
535
  }
532
536
  getRecipientFields() {
@@ -548,24 +552,36 @@ export class VerdocsSign {
548
552
  }
549
553
  this.updateAllFlags();
550
554
  }
551
- getNextRequiredField() {
552
- // Find and focus the next incomplete field (that is fillable)
553
- const emptyFields = this.getSortedFillableFields().filter(field => field.required && !isFieldFilled(field, this.getRecipientFields()));
554
- sortFields(emptyFields);
555
- // console.log(
556
- // '[SIGN] Pending fields',
557
- // emptyFields.map(f => `${f.name} (${f.type}) req=${f.required}`),
558
- // );
559
- if (emptyFields.length === 0) {
560
- const allUnfilled = this.getSortedFillableFields().filter(field => !isFieldFilled(field, this.getRecipientFields()));
561
- sortFields(allUnfilled);
562
- if (allUnfilled.length > 0) {
563
- // If we are here, there are no required fields left, but there are optional ones.
564
- return this.getNextFieldFromList(allUnfilled);
565
- }
555
+ getNextFieldInOrder() {
556
+ // Find the next incomplete field in overall order (required + optional).
557
+ const fields = this.getSortedFillableFields();
558
+ if (fields.length === 0)
566
559
  return null;
560
+ const recipientFields = this.getRecipientFields();
561
+ const focusedIndex = fields.findIndex(field => field.name === this.focusedField);
562
+ const startIndex = focusedIndex >= 0 ? focusedIndex + 1 : 0;
563
+ for (let i = 0; i < fields.length; i++) {
564
+ const idx = (startIndex + i) % fields.length;
565
+ const field = fields[idx];
566
+ if (!this.isFieldFilledForNav(field, recipientFields)) {
567
+ return field;
568
+ }
569
+ }
570
+ return null;
571
+ }
572
+ isFieldFilledForNav(field, recipientFields) {
573
+ if (field.type === 'signature' || field.type === 'initial') {
574
+ const value = typeof field.value === 'string' ? field.value.trim() : field.value;
575
+ if (!value)
576
+ return false;
577
+ if (value === 'signed' || value === 'initialed')
578
+ return false;
579
+ return true;
580
+ }
581
+ if (field.type === 'dropdown') {
582
+ return isFieldFilled(field, recipientFields) && !!field.value;
567
583
  }
568
- return this.getNextFieldFromList(emptyFields);
584
+ return isFieldFilled(field, recipientFields);
569
585
  }
570
586
  getNextFieldFromList(fields) {
571
587
  const focusedIndex = fields.findIndex(field => field.name === this.focusedField);
@@ -603,12 +619,12 @@ export class VerdocsSign {
603
619
  // Remove existing flags
604
620
  const existingFlags = controlsDiv.querySelectorAll('.verdocs-flag-instance');
605
621
  existingFlags.forEach(el => el.remove());
606
- let nextField = this.getNextRequiredField();
622
+ let nextField = this.getNextFieldInOrder();
607
623
  const focusedFieldObj = this.getRecipientFields().find(f => f.name === this.focusedField);
608
624
  // If the currently focused field is unfilled, we should point the flag to IT, not the next one.
609
- // getNextRequiredField() is designed for the "Next" button (skipping current), but the visual flag
625
+ // getNextFieldInOrder() is designed for the "Next" button (skipping current), but the visual flag
610
626
  // should guide the user to the current task if it's incomplete.
611
- if (focusedFieldObj && !isFieldFilled(focusedFieldObj, this.getRecipientFields())) {
627
+ if (focusedFieldObj && !this.isFieldFilledForNav(focusedFieldObj, this.getRecipientFields())) {
612
628
  nextField = focusedFieldObj;
613
629
  }
614
630
  if (nextField && nextField.page === pageInfo.pageNumber && nextField.document_id === pageInfo.documentId) {
@@ -626,13 +642,6 @@ export class VerdocsSign {
626
642
  onSkip: () => {
627
643
  this.handleNext();
628
644
  },
629
- onClick: () => {
630
- var _a;
631
- const id = getFieldId(nextField);
632
- const el = document.getElementById(id);
633
- el === null || el === void 0 ? void 0 : el.scrollIntoView({ behavior: 'smooth', block: 'center' });
634
- (_a = el === null || el === void 0 ? void 0 : el.focusField) === null || _a === void 0 ? void 0 : _a.call(el);
635
- },
636
645
  });
637
646
  }
638
647
  }
@@ -949,7 +958,7 @@ export class VerdocsSign {
949
958
  }
950
959
  return (h("verdocs-signing-progress", { mode: mode, current: Math.max(1, currentIndex), total: totalFields, remainingFields: remainingFields, progress: progress, fieldLabel: getFieldLabel(focusedFieldObj), fieldCompleted: focusedFieldObj ? !!isFilled(focusedFieldObj) : false, onStarted: () => {
951
960
  this.adoptingSignature = true;
952
- // this.handleNext();
961
+ this.handleNext();
953
962
  }, onNext: () => this.handleNext(), onPrevious: () => this.handlePrev(), onExit: () => this.handleNext() }));
954
963
  })(), h("div", { class: `document signed-document-container zoom-${this.zoomLevel}` }, (this.envelope.documents || []).map(envelopeDocument => {
955
964
  const pageNumbers = integerSequence(1, envelopeDocument.pages);