Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinKlein1508 committed Jul 2, 2024
2 parents 1d3b570 + 3add03e commit 8fa761f
Show file tree
Hide file tree
Showing 20 changed files with 108 additions and 24 deletions.
6 changes: 6 additions & 0 deletions BlazorSRRDemo/BlazorSRRDemo/BlazorSRRDemo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.6" />
</ItemGroup>

<ItemGroup>
<Content Update="Components\Pages\ExistingSignature.razor">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion BlazorSRRDemo/BlazorSRRDemo/Components/Pages/BGImage.razor
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@page "/BGImageDemo"

<Demos.Core.SignaturePadDemos.BackgroundImageDemo @rendermode="InteractiveServer" />
<BackgroundImageDemo @rendermode="InteractiveServer" />
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@page "/Disabled"

<Demos.Core.SignaturePadDemos.DisabledDemo @rendermode="InteractiveServer" />
<DisabledDemo @rendermode="InteractiveServer" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@page "/ExistingSignature"

<ExistingSignatureDemo @rendermode="InteractiveServer" />

2 changes: 1 addition & 1 deletion BlazorSRRDemo/BlazorSRRDemo/Components/Pages/Home.razor
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@page "/"

<Demos.Core.SignaturePadDemos.HomeDemo @rendermode="InteractiveServer" />
<HomeDemo @rendermode="InteractiveServer" />
2 changes: 1 addition & 1 deletion BlazorSRRDemo/BlazorSRRDemo/Components/Pages/Options.razor
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@page "/OptionsDemo"

<Demos.Core.SignaturePadDemos.OptionsDemo @rendermode="InteractiveServer" />
<OptionsDemo @rendermode="InteractiveServer" />
1 change: 1 addition & 0 deletions BlazorSRRDemo/BlazorSRRDemo/Components/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
@using BlazorSRRDemo
@using BlazorSRRDemo.Components
@using Demos.Core
@using Demos.Core.SignaturePadDemos
6 changes: 6 additions & 0 deletions BlazorServerDemo/BlazorServerDemo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@
<ProjectReference Include="..\SignaturePad\SignaturePad.csproj" />
</ItemGroup>

<ItemGroup>
<Content Update="Pages\ExistingSignature.razor">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions BlazorServerDemo/Pages/ExistingSignature.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@page "/ExistingSignature"

<ExistingSignatureDemo />

6 changes: 6 additions & 0 deletions BlazorWebAssemblyDemo/BlazorWebAssemblyDemo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@
<ProjectReference Include="..\Demos.Core\Demos.Core.csproj" />
</ItemGroup>

<ItemGroup>
<Content Update="Pages\ExistingSignature.razor">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion BlazorWebAssemblyDemo/Pages/BGImage.razor
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@page "/BGImageDemo"

<Demos.Core.SignaturePadDemos.BackgroundImageDemo />
<BackgroundImageDemo />
2 changes: 1 addition & 1 deletion BlazorWebAssemblyDemo/Pages/Disabled.razor
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@page "/Disabled"

<Demos.Core.SignaturePadDemos.DisabledDemo />
<DisabledDemo />
5 changes: 5 additions & 0 deletions BlazorWebAssemblyDemo/Pages/ExistingSignature.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@page "/ExistingSignature"


<ExistingSignatureDemo />

2 changes: 1 addition & 1 deletion BlazorWebAssemblyDemo/Pages/Home.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

Welcome to your new app.

<Demos.Core.SignaturePadDemos.HomeDemo />
<HomeDemo />
2 changes: 1 addition & 1 deletion BlazorWebAssemblyDemo/Pages/Options.razor
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@page "/OptionsDemo"

<Demos.Core.SignaturePadDemos.OptionsDemo />
<OptionsDemo />
1 change: 1 addition & 0 deletions BlazorWebAssemblyDemo/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
@using BlazorWebAssemblyDemo
@using BlazorWebAssemblyDemo.Layout
@using Demos.Core
@using Demos.Core.SignaturePadDemos
6 changes: 6 additions & 0 deletions Demos.Core/Demos.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@
<ProjectReference Include="..\SignaturePad\SignaturePad.csproj" />
</ItemGroup>

<ItemGroup>
<Content Update="SignaturePadDemos\ExistingSignatureDemo.razor">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions Demos.Core/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
</NavLink>
</div>

<div class="nav-item px-3">
<NavLink class="nav-link" href="ExistingSignature" Match="NavLinkMatch.All">
<span class="oi oi-home" aria-hidden="true"></span> Existing signature
</NavLink>
</div>

<div class="nav-item px-3">
<NavLink class="nav-link" href="BGImageDemo" Match="NavLinkMatch.All">
<span class="oi oi-home" aria-hidden="true"></span> BG Image
Expand Down
45 changes: 45 additions & 0 deletions Demos.Core/SignaturePadDemos/ExistingSignatureDemo.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@using System.Text
@inject NavigationManager navigationManager
@inject SignatureInMemoryService memoryService

<h1>SignaturePad Default Demo</h1>
<SignaturePad @bind-Value="Input.Signature" style="width: 100%;" />


@if (Input.Signature.Any())
{
<h2>Signature</h2>
<img src="@Input.SignatureAsBase64" />
<button type="button" class="btn btn-primary" @onclick="SaveSignature">Save signature</button>
<button type="button" class="btn btn-primary" @onclick="OpenSignature">Open signature</button>
}

@if(memoryService.Signature.Any())
{
<button type="button" class="btn btn-primary ms-1" @onclick="ReadSignature">Read signature</button>
}

@code {
public MyInput Input { get; set; } = new();

public ExistingSignatureDemo()
{
Input.Signature = Encoding.UTF8.GetBytes("data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAALgAAAA5CAYAAACF3+G6AAAAAXNSR0IArs4c6QAADlZJREFUeF7t3QOULFkSBuB/1rZt27Zt88zatm3be9actW3bmLVtz25+b+7dyZed1ZXVXV1d3ZVxTp3u1y95b9y4EX/8EbVPRpnHCBwuyY2T+Pm3JP8sn88m+eqEG5wiyVmSnC7JX5NcJslxkhwqyeGTHKVc7x9J9kvyqSRfT/KOeTzwqlxjn1V50Rnf8xBJLlAU7YxJTp3k4ElOleT0SQ5b/j3jZfccXpX/CBs5uZzzsyTvTPKlJN9sFscnkvx2E9fbtaeuqoKfO8kxk5w1yX+SXDDJ2ZIcq8w0q3noGWb9L0k+k+S/nXMsjON2/kbBWekvJvllscz/Luf/uaXAf2wtrPOXBed5j9HzXH8vC47Cn2OG5971h+5WBadA10py1OIGnKYoM8s7RCjqp4vr8MPG/fheOekH5XeL4pPFGg+53jyPsaNcOMlJyqI8UZKTl4Vql7lEs2DfO88b7uRr7SYFv3qzZV8tyfnK5E+bl/2TfCPJ54oy2+p9dqrcorHuT0tiEZ6pxAI79V3m9tw7VcE998WSXKgJ4q6Z5LTrjIgAToDGhfh4kh8VhZ7bIC7JhcQNFixr/ook11uS59rWx9hpCn6TJJdqLO111xk1fihFptTcjC9v6wgv9uaXTPL24o8fLcnvFnv75bvbsis4H/oGJdjifnQDNiMqUHtr44++Kcm7kwj4VlU+WHY1wapgVLC80rJsCn70EhyetKAG5+2ZHSgELPg9ST6wYhZ6PWW1u72wBJvXTvK6ldbs8vLLoOCUmttx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HwkExFQxsRKTM9TmU8V0E4W0jz7jhc5ZdwXEWwHztZp71ZU2MLVRipoupb3hAduCJxqHbonroa/CndazdtUZhGRWcG4ItpvNTl5Ira6mjFvbfoJq8oTO9g4+DCE1CjbxWpaH6KdsMzkP5pdxyHLtalkHBKbSUr0QCS9RVapkxkwGSGtPna9Xx8o178pJSEADxQl+gxJWGUSuo0C2UeXHj2iVgo4JvwQiwzgIiHN5upQbyOguD0LXfbt4+5ziuLDPCE0wbUtJGlXCGjKUax5Wj+y7KgiNhoZ0KFLuMQBZHZYeqHtE73slSZsXmqJDzuBT4j6FAR0BVbQsECdFJgfgqxyeDIaSNTojI3tdK8KlrJQ2+Cg65Dk+CxNpzZKP3WJXz1ItCkbhyfWiSQnFjygXBuhxlBox01sGSLVO3WPvywVNZZ99UzP2AV4+y/ghURZbQEptwQ9rClaPQAm/YP9x6lM4IzNNFUVkD1kPUqt8nQ7ElDpSBjfyPyeoHBtWJi/vGlTMv3eoiCoypx4Xz2UzJ18oshHkouIIHVNo2lRIkpU8Ftt5mudy7aTIgGgyAdDmrrCiaG9el8qInMwjqR7V/gyTtyFT5dk/ePBRcSZlApgaPkgYmBuPMNsrnxjNHihJsWhA+6vZqIyDkHRCXifVMrgGj3UnlYpQWr75WN1WLDPZUDd79huf23Au0KTQLzZVTHK3CaZRNjsA8FNwjYPE9sHCJ53XNIa/GBerezxfMon1aLFXZplFA2/cCpakiomBS15XzIjC2M6GLYlyyvu3i2r5n6b6DMj4cauV2dj3Y/ui6DZnpDR4zb2V8UCk0wM3ezULxawKllmlVi2sB2MHsXPV3C0ajoJVJsCzL5P8Pkg7Vm1kdRBkAAAAASUVORK5CYII=");
}

private void SaveSignature()
{
memoryService.Signature = Input.Signature;
}

private void OpenSignature()
{
navigationManager.NavigateTo(Input.SignatureAsBase64);
}

private void ReadSignature()
{
Input.Signature = memoryService.Signature;
StateHasChanged();
}
}
26 changes: 10 additions & 16 deletions SignaturePad/SignaturePad.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,8 @@ namespace SignaturePad
public partial class SignaturePad
{
[Parameter]
public byte[] Value
{
get => _value;
set
{
if (value == _value) return;

_value = value;
UpdateImage();
}
}
public byte[] Value { get; set; } = [];

[Parameter]
public EventCallback<byte[]> ValueChanged { get; set; }
[Parameter]
Expand All @@ -36,6 +27,7 @@ public byte[] Value
public bool Disabled { get; set; }



/// <summary>
/// Captures all the custom attributes that are not part of BlazorBootstrap component.
/// </summary>
Expand All @@ -45,8 +37,8 @@ public byte[] Value
private readonly string _id = Guid.NewGuid().ToString();
private readonly DotNetObjectReference<SignaturePad> _reference;
private IJSObjectReference? _jsModule;
private byte[] _value = [];


public SignaturePad()
{
_reference = DotNetObjectReference.Create(this);
Expand All @@ -56,19 +48,19 @@ public SignaturePad()
public async Task SignatureDataChangedAsync()
{
using MemoryStream memoryStream = new();
var dataReference = await _jsModule.InvokeAsync<IJSStreamReference>("getBase64", _id);
var dataReference = await _jsModule!.InvokeAsync<IJSStreamReference>("getBase64", _id);
using var dataReferenceStream = await dataReference.OpenReadStreamAsync(maxAllowedSize: 10_000_000);
await dataReferenceStream.CopyToAsync(memoryStream);

string base64 = Encoding.UTF8.GetString(memoryStream.ToArray());

try
{
_value = Convert.FromBase64String(base64);
Value = Convert.FromBase64String(base64);
}
catch (Exception)
{
_value = [];
Value = [];
}


Expand All @@ -82,6 +74,8 @@ protected async override Task OnAfterRenderAsync(bool firstRender)
{
_jsModule = await jsRuntime.InvokeAsync<IJSObjectReference>("import", "./_content/Blazor.SignaturePad/sigpad.interop.js?ver=8.1.2");
await Setup();
await Update();
await UpdateImage();
}

await base.OnAfterRenderAsync(firstRender);
Expand Down

0 comments on commit 8fa761f

Please sign in to comment.