Skip to content

Commit

Permalink
upgraded to .net 5 (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
amazingalek authored Apr 30, 2021
1 parent 01760f4 commit 3555a55
Show file tree
Hide file tree
Showing 27 changed files with 753 additions and 749 deletions.
29 changes: 15 additions & 14 deletions src/BlazorQuery.Library/ActionWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@

namespace BlazorQuery.Library
{
public class ActionWrapper<T>
{
private readonly Action<T> _action;
public class ActionWrapper<T>
{
private readonly Action<T> _action;

public ActionWrapper(Action<T> action)
{
this._action = action;
}
// Callbacks
[JSInvokable]
public void ActionCallback(T obj)
{
_action(obj);
}
}
public ActionWrapper(Action<T> action)
{
_action = action;
}

// Callbacks
[JSInvokable]
public void ActionCallback(T obj)
{
_action(obj);
}
}
}
99 changes: 48 additions & 51 deletions src/BlazorQuery.Library/BlazorQuery.Library.csproj
Original file line number Diff line number Diff line change
@@ -1,59 +1,56 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<RazorLangVersion>3.0</RazorLangVersion>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<AssemblyName>BlazorQuery.Library</AssemblyName>
<RootNamespace>BlazorQuery.Library</RootNamespace>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Version>0.0.2</Version>
<Authors>KevinJPetersen and contributors</Authors>
<RepositoryUrl>https://github.com/kevinjpetersen/BlazorQuery</RepositoryUrl>
<PackageProjectUrl>https://github.com/kevinjpetersen/BlazorQuery</PackageProjectUrl>
<RepositoryType>GitHub</RepositoryType>
<PackageTags>Blazor, Razor, jQuery, Query, CSharp, DOM, Manipulation</PackageTags>
<PackageReleaseNotes>Version 0.0.2 - 2020-07-29 | Functionality added
* Update projects to build with latest version of Blazor
* Migration from blazor preview --&gt; blazor release
* Starting wrapping fadein and fadeout
* New testapp to test with blazor webassembly, and refactoring to make common code between the 2 testaspp
Version 0.0.1 - 2019-07-09 | Functionality added
* Added Select (Equivalent to $/jQuery, to select elements)
* Added AddClass, RemoveClass,
* Added Height (Set &amp; Get), Width (Set &amp; Get)
* Added Text (Set &amp; Get)
* Added CSS</PackageReleaseNotes>
<Description>BlazorQuery is a Blazor Library that wraps jQuery in C# so that DOM Manipulation, Ajax, etc, can be done directly without leaving the comfort of C#.</Description>
<Copyright>MIT License</Copyright>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>net5</TargetFrameworks>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<AssemblyName>BlazorQuery.Library</AssemblyName>
<RootNamespace>BlazorQuery.Library</RootNamespace>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Version>0.0.2</Version>
<Authors>KevinJPetersen and contributors</Authors>
<RepositoryUrl>https://github.com/kevinjpetersen/BlazorQuery</RepositoryUrl>
<PackageProjectUrl>https://github.com/kevinjpetersen/BlazorQuery</PackageProjectUrl>
<RepositoryType>GitHub</RepositoryType>
<PackageTags>Blazor, Razor, jQuery, Query, CSharp, DOM, Manipulation</PackageTags>
<PackageReleaseNotes>
Version 0.0.2 - 2020-07-29 | Functionality added
* Update projects to build with latest version of Blazor
* Migration from blazor preview --&gt; blazor release
* Starting wrapping fadein and fadeout
* New testapp to test with blazor webassembly, and refactoring to make common code between the 2 testaspp
Version 0.0.1 - 2019-07-09 | Functionality added
* Added Select (Equivalent to $/jQuery, to select elements)
* Added AddClass, RemoveClass,
* Added Height (Set &amp; Get), Width (Set &amp; Get)
* Added Text (Set &amp; Get)
* Added CSS
</PackageReleaseNotes>
<Description>BlazorQuery is a Blazor Library that wraps jQuery in C# so that DOM Manipulation, Ajax, etc, can be done directly without leaving the comfort of C#.</Description>
<Copyright>MIT License</Copyright>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.6" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.6" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components" Version="5.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.5" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<EmbeddedResource Include="wwwroot\*.js" Exclude="wwwroot\*.min.js" LogicalName="blazor:js:%(RecursiveDir)%(Filename)%(Extension)" />
<EmbeddedResource Include="wwwroot\*.css" Exclude="wwwroot\*.min.css" LogicalName="blazor:css:%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<EmbeddedResource Include="wwwroot\*.js" Exclude="wwwroot\*.min.js" LogicalName="blazor:js:%(RecursiveDir)%(Filename)%(Extension)" />
<EmbeddedResource Include="wwwroot\*.css" Exclude="wwwroot\*.min.css" LogicalName="blazor:css:%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)' == 'Release'">
<EmbeddedResource Include="wwwroot\*.min.js" LogicalName="blazor:js:%(RecursiveDir)%(Filename)%(Extension)" />
<EmbeddedResource Include="wwwroot\*.min.css" LogicalName="blazor:css:%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Release'">
<EmbeddedResource Include="wwwroot\*.min.js" LogicalName="blazor:js:%(RecursiveDir)%(Filename)%(Extension)" />
<EmbeddedResource Include="wwwroot\*.min.css" LogicalName="blazor:css:%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Remove="wwwroot\jquery.js" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\LICENSE">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>
<ItemGroup>
<None Include="..\..\LICENSE">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

</Project>
124 changes: 59 additions & 65 deletions src/BlazorQuery.Library/BlazorQueryDOM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,67 @@
using System.Collections.Generic;
using System.Text.Json;
using System.Threading.Tasks;
using BlazorQuery.Library.Elements;

namespace BlazorQuery.Library
{

public class BlazorQueryDOM : ComponentBase
{
private IJSRuntime JSRuntime { get; set; }

public List<BlazorQueryDOMElement> Elements { get; private set; }
private string CurrentSelector { get; set; }

public BlazorQueryDOM(IJSRuntime JSRuntime)
{
this.JSRuntime = JSRuntime;
Elements = new List<BlazorQueryDOMElement>();
}

public async Task<BlazorQueryDOM> Select(string selector)
{
BlazorQueryDOM dom = new BlazorQueryDOM(JSRuntime);
dom.CurrentSelector = selector;
var data = await JSRuntime.InvokeAsync<string>(BlazorQueryList.Select, selector);
dom.Elements = JsonSerializer.Deserialize<List<BlazorQueryDOMElement>>(data);

return dom;
}

// Utilities
public async Task Alert(string message) => await JSRuntime.InvokeAsync<Task>(BlazorQueryList.Utils_Alert, message);
public async Task ConsoleLog(string message) => await JSRuntime.InvokeAsync<Task>(BlazorQueryList.Utils_ConsoleLog, message);

// Functions - Actions
public async Task<BlazorQueryDOM> AddClass(string className) { await JSRuntime.InvokeAsync<Task>(BlazorQueryList.AddClass, CurrentSelector, className); return this; }
public async Task<BlazorQueryDOM> RemoveClass(string className) { await JSRuntime.InvokeAsync<Task>(BlazorQueryList.RemoveClass, CurrentSelector, className); return this; }
public async Task<BlazorQueryDOM> CSS(string style, string styleValue) { await JSRuntime.InvokeAsync<Task>(BlazorQueryList.CSS, CurrentSelector, style, styleValue); return this; }
public async Task<BlazorQueryDOM> Height(int height) { await JSRuntime.InvokeAsync<Task>(BlazorQueryList.Height_Set, CurrentSelector, height); return this; }
public async Task<BlazorQueryDOM> Width(int width) { await JSRuntime.InvokeAsync<Task>(BlazorQueryList.Width_Set, CurrentSelector, width); return this; }
public async Task<BlazorQueryDOM> Text(string text) { await JSRuntime.InvokeAsync<Task>(BlazorQueryList.Text_Set, CurrentSelector, text); return this; }
public async Task<BlazorQueryDOM> FadeOut(Action<string> completed)
{
var actionWrapper = new ActionWrapper<string>(completed);
var dotNetObjectReference = DotNetObjectReference.Create(actionWrapper);
await JSRuntime.InvokeAsync<Task>(BlazorQueryList.FadeOut, CurrentSelector, dotNetObjectReference);
return this;
}

// Functions - Chain-enders
public async Task<int> Height() => await JSRuntime.InvokeAsync<int>(BlazorQueryList.Height_Get, CurrentSelector);
public async Task<int> Width() => await JSRuntime.InvokeAsync<int>(BlazorQueryList.Width_Get, CurrentSelector);
public async Task<string> Text() => await JSRuntime.InvokeAsync<string>(BlazorQueryList.Text_Get, CurrentSelector);

}

public static class BlazorQueryDOMHelpers
{
// Functions - Actions
public async static Task<BlazorQueryDOM> AddClass(this Task<BlazorQueryDOM> dom, string className) => await (await dom).AddClass(className);
public async static Task<BlazorQueryDOM> RemoveClass(this Task<BlazorQueryDOM> dom, string className) => await (await dom).RemoveClass(className);
public async static Task<BlazorQueryDOM> CSS(this Task<BlazorQueryDOM> dom, string style, string styleValue) => await (await dom).CSS(style, styleValue);
public async static Task<BlazorQueryDOM> Height(this Task<BlazorQueryDOM> dom, int height) => await (await dom).Height(height);
public async static Task<BlazorQueryDOM> Width(this Task<BlazorQueryDOM> dom, int width) => await (await dom).Width(width);
public async static Task<BlazorQueryDOM> Text(this Task<BlazorQueryDOM> dom, string text) => await (await dom).Text(text);
public async static Task<BlazorQueryDOM> FadeOut(this Task<BlazorQueryDOM> dom, Action<string> completed) => await (await dom).FadeOut(completed);

// Functions - Chain-enders
public async static Task<int> Height(this Task<BlazorQueryDOM> dom) => await (await dom).Height();
public async static Task<int> Width(this Task<BlazorQueryDOM> dom) => await (await dom).Width();
public async static Task<string> Text(this Task<BlazorQueryDOM> dom) => await (await dom).Text();
}
public class BlazorQueryDOM : ComponentBase
{
private IJSRuntime JsRuntime { get; }

public List<BlazorQueryDOMElement> Elements { get; private set; }

private string CurrentSelector { get; set; }

public BlazorQueryDOM(IJSRuntime jsRuntime)
{
JsRuntime = jsRuntime;
Elements = new List<BlazorQueryDOMElement>();
}

public async Task<BlazorQueryDOM> Select(string selector)
{
var data = await JsRuntime.InvokeAsync<string>(BlazorQueryList.Select, selector);

return new BlazorQueryDOM(JsRuntime)
{
CurrentSelector = selector,
Elements = JsonSerializer.Deserialize<List<BlazorQueryDOMElement>>(data)
};
}

// Utilities
public async Task Alert(string message) => await JsRuntime.InvokeAsync<Task>(BlazorQueryList.Utils_Alert, message);

public async Task ConsoleLog(string message) => await JsRuntime.InvokeAsync<Task>(BlazorQueryList.Utils_ConsoleLog, message);

// Functions - Actions
public async Task<BlazorQueryDOM> AddClass(string className) { await JsRuntime.InvokeAsync<Task>(BlazorQueryList.AddClass, CurrentSelector, className); return this; }

public async Task<BlazorQueryDOM> RemoveClass(string className) { await JsRuntime.InvokeAsync<Task>(BlazorQueryList.RemoveClass, CurrentSelector, className); return this; }

public async Task<BlazorQueryDOM> CSS(string style, string styleValue) { await JsRuntime.InvokeAsync<Task>(BlazorQueryList.CSS, CurrentSelector, style, styleValue); return this; }

public async Task<BlazorQueryDOM> Height(double height) { await JsRuntime.InvokeAsync<Task>(BlazorQueryList.Height_Set, CurrentSelector, height); return this; }

public async Task<BlazorQueryDOM> Width(double width) { await JsRuntime.InvokeAsync<Task>(BlazorQueryList.Width_Set, CurrentSelector, width); return this; }

public async Task<BlazorQueryDOM> Text(string text) { await JsRuntime.InvokeAsync<Task>(BlazorQueryList.Text_Set, CurrentSelector, text); return this; }

public async Task<BlazorQueryDOM> FadeOut(Action<string> completed)
{
var actionWrapper = new ActionWrapper<string>(completed);
var dotNetObjectReference = DotNetObjectReference.Create(actionWrapper);
await JsRuntime.InvokeAsync<Task>(BlazorQueryList.FadeOut, CurrentSelector, dotNetObjectReference);
return this;
}

// Functions - Chain-enders
public async Task<double> Height() => await JsRuntime.InvokeAsync<double>(BlazorQueryList.Height_Get, CurrentSelector);

public async Task<double> Width() => await JsRuntime.InvokeAsync<double>(BlazorQueryList.Width_Get, CurrentSelector);

public async Task<string> Text() => await JsRuntime.InvokeAsync<string>(BlazorQueryList.Text_Get, CurrentSelector);
}
}
30 changes: 30 additions & 0 deletions src/BlazorQuery.Library/BlazorQueryDOMHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Threading.Tasks;

namespace BlazorQuery.Library
{
public static class BlazorQueryDOMHelpers
{
// Functions - Actions
public static async Task<BlazorQueryDOM> AddClass(this Task<BlazorQueryDOM> dom, string className) => await (await dom).AddClass(className);

public static async Task<BlazorQueryDOM> RemoveClass(this Task<BlazorQueryDOM> dom, string className) => await (await dom).RemoveClass(className);

public static async Task<BlazorQueryDOM> CSS(this Task<BlazorQueryDOM> dom, string style, string styleValue) => await (await dom).CSS(style, styleValue);

public static async Task<BlazorQueryDOM> Height(this Task<BlazorQueryDOM> dom, double height) => await (await dom).Height(height);

public static async Task<BlazorQueryDOM> Width(this Task<BlazorQueryDOM> dom, double width) => await (await dom).Width(width);

public static async Task<BlazorQueryDOM> Text(this Task<BlazorQueryDOM> dom, string text) => await (await dom).Text(text);

public static async Task<BlazorQueryDOM> FadeOut(this Task<BlazorQueryDOM> dom, Action<string> completed) => await (await dom).FadeOut(completed);

// Functions - Chain-enders
public static async Task<double> Height(this Task<BlazorQueryDOM> dom) => await (await dom).Height();

public static async Task<double> Width(this Task<BlazorQueryDOM> dom) => await (await dom).Width();

public static async Task<string> Text(this Task<BlazorQueryDOM> dom) => await (await dom).Text();
}
}
Loading

0 comments on commit 3555a55

Please sign in to comment.