@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.
@@ -414,6 +414,8 @@ const VerdocsSign$1 = /*@__PURE__*/ proxyCustomElement(class VerdocsSign extends
414
414
  if (e.detail === null) {
415
415
  console.log('[SIGN] Clearing initial');
416
416
  const updateResult = await updateEnvelopeField(this.endpoint, this.envelopeId, this.roleId, field.name, null, false);
417
+ updateResult.value = null;
418
+ this.initialId = null;
417
419
  return this.updateRecipientFieldValue(field.name, updateResult);
418
420
  }
419
421
  // If we already have an initials block, apply it
@@ -454,6 +456,8 @@ const VerdocsSign$1 = /*@__PURE__*/ proxyCustomElement(class VerdocsSign extends
454
456
  if (e.detail === null) {
455
457
  console.log('[SIGN] Clearing signature');
456
458
  const updateResult = await updateEnvelopeField(this.endpoint, this.envelopeId, this.roleId, field.name, null, false);
459
+ updateResult.value = null;
460
+ this.signatureId = null;
457
461
  return this.updateRecipientFieldValue(field.name, updateResult);
458
462
  }
459
463
  // If we already have a signature block, apply it
@@ -523,13 +527,13 @@ const VerdocsSign$1 = /*@__PURE__*/ proxyCustomElement(class VerdocsSign extends
523
527
  }
524
528
  return;
525
529
  }
526
- const nextRequiredField = this.getNextRequiredField();
527
- if (nextRequiredField) {
528
- const id = getFieldId(nextRequiredField);
530
+ const nextField = this.getNextFieldInOrder();
531
+ if (nextField) {
532
+ const id = getFieldId(nextField);
529
533
  const el = document.getElementById(id);
530
534
  el === null || el === void 0 ? void 0 : el.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'center' });
531
535
  el === null || el === void 0 ? void 0 : el.focusField();
532
- this.focusedField = nextRequiredField.name;
536
+ this.focusedField = nextField.name;
533
537
  }
534
538
  }
535
539
  getRecipientFields() {
@@ -551,24 +555,36 @@ const VerdocsSign$1 = /*@__PURE__*/ proxyCustomElement(class VerdocsSign extends
551
555
  }
552
556
  this.updateAllFlags();
553
557
  }
554
- getNextRequiredField() {
555
- // Find and focus the next incomplete field (that is fillable)
556
- const emptyFields = this.getSortedFillableFields().filter(field => field.required && !isFieldFilled(field, this.getRecipientFields()));
557
- sortFields(emptyFields);
558
- // console.log(
559
- // '[SIGN] Pending fields',
560
- // emptyFields.map(f => `${f.name} (${f.type}) req=${f.required}`),
561
- // );
562
- if (emptyFields.length === 0) {
563
- const allUnfilled = this.getSortedFillableFields().filter(field => !isFieldFilled(field, this.getRecipientFields()));
564
- sortFields(allUnfilled);
565
- if (allUnfilled.length > 0) {
566
- // If we are here, there are no required fields left, but there are optional ones.
567
- return this.getNextFieldFromList(allUnfilled);
568
- }
558
+ getNextFieldInOrder() {
559
+ // Find the next incomplete field in overall order (required + optional).
560
+ const fields = this.getSortedFillableFields();
561
+ if (fields.length === 0)
569
562
  return null;
563
+ const recipientFields = this.getRecipientFields();
564
+ const focusedIndex = fields.findIndex(field => field.name === this.focusedField);
565
+ const startIndex = focusedIndex >= 0 ? focusedIndex + 1 : 0;
566
+ for (let i = 0; i < fields.length; i++) {
567
+ const idx = (startIndex + i) % fields.length;
568
+ const field = fields[idx];
569
+ if (!this.isFieldFilledForNav(field, recipientFields)) {
570
+ return field;
571
+ }
572
+ }
573
+ return null;
574
+ }
575
+ isFieldFilledForNav(field, recipientFields) {
576
+ if (field.type === 'signature' || field.type === 'initial') {
577
+ const value = typeof field.value === 'string' ? field.value.trim() : field.value;
578
+ if (!value)
579
+ return false;
580
+ if (value === 'signed' || value === 'initialed')
581
+ return false;
582
+ return true;
583
+ }
584
+ if (field.type === 'dropdown') {
585
+ return isFieldFilled(field, recipientFields) && !!field.value;
570
586
  }
571
- return this.getNextFieldFromList(emptyFields);
587
+ return isFieldFilled(field, recipientFields);
572
588
  }
573
589
  getNextFieldFromList(fields) {
574
590
  const focusedIndex = fields.findIndex(field => field.name === this.focusedField);
@@ -606,12 +622,12 @@ const VerdocsSign$1 = /*@__PURE__*/ proxyCustomElement(class VerdocsSign extends
606
622
  // Remove existing flags
607
623
  const existingFlags = controlsDiv.querySelectorAll('.verdocs-flag-instance');
608
624
  existingFlags.forEach(el => el.remove());
609
- let nextField = this.getNextRequiredField();
625
+ let nextField = this.getNextFieldInOrder();
610
626
  const focusedFieldObj = this.getRecipientFields().find(f => f.name === this.focusedField);
611
627
  // If the currently focused field is unfilled, we should point the flag to IT, not the next one.
612
- // getNextRequiredField() is designed for the "Next" button (skipping current), but the visual flag
628
+ // getNextFieldInOrder() is designed for the "Next" button (skipping current), but the visual flag
613
629
  // should guide the user to the current task if it's incomplete.
614
- if (focusedFieldObj && !isFieldFilled(focusedFieldObj, this.getRecipientFields())) {
630
+ if (focusedFieldObj && !this.isFieldFilledForNav(focusedFieldObj, this.getRecipientFields())) {
615
631
  nextField = focusedFieldObj;
616
632
  }
617
633
  if (nextField && nextField.page === pageInfo.pageNumber && nextField.document_id === pageInfo.documentId) {
@@ -629,13 +645,6 @@ const VerdocsSign$1 = /*@__PURE__*/ proxyCustomElement(class VerdocsSign extends
629
645
  onSkip: () => {
630
646
  this.handleNext();
631
647
  },
632
- onClick: () => {
633
- var _a;
634
- const id = getFieldId(nextField);
635
- const el = document.getElementById(id);
636
- el === null || el === void 0 ? void 0 : el.scrollIntoView({ behavior: 'smooth', block: 'center' });
637
- (_a = el === null || el === void 0 ? void 0 : el.focusField) === null || _a === void 0 ? void 0 : _a.call(el);
638
- },
639
648
  });
640
649
  }
641
650
  }
@@ -952,7 +961,7 @@ const VerdocsSign$1 = /*@__PURE__*/ proxyCustomElement(class VerdocsSign extends
952
961
  }
953
962
  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: () => {
954
963
  this.adoptingSignature = true;
955
- // this.handleNext();
964
+ this.handleNext();
956
965
  }, onNext: () => this.handleNext(), onPrevious: () => this.handlePrev(), onExit: () => this.handleNext() }));
957
966
  })(), h("div", { class: `document signed-document-container zoom-${this.zoomLevel}` }, (this.envelope.documents || []).map(envelopeDocument => {
958
967
  const pageNumbers = integerSequence(1, envelopeDocument.pages);