Skip to content

Commit

Permalink
Feature/fix triggers on load event when replace image (#317)
Browse files Browse the repository at this point in the history
## Target
<!--
  Why are you making this change?
 -->
Fix triggers on load event when replace image
#### Open Questions
<!-- OPTIONAL
- [ ] Use the GitHub checklists to spark discussion on issues that may
arise from your approach. Please tick the box and explain your answer.
-->

## Checklist
<!--
It serves as a gentle reminder for common tasks. Confirm it's done and
check everything that applies.
-->
- [x] Documentation updated
- [x] Tests cover new or modified code
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] New dependencies added
- [ ] Includes breaking changes
- [ ] Version bumped

## Visuals
<!-- OPTIONAL
Show results both before and after this change. When the output changes,
it can be a screenshot of a trace, metric, or log illustrating the
change.
-->

---------

Co-authored-by: ColdForeign <[email protected]>
  • Loading branch information
MaxymGorn and ColdForeign authored Mar 30, 2024
1 parent b3bf289 commit faea1ec
Show file tree
Hide file tree
Showing 34 changed files with 639 additions and 74 deletions.
38 changes: 32 additions & 6 deletions examples/Cropper.Blazor.Demo.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cropper.Blazor.MAUI.Net8",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cropper.Blazor.Server.Net8", "Cropper.Blazor.Server.Net8\Cropper.Blazor.Server.Net8.csproj", "{9A16F9F9-231A-42C8-A2E9-AE687141BC3B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cropper.Blazor.WPF.Net6", "Cropper.Blazor.WPF.Net6\Cropper.Blazor.WPF.Net6.csproj", "{4E800E87-808D-4583-90E2-C3A13C25F38C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WPF", "WPF", "{516A76C9-8502-4FC4-A614-9989C7C48E21}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cropper.Blazor.WebView.Net6", "Cropper.Blazor.WebView.Net6\Cropper.Blazor.WebView.Net6.csproj", "{BDE3364F-64EA-4906-A889-63CC4BD6EF25}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MAUI", "MAUI", "{4DED931E-A01B-4B5F-AA64-A003FC0F8DC1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MVC", "MVC", "{C1872578-F52C-42A9-98E1-7057E54705E6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Server", "Server", "{FE00A07D-B8ED-4AC5-81A7-9F0AF7AE949B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -59,18 +71,32 @@ Global
{9A16F9F9-231A-42C8-A2E9-AE687141BC3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A16F9F9-231A-42C8-A2E9-AE687141BC3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A16F9F9-231A-42C8-A2E9-AE687141BC3B}.Release|Any CPU.Build.0 = Release|Any CPU
{4E800E87-808D-4583-90E2-C3A13C25F38C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4E800E87-808D-4583-90E2-C3A13C25F38C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E800E87-808D-4583-90E2-C3A13C25F38C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E800E87-808D-4583-90E2-C3A13C25F38C}.Release|Any CPU.Build.0 = Release|Any CPU
{BDE3364F-64EA-4906-A889-63CC4BD6EF25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BDE3364F-64EA-4906-A889-63CC4BD6EF25}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BDE3364F-64EA-4906-A889-63CC4BD6EF25}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BDE3364F-64EA-4906-A889-63CC4BD6EF25}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{7D576440-AFE9-4544-8473-0A557A545728} = {49B4C364-A66D-44E3-8094-35C8CEC06100}
{DCB512C2-9EF1-4777-82B8-D9E8FAFD3883} = {49B4C364-A66D-44E3-8094-35C8CEC06100}
{A607E161-5266-4B13-AB68-6DEBB8768F54} = {49B4C364-A66D-44E3-8094-35C8CEC06100}
{7D576440-AFE9-4544-8473-0A557A545728} = {4DED931E-A01B-4B5F-AA64-A003FC0F8DC1}
{DCB512C2-9EF1-4777-82B8-D9E8FAFD3883} = {FE00A07D-B8ED-4AC5-81A7-9F0AF7AE949B}
{A607E161-5266-4B13-AB68-6DEBB8768F54} = {FE00A07D-B8ED-4AC5-81A7-9F0AF7AE949B}
{84AC7F07-3FB9-4147-AB61-733243686D9A} = {4F93F51C-1D65-4E5D-86F7-7BC5B8899180}
{B6352D48-8912-40CA-B099-E337F1B3CD4B} = {49B4C364-A66D-44E3-8094-35C8CEC06100}
{0C1676CF-1503-4ECC-AD16-4FD844C0FCC0} = {49B4C364-A66D-44E3-8094-35C8CEC06100}
{9A16F9F9-231A-42C8-A2E9-AE687141BC3B} = {49B4C364-A66D-44E3-8094-35C8CEC06100}
{B6352D48-8912-40CA-B099-E337F1B3CD4B} = {C1872578-F52C-42A9-98E1-7057E54705E6}
{0C1676CF-1503-4ECC-AD16-4FD844C0FCC0} = {4DED931E-A01B-4B5F-AA64-A003FC0F8DC1}
{9A16F9F9-231A-42C8-A2E9-AE687141BC3B} = {FE00A07D-B8ED-4AC5-81A7-9F0AF7AE949B}
{4E800E87-808D-4583-90E2-C3A13C25F38C} = {516A76C9-8502-4FC4-A614-9989C7C48E21}
{516A76C9-8502-4FC4-A614-9989C7C48E21} = {49B4C364-A66D-44E3-8094-35C8CEC06100}
{BDE3364F-64EA-4906-A889-63CC4BD6EF25} = {516A76C9-8502-4FC4-A614-9989C7C48E21}
{4DED931E-A01B-4B5F-AA64-A003FC0F8DC1} = {49B4C364-A66D-44E3-8094-35C8CEC06100}
{C1872578-F52C-42A9-98E1-7057E54705E6} = {49B4C364-A66D-44E3-8094-35C8CEC06100}
{FE00A07D-B8ED-4AC5-81A7-9F0AF7AE949B} = {49B4C364-A66D-44E3-8094-35C8CEC06100}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5FA0980D-10C3-4751-9432-DE20984B0A69}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" VersionOverride="7.0.1" Version="7.0.1" />
<PackageReference Include="MudBlazor" Version="6.11.1" />
<PackageReference Include="MudBlazor" Version="6.19.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.14" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.14" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="8.0.14" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="MudBlazor" Version="6.11.1" />
<PackageReference Include="MudBlazor" Version="6.19.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ public App()

protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
Expand All @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MudBlazor" Version="6.11.1" />
<PackageReference Include="MudBlazor" Version="6.19.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MudBlazor" Version="6.11.1" />
<PackageReference Include="MudBlazor" Version="6.19.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MudBlazor" Version="6.11.1" />
<PackageReference Include="MudBlazor" Version="6.19.1" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 9 additions & 0 deletions examples/Cropper.Blazor.WPF.Net6/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Application x:Class="Cropper.Blazor.WPF.Net6.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Cropper.Blazor.WPF.Net6"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
12 changes: 12 additions & 0 deletions examples/Cropper.Blazor.WPF.Net6/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Windows;

namespace Cropper.Blazor.WPF.Net6
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}

}
10 changes: 10 additions & 0 deletions examples/Cropper.Blazor.WPF.Net6/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
20 changes: 20 additions & 0 deletions examples/Cropper.Blazor.WPF.Net6/Cropper.Blazor.WPF.Net6.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Wpf" Version="6.0.553" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Cropper.Blazor.WebView.Net6\Cropper.Blazor.WebView.Net6.csproj" />
</ItemGroup>

</Project>
20 changes: 20 additions & 0 deletions examples/Cropper.Blazor.WPF.Net6/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Window x:Class="Cropper.Blazor.WPF.Net6.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Cropper.Blazor.WPF.Net6"
xmlns:imgrazor="clr-namespace:Cropper.Blazor.WebView.Net6;assembly=Cropper.Blazor.WebView.Net6"
xmlns:blazor="http://schemas.microsoft.com/winfx/2006/xaml/presentation/blazor"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<blazor:BlazorWebView HostPage="wwwroot\index.html" Services="{DynamicResource services}">
<blazor:BlazorWebView.RootComponents>
<blazor:RootComponent
Selector="#app"
ComponentType="{x:Type imgrazor:Component}" />
</blazor:BlazorWebView.RootComponents>
</blazor:BlazorWebView>
</Grid>
</Window>
29 changes: 29 additions & 0 deletions examples/Cropper.Blazor.WPF.Net6/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Windows;
using Cropper.Blazor.Extensions;
using Microsoft.Extensions.DependencyInjection;
using MudBlazor.Services;

namespace Cropper.Blazor.WPF.Net6
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
// https://www.infoq.com/news/2021/04/dotnet-6-webview-winforms-wpf/
public MainWindow()
{
InitializeComponent();

var serviceCollection = new ServiceCollection();
serviceCollection.AddWpfBlazorWebView();
serviceCollection.AddCropper();
serviceCollection.AddMudServices();

#if DEBUG
serviceCollection.AddBlazorWebViewDeveloperTools();
#endif
Resources.Add("services", serviceCollection.BuildServiceProvider());
}
}
}
56 changes: 56 additions & 0 deletions examples/Cropper.Blazor.WebView.Net6/Component.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
@using Cropper.Blazor.Components
@using Cropper.Blazor.Models
@using Microsoft.AspNetCore.Components.Forms
@using MudBlazor

<MudThemeProvider />
<MudDialogProvider />
<MudSnackbarProvider />

<PageTitle>Cropper Blazor Server Demo</PageTitle>

<MudButtonGroup Color="Color.Primary" Variant="Variant.Filled">
<MudTooltip Text="Import image with Blob URLs">
<InputFile id="imageInput" OnChange="InputFileChange" accept="image/*" hidden multiple />
<MudIconButton HtmlTag="label" Icon="@Icons.Filled.PhotoCamera" for="imageInput" Title="Upload image file" />
</MudTooltip>
<MudTooltip Text="cropper.getCroppedCanvas({ maxWidth: 4096, maxHeight: 4096 })">
<MudButton Color="Color.Secondary" Variant="Variant.Filled"
OnClick="@(()=>GetCroppedCanvasDataURL(new GetCroppedCanvasOptions(){ MaxHeight = 4096, MaxWidth = 4096}))">
Get Cropped Canvas
</MudButton>
</MudTooltip>
</MudButtonGroup>

<div class="img-container">
<CropperComponent Class="cropper-container big-img"
ErrorLoadImageClass="cropper-error-load"
@ref="cropperComponent"
OnCropStartEvent="OnCropStartEvent"
OnCropEndEvent="OnCropEndEvent"
OnCropEvent="OnCropEvent"
OnZoomEvent="OnZoomEvent"
OnCropMoveEvent="OnCropMoveEvent"
OnReadyEvent="OnCropReadyEvent"
OnLoadImageEvent="OnLoadImageEvent"
Src="@Src"
InputAttributes="@InputAttributes"
ErrorLoadImageSrc="@_errorLoadImageSrc"
IsErrorLoadImage="@IsErrorLoadImage"
OnErrorLoadImageEvent="OnErrorLoadImageEvent"
Options="options" />
</div>

<style>
.big-img {
max-height: 400px;
/* This rule is very important, please don't ignore this */
max-width: 100%;
}
.img-container {
max-height: 400px;
width: 100%;
}
</style>
Loading

0 comments on commit faea1ec

Please sign in to comment.