Enhance signature navigation and localization
Added localized strings for navigation and signature-related features in multiple languages. Updated `SenderPdfImageEditor` to support hiding fields, highlighting active fields, and auto-scrolling to active fields. Improved `ReceiverPage` with navigation buttons, signature position display, and better field management. Introduced a new JavaScript function for smooth scrolling to specific fields and added CSS styling for active field highlighting. Refactored code to simplify field handling and navigation logic. These changes improve the user experience for managing and navigating signature fields.
This commit is contained in:
@@ -84,9 +84,9 @@
|
||||
<div class="sender-image-editor__page-placeholder">@L("SenderEditor_PageLabel", "Seite") @pageNumber</div>
|
||||
}
|
||||
|
||||
@foreach (var field in Fields.Where(f => f.Page == pageNumber))
|
||||
@foreach (var field in Fields.Where(f => f.Page == pageNumber && !HiddenFieldIndexes.Contains(f.Index)))
|
||||
{
|
||||
<div class="sender-image-editor__field"
|
||||
<div class="sender-image-editor__field @(ActiveFieldIndex == field.Index ? "sender-image-editor__field--active" : string.Empty)"
|
||||
style="@GetFieldStyle(field, widthPt, heightPt, FieldCursor)"
|
||||
title="@field.ReceiverName"
|
||||
@onmousedown="args => OnFieldMouseDownAsync(args, field)"
|
||||
@@ -163,6 +163,9 @@
|
||||
[Parameter]
|
||||
public bool ShowFieldRemoveButton { get; set; } = true;
|
||||
|
||||
[Parameter]
|
||||
public IReadOnlyCollection<int> HiddenFieldIndexes { get; set; } = Array.Empty<int>();
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<MouseEventArgs> EditorClick { get; set; }
|
||||
|
||||
@@ -178,6 +181,12 @@
|
||||
[Parameter]
|
||||
public string FieldCursor { get; set; } = "move";
|
||||
|
||||
[Parameter]
|
||||
public int? ActiveFieldIndex { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool AutoScrollToActiveField { get; set; }
|
||||
|
||||
private int? _draggedFieldIndex;
|
||||
private bool _isDragging;
|
||||
private double _grabOffsetXPt;
|
||||
@@ -187,6 +196,8 @@
|
||||
private bool _zoomOverrideInitialized;
|
||||
private bool _isDownloading;
|
||||
private bool _isPrinting;
|
||||
private int? _lastActiveFieldIndex;
|
||||
private ActiveFieldScrollTarget? _pendingActiveFieldScrollTarget;
|
||||
|
||||
private const int MinZoomPercent = 50;
|
||||
private const int MaxZoomPercent = 300;
|
||||
@@ -267,18 +278,50 @@
|
||||
}
|
||||
|
||||
_currentPage = Math.Max(1, Math.Min(_currentPage, PageCount));
|
||||
|
||||
if (!AutoScrollToActiveField || ActiveFieldIndex == _lastActiveFieldIndex)
|
||||
return;
|
||||
|
||||
_lastActiveFieldIndex = ActiveFieldIndex;
|
||||
|
||||
if (!ActiveFieldIndex.HasValue)
|
||||
return;
|
||||
|
||||
var activeField = Fields.FirstOrDefault(f => f.Index == ActiveFieldIndex.Value);
|
||||
if (activeField is null)
|
||||
return;
|
||||
|
||||
var (_, pageHeightPt) = GetPageSize(activeField.Page);
|
||||
const double sigHeightPt = 1.96 * 72;
|
||||
var normY = (activeField.YPt + (sigHeightPt / 2.0)) / pageHeightPt;
|
||||
normY = Math.Clamp(normY, 0, 1);
|
||||
_pendingActiveFieldScrollTarget = new ActiveFieldScrollTarget(activeField.Page, normY);
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (_zoomOverrideInitialized)
|
||||
return;
|
||||
if (!_zoomOverrideInitialized)
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync(
|
||||
"envelopeEditor.ensureZoomOverride",
|
||||
"sender-editor-pdf-viewer");
|
||||
|
||||
await JSRuntime.InvokeVoidAsync(
|
||||
"envelopeEditor.ensureZoomOverride",
|
||||
"sender-editor-pdf-viewer");
|
||||
_zoomOverrideInitialized = true;
|
||||
}
|
||||
|
||||
_zoomOverrideInitialized = true;
|
||||
if (_pendingActiveFieldScrollTarget is not null)
|
||||
{
|
||||
var target = _pendingActiveFieldScrollTarget;
|
||||
_pendingActiveFieldScrollTarget = null;
|
||||
|
||||
await JSRuntime.InvokeVoidAsync(
|
||||
"envelopeEditor.scrollToPdfField",
|
||||
"sender-editor-pdf-viewer",
|
||||
target.PageNumber,
|
||||
target.NormY);
|
||||
|
||||
_currentPage = target.PageNumber;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleClickAsync(MouseEventArgs args)
|
||||
@@ -514,6 +557,7 @@
|
||||
}
|
||||
|
||||
private sealed record EditorCoords(double NormX, double NormY, int PageIndex, int PageNumber);
|
||||
private sealed record ActiveFieldScrollTarget(int PageNumber, double NormY);
|
||||
|
||||
private string L(string key, string fallback)
|
||||
{
|
||||
|
||||
@@ -89,16 +89,49 @@
|
||||
}
|
||||
@if (_signatures.Count > 0)
|
||||
{
|
||||
@if (_signatures.Count > 1)
|
||||
{
|
||||
<button class="pdf-toolbar__btn pdf-toolbar__btn--signature-change"
|
||||
@onclick="GoToPreviousSignatureAsync"
|
||||
disabled="@(!CanNavigateToAnotherSignature)"
|
||||
title='@L("Receiver_SignNav_Previous", "Vorheriges Feld")'
|
||||
style="padding: 0.2rem 0.55rem; min-width: 2.1rem; min-height: 1.75rem;">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="currentColor" viewBox="0 0 16 16" aria-hidden="true">
|
||||
<path fill-rule="evenodd" d="M11.354 1.646a.5.5 0 0 1 0 .708L5.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0z" />
|
||||
</svg>
|
||||
</button>
|
||||
}
|
||||
|
||||
<span style="display: inline-flex; align-items: center; padding: 0.125rem 0.4rem; background: @(_capturedSignature is not null ? "#d1fae5" : "#ede9fe"); border-radius: 0.25rem; color: @(_capturedSignature is not null ? "#065f46" : "#6d28d9"); font-weight: 500; white-space: nowrap;">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="9" height="9" fill="currentColor" class="me-1" viewBox="0 0 16 16">
|
||||
<path d="M12.146.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1 0 .708l-10 10a.5.5 0 0 1-.168.11l-5 2a.5.5 0 0 1-.65-.65l2-5a.5.5 0 0 1 .11-.168l10-10zM11.207 2.5 13.5 4.793 14.793 3.5 12.5 1.207 11.207 2.5zm1.586 3L10.5 3.207 4 9.707V10h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.293l6.5-6.5zm-9.761 5.175-.106.106-1.528 3.821 3.821-1.528.106-.106A.5.5 0 0 1 5 12.5V12h-.5a.5.5 0 0 1-.5-.5V11h-.5a.5.5 0 0 1-.468-.325z" />
|
||||
</svg>
|
||||
@_signatures.Count Unterschrift@(_signatures.Count != 1 ? "en" : "")
|
||||
@if (_signatures.Count > 1)
|
||||
{
|
||||
@string.Format(L("Receiver_SignNav_PositionWithLabel", "{0} / {1} Signaturen"), CurrentSignatureDisplayIndex, _signatures.Count)
|
||||
}
|
||||
else
|
||||
{
|
||||
@($"{_signatures.Count} {L("Receiver_Signature_Singular", "Unterschrift")}")
|
||||
}
|
||||
@if (_capturedSignature is not null)
|
||||
{
|
||||
<span class="ms-1">✓</span>
|
||||
}
|
||||
</span>
|
||||
|
||||
@if (_signatures.Count > 1)
|
||||
{
|
||||
<button class="pdf-toolbar__btn pdf-toolbar__btn--signature-change"
|
||||
@onclick="GoToNextSignatureAsync"
|
||||
disabled="@(!CanNavigateToAnotherSignature)"
|
||||
title='@L("Receiver_SignNav_Next", "Nächstes Feld")'
|
||||
style="padding: 0.2rem 0.55rem; min-width: 2.1rem; min-height: 1.75rem;">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="currentColor" viewBox="0 0 16 16" aria-hidden="true">
|
||||
<path fill-rule="evenodd" d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z" />
|
||||
</svg>
|
||||
</button>
|
||||
}
|
||||
}
|
||||
@if (_envelopeReceiver.Envelope?.UseAccessCode ?? false)
|
||||
{
|
||||
@@ -218,9 +251,12 @@
|
||||
Pages="@_pagePreviews"
|
||||
PdfDataUrl="@PdfDataUrl"
|
||||
PdfFileName="@PdfFileName"
|
||||
Fields="@VisibleFieldOverlays"
|
||||
Fields="@FieldOverlays"
|
||||
HiddenFieldIndexes="@_appliedSignatureFieldIndexes"
|
||||
SignatureOverlays="@SignedOverlays"
|
||||
FieldCursor="pointer"
|
||||
ActiveFieldIndex="@ActiveSignatureFieldIndex"
|
||||
AutoScrollToActiveField="true"
|
||||
FieldClick="OnSignatureFieldClickAsync"
|
||||
ShowFieldRemoveButton="false" />
|
||||
}
|
||||
@@ -475,10 +511,6 @@
|
||||
.Select((s, i) => new SenderPdfFieldOverlay(i, s.Page, s.X, s.Y, L("Receiver_SignField_ClickToSign", "Sign here"), "#4F46E5"))
|
||||
.ToList();
|
||||
|
||||
IReadOnlyList<SenderPdfFieldOverlay> VisibleFieldOverlays => FieldOverlays
|
||||
.Where(field => !_appliedSignatureFieldIndexes.Contains(field.Index))
|
||||
.ToList();
|
||||
|
||||
IReadOnlyList<SenderPdfSignatureOverlay> SignedOverlays => _capturedSignature is null
|
||||
? Array.Empty<SenderPdfSignatureOverlay>()
|
||||
: _signatures
|
||||
@@ -496,6 +528,12 @@
|
||||
.ToList();
|
||||
|
||||
bool AllSignatureFieldsApplied => _signatures.Count > 0 && _appliedSignatureFieldIndexes.Count == _signatures.Count;
|
||||
List<int> NavigableSignatureIndexes => Enumerable.Range(0, _signatures.Count).ToList();
|
||||
bool CanNavigateToAnotherSignature => _signatures.Count > 1;
|
||||
int? ActiveSignatureFieldIndex => _currentSignatureNavFieldIndex;
|
||||
int CurrentSignatureDisplayIndex => _currentSignatureNavFieldIndex.HasValue
|
||||
? (_currentSignatureNavFieldIndex.Value + 1)
|
||||
: (_signatures.Count > 0 ? 1 : 0);
|
||||
|
||||
string? PdfDataUrl => _displayPdfBytes is { Length: > 0 }
|
||||
? $"data:application/pdf;base64,{Convert.ToBase64String(_displayPdfBytes)}"
|
||||
@@ -522,6 +560,7 @@
|
||||
string? _submitErrorMessage;
|
||||
string? _capturedSignatureDateText;
|
||||
readonly HashSet<int> _appliedSignatureFieldIndexes = [];
|
||||
int? _currentSignatureNavFieldIndex;
|
||||
|
||||
// ----- Share popup state -----
|
||||
bool _sharePopupVisible = false;
|
||||
@@ -689,6 +728,7 @@
|
||||
_activeSignatureTab = SignatureTabDraw;
|
||||
_signaturePopupVisible = false;
|
||||
_popupValidationMessage = null;
|
||||
EnsureActiveNavigableField();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -744,6 +784,7 @@
|
||||
|
||||
if (_capturedSignature is null)
|
||||
{
|
||||
_currentSignatureNavFieldIndex = fieldIndex;
|
||||
_pendingSignatureFieldIndex = fieldIndex;
|
||||
OpenSignaturePopup(keepPendingField: true);
|
||||
return;
|
||||
@@ -756,6 +797,40 @@
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
Task GoToNextSignatureAsync()
|
||||
{
|
||||
var indexes = NavigableSignatureIndexes;
|
||||
if (indexes.Count == 0)
|
||||
return Task.CompletedTask;
|
||||
|
||||
if (!_currentSignatureNavFieldIndex.HasValue || !indexes.Contains(_currentSignatureNavFieldIndex.Value))
|
||||
{
|
||||
_currentSignatureNavFieldIndex = indexes[0];
|
||||
return InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
var currentIndex = indexes.IndexOf(_currentSignatureNavFieldIndex.Value);
|
||||
_currentSignatureNavFieldIndex = indexes[(currentIndex + 1) % indexes.Count];
|
||||
return InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
Task GoToPreviousSignatureAsync()
|
||||
{
|
||||
var indexes = NavigableSignatureIndexes;
|
||||
if (indexes.Count == 0)
|
||||
return Task.CompletedTask;
|
||||
|
||||
if (!_currentSignatureNavFieldIndex.HasValue || !indexes.Contains(_currentSignatureNavFieldIndex.Value))
|
||||
{
|
||||
_currentSignatureNavFieldIndex = indexes[0];
|
||||
return InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
var currentIndex = indexes.IndexOf(_currentSignatureNavFieldIndex.Value);
|
||||
_currentSignatureNavFieldIndex = indexes[(currentIndex - 1 + indexes.Count) % indexes.Count];
|
||||
return InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
async Task OnPopupShownAsync()
|
||||
{
|
||||
await InitializeActiveSignatureTabAsync();
|
||||
@@ -915,8 +990,11 @@
|
||||
pendingFieldIndex < _signatures.Count)
|
||||
{
|
||||
_appliedSignatureFieldIndexes.Add(pendingFieldIndex);
|
||||
_currentSignatureNavFieldIndex = pendingFieldIndex;
|
||||
}
|
||||
}
|
||||
else
|
||||
EnsureActiveNavigableField();
|
||||
|
||||
_pendingSignatureFieldIndex = null;
|
||||
_submitErrorMessage = null;
|
||||
@@ -1046,4 +1124,19 @@
|
||||
return value.ResourceNotFound ? fallback : value.Value;
|
||||
}
|
||||
|
||||
void EnsureActiveNavigableField()
|
||||
{
|
||||
var indexes = NavigableSignatureIndexes;
|
||||
if (indexes.Count == 0)
|
||||
{
|
||||
_currentSignatureNavFieldIndex = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_currentSignatureNavFieldIndex.HasValue && indexes.Contains(_currentSignatureNavFieldIndex.Value))
|
||||
return;
|
||||
|
||||
_currentSignatureNavFieldIndex = indexes[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -392,6 +392,11 @@
|
||||
filter: brightness(0.96);
|
||||
}
|
||||
|
||||
.sender-image-editor__field--active {
|
||||
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.28);
|
||||
filter: brightness(0.93);
|
||||
}
|
||||
|
||||
.sender-image-editor__signature {
|
||||
position: absolute;
|
||||
border: 1px solid rgba(100, 116, 139, 0.5);
|
||||
|
||||
@@ -151,6 +151,35 @@ window.envelopeEditor = {
|
||||
});
|
||||
},
|
||||
|
||||
scrollToPdfField: function (viewerCssClass, pageNumber, normY) {
|
||||
const viewer = document.querySelector('.' + viewerCssClass);
|
||||
if (!viewer) {
|
||||
return;
|
||||
}
|
||||
|
||||
const targetPageNumber = Math.max(1, Number(pageNumber) || 1);
|
||||
const page = viewer.querySelector('[data-editor-page="' + targetPageNumber + '"]');
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
|
||||
const viewerRect = viewer.getBoundingClientRect();
|
||||
const pageRect = page.getBoundingClientRect();
|
||||
const normalizedY = Math.max(0, Math.min(1, Number(normY) || 0));
|
||||
|
||||
const pageTopInViewer = viewer.scrollTop + (pageRect.top - viewerRect.top);
|
||||
const targetYInPage = normalizedY * pageRect.height;
|
||||
const desiredTop = pageTopInViewer + targetYInPage - (viewer.clientHeight * 0.35);
|
||||
|
||||
const maxScrollTop = Math.max(0, viewer.scrollHeight - viewer.clientHeight);
|
||||
const targetScrollTop = Math.max(0, Math.min(desiredTop, maxScrollTop));
|
||||
|
||||
viewer.scrollTo({
|
||||
top: targetScrollTop,
|
||||
behavior: 'smooth'
|
||||
});
|
||||
},
|
||||
|
||||
getVisiblePdfPageNumber: function (viewerCssClass) {
|
||||
const viewer = document.querySelector('.' + viewerCssClass);
|
||||
if (!viewer) {
|
||||
|
||||
Reference in New Issue
Block a user