-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee6f6ae
commit fa1962b
Showing
12 changed files
with
180 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/Blazor.Permissions.WebAssembly/Blazor.Permissions.WebAssembly.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>true</ImplicitUsings> | ||
<Description>Source generated JavaScript interop for the browser's permissions API compatible with Blazor WebAssembly.</Description> | ||
<Copyright>Copyright © David Pine. All rights reserved. Licensed under the MIT License.</Copyright> | ||
<NeutralLanguage>en-US</NeutralLanguage> | ||
<CurrentDate>$([System.DateTime]::Now.ToString(yyyyMMdd))</CurrentDate> | ||
<ClientVersion Condition=" '$(IsPreview)' != 'true' ">$(ClientOfficialVersion)</ClientVersion> | ||
<ClientVersion Condition=" '$(IsPreview)' == 'true' ">$(ClientPreviewVersion)</ClientVersion> | ||
<VersionSuffix Condition=" '$(IsNightly)' == 'true' ">nightly-$(CurrentDate)</VersionSuffix> | ||
<VersionSuffix Condition=" '$(IsPreview)' == 'true' ">preview</VersionSuffix> | ||
<Version Condition=" '$(VersionSuffix)' == '' ">$(ClientVersion)</Version> | ||
<Version Condition=" '$(VersionSuffix)' != '' ">$(ClientVersion)-$(VersionSuffix)</Version> | ||
<FileVersion>$(ClientVersion)</FileVersion> | ||
<Authors>David Pine</Authors> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
<AssemblyName>Blazor.Permissions.WebAssembly</AssemblyName> | ||
<Title>A C# source-generated class library implementation of the native browser's permissions API available as IJSInProcessRuntime extension methods.</Title> | ||
<PackageId>Blazor.Permissions.WebAssembly</PackageId> | ||
<PackageTags>dotnet;dotnetcore;csharp;blazor;webassembly;wasm;generators;sourcegen;roslyn;</PackageTags> | ||
<PackageReleaseNotes></PackageReleaseNotes> | ||
<PackageProjectUrl>https://github.com/IEvangelist/blazorators</PackageProjectUrl> | ||
<PublishRepositoryUrl Condition=" '$(ProjectRef)' != 'True' ">true</PublishRepositoryUrl> | ||
<GenerateAssemblyInfo>true</GenerateAssemblyInfo> | ||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<ShippingScope>External</ShippingScope> | ||
<SigningType>Product</SigningType> | ||
<DebugType>embedded</DebugType> | ||
<IncludeSymbols>false</IncludeSymbols> | ||
<IncludeSource>false</IncludeSource> | ||
<RootNamespace>Blazor.Permissions.WebAssembly</RootNamespace> | ||
<NoWarn>NU5125;NU5039;</NoWarn> | ||
<Optimize Condition="'$(Configuration)'=='Release'">true</Optimize> | ||
<RepositoryUrl>https://github.com/IEvangelist/blazorators</RepositoryUrl> | ||
<PackageLicenseFile>LICENSE</PackageLicenseFile> | ||
<RepositoryType>git</RepositoryType> | ||
<EmbedUntrackedSources>true</EmbedUntrackedSources> | ||
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder> | ||
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
<IsPackable>true</IsPackable> | ||
<PackageIcon>logo.png</PackageIcon> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="MinVer" Version="2.5.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Primitives" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.JSInterop" Version="6.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Blazor.SourceGenerators\Blazor.SourceGenerators.csproj" OutputItemType="Analyzer" SetTargetFramework="TargetFramework=netstandard2.0" ReferenceOutputAssembly="false" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Label="Files"> | ||
<None Include="..\..\LICENSE" Pack="true" PackagePath="\" /> | ||
<None Include="README.md" Pack="true" PackagePath="\" /> | ||
<None Include="..\..\logo.png" Pack="true" PackagePath="\" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Microsoft.JSInterop; | ||
|
||
/// <summary></summary> | ||
[JSAutoInterop( | ||
TypeName = "Permissions", | ||
Implementation = "window.navigator.permissions", | ||
Url = "https://developer.mozilla.org/en-US/docs/Web/API/Navigator/permissions")] | ||
public partial interface IPermissionsService | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Blazorators: The Source Generated `sessionStorage` JavaScript Interop library for Blazor WebAssembly | ||
|
||
The [`Blazor.SessionStorage.WebAssembly`](https://www.nuget.org/packages/Blazor.SessionStorage.WebAssembly) package consumes the [`Blazor.SourceGenerators`](https://www.nuget.org/packages/Blazor.SourceGenerators) package. It exposes a source generated `IStorageService` interface specific to Blazor WebAssembly and the [`sessionStorage`](https://developer.mozilla.org/docs/Web/API/Window/sessionStorage) Web API. | ||
|
||
## Get started | ||
|
||
After the NuGet package is added as a reference, call the `AddSessionStorageServices` method to register the `ISessionStorageService` service type. | ||
|
||
```csharp | ||
using Microsoft.AspNetCore.Components.Web; | ||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting; | ||
|
||
var builder = WebAssemblyHostBuilder.CreateDefault(args); | ||
builder.RootComponents.Add<App>("#app"); | ||
builder.RootComponents.Add<HeadOutlet>("head::after"); | ||
|
||
builder.Services.AddScoped( | ||
sp => new HttpClient | ||
{ | ||
BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) | ||
}); | ||
|
||
builder.Services.AddSessionStorageServices(); | ||
|
||
await builder.Build().RunAsync(); | ||
``` | ||
|
||
Anywhere needed within your Razor component, or Blazor client code — either `@inject` or `[Inject]` the `ISessionStorageService` type. The interface takes the following shape: | ||
|
||
```csharp | ||
using Blazor.Serialization.Extensions; | ||
using System.Text.Json; | ||
|
||
#nullable enable | ||
namespace Microsoft.JSInterop; | ||
|
||
/// <summary> | ||
/// Source generated interface definition of the <c>Storage</c> type. | ||
/// </summary> | ||
public interface ISessionStorageService | ||
{ | ||
/// <summary> | ||
/// Source generated implementation of <c>window.sessionStorage.clear</c>. | ||
/// <a href="https://developer.mozilla.org/docs/Web/API/Storage/clear"></a> | ||
/// </summary> | ||
void Clear(); | ||
|
||
/// <summary> | ||
/// Source generated implementation of <c>window.sessionStorage.getItem</c>. | ||
/// <a href="https://developer.mozilla.org/docs/Web/API/Storage/getItem"></a> | ||
/// </summary> | ||
TResult? GetItem<TResult>(string key, JsonSerializerOptions? options = null); | ||
|
||
/// <summary> | ||
/// Source generated implementation of <c>window.sessionStorage.key</c>. | ||
/// <a href="https://developer.mozilla.org/docs/Web/API/Storage/key"></a> | ||
/// </summary> | ||
string? Key(double index); | ||
|
||
/// <summary> | ||
/// Source generated implementation of <c>window.sessionStorage.removeItem</c>. | ||
/// <a href="https://developer.mozilla.org/docs/Web/API/Storage/removeItem"></a> | ||
/// </summary> | ||
void RemoveItem(string key); | ||
|
||
/// <summary> | ||
/// Source generated implementation of <c>window.sessionStorage.setItem</c>. | ||
/// <a href="https://developer.mozilla.org/docs/Web/API/Storage/setItem"></a> | ||
/// </summary> | ||
void SetItem<TArg>(string key, TArg value, JsonSerializerOptions? options = null); | ||
|
||
/// <summary> | ||
/// Source generated implementation of <c>window.sessionStorage.length</c>. | ||
/// <a href="https://developer.mozilla.org/docs/Web/API/Storage/length"></a> | ||
/// </summary> | ||
double Length { get; } | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.