Enhance upload panel resizing with JS interop

Introduced JavaScript interop for dynamic resizing of the upload
panel in `CreateEnvelopeWizardPopup`. Added `DotNetObjectReference`
to enable communication between Blazor and JavaScript, replacing
synchronous resizing logic with asynchronous calls for improved
performance.

Refactored event handlers and updated state management to ensure
proper handling of resizing operations. Enhanced `envelope-editor.js`
with a dedicated `_wizardResize` object to manage resizing state
and optimize performance using `requestAnimationFrame`.

Added cleanup logic with `DisposeAsync` to release resources and
prevent memory leaks. Removed redundant event handlers from the
Razor file, delegating resizing logic to JavaScript. Improved
error handling for JavaScript calls to ensure robustness.
This commit is contained in:
2026-11-30 13:35:46 +01:00
parent 3eb74e8054
commit 4653670b2c
2 changed files with 138 additions and 13 deletions

View File

@@ -8,10 +8,13 @@
@using MudBlazor
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.Extensions.Localization
@using Microsoft.JSInterop
@implements IAsyncDisposable
@inject IStringLocalizer<Model> ModelLocalizer
@inject IStringLocalizer<Resource> UiLocalizer
@inject ReceiverService ReceiverService
@inject PdfRenderService PdfRenderService
@inject IJSRuntime JSRuntime
<DxPopup Visible="@_isVisible"
VisibleChanged="OnPopupVisibleChangedAsync"
@@ -33,10 +36,7 @@
tabindex="0"
@onkeydown="OnWizardKeyDownAsync">
<div class="sender-create-wizard__body-layout @(_isUploadPanelResizing ? "sender-create-wizard__body-layout--resizing" : string.Empty)"
style="@($"--sender-upload-panel-width: {_uploadPanelWidthPx}px;")"
@onmousemove="OnBodyLayoutMouseMove"
@onmouseup="StopUploadPanelResize"
@onmouseleave="StopUploadPanelResize">
style="@($"--sender-upload-panel-width: {_uploadPanelWidthPx}px;")">
<MudPaper Class="sender-create-wizard__stepper-shell" Elevation="0">
<MudStepper Vertical="true"
NonLinear="false"
@@ -538,6 +538,7 @@
private bool _isUploadPanelResizing;
private double _uploadPanelResizeStartX;
private double _uploadPanelResizeStartWidthPx;
private DotNetObjectReference<CreateEnvelopeWizardPopup>? _resizeDotNetRef;
private string? _validationMessage;
@@ -782,29 +783,39 @@
}
}
private Task StartUploadPanelResize(MouseEventArgs args)
private async Task StartUploadPanelResize(MouseEventArgs args)
{
_isUploadPanelResizing = true;
_uploadPanelResizeStartX = args.ClientX;
_uploadPanelResizeStartWidthPx = _uploadPanelWidthPx;
return Task.CompletedTask;
_resizeDotNetRef ??= DotNetObjectReference.Create(this);
await JSRuntime.InvokeVoidAsync(
"envelopeEditor.startWizardUploadPanelResize",
_uploadPanelResizeStartX,
_uploadPanelResizeStartWidthPx,
UploadPanelMinWidthPx,
UploadPanelMaxWidthPx,
_resizeDotNetRef);
await InvokeAsync(StateHasChanged);
}
private Task OnBodyLayoutMouseMove(MouseEventArgs args)
[JSInvokable]
public Task OnUploadPanelResizeMove(double widthPx)
{
if (!_isUploadPanelResizing)
return Task.CompletedTask;
var delta = _uploadPanelResizeStartX - args.ClientX;
var nextWidth = _uploadPanelResizeStartWidthPx + delta;
_uploadPanelWidthPx = Math.Clamp(nextWidth, UploadPanelMinWidthPx, UploadPanelMaxWidthPx);
return Task.CompletedTask;
_uploadPanelWidthPx = Math.Clamp(widthPx, UploadPanelMinWidthPx, UploadPanelMaxWidthPx);
return InvokeAsync(StateHasChanged);
}
private Task StopUploadPanelResize()
[JSInvokable]
public Task OnUploadPanelResizeEnd()
{
_isUploadPanelResizing = false;
return Task.CompletedTask;
return InvokeAsync(StateHasChanged);
}
private Task MoveBack()
@@ -961,6 +972,7 @@
if (!value)
{
await StopUploadPanelResizeAsync();
_cancelConfirmVisible = false;
ResetWizardState();
}
@@ -1258,6 +1270,8 @@
private void ResetWizardState()
{
_isUploadPanelResizing = false;
_cancelConfirmVisible = false;
_currentStep = 0;
_completedSteps.Clear();
@@ -1306,4 +1320,23 @@
return uiValue.ResourceNotFound ? fallback : uiValue.Value;
}
private async Task StopUploadPanelResizeAsync()
{
try
{
await JSRuntime.InvokeVoidAsync("envelopeEditor.stopWizardUploadPanelResize");
}
catch
{
// no-op
}
}
public async ValueTask DisposeAsync()
{
await StopUploadPanelResizeAsync();
_resizeDotNetRef?.Dispose();
_resizeDotNetRef = null;
}
}