diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ed6b0f0..6842c1d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.6.0 - 2024-02-14 + +### 💥 Introduce breaking changes + +- Drop IFormFile upload (not supported in WASM). IBrowserFile is still available (#118) + ## 0.5.1 - 2024-02-12 ### ✨ Introduce new features diff --git a/CodeMirror6/CodeMirror6.csproj b/CodeMirror6/CodeMirror6.csproj index f787ac24..b889b94e 100644 --- a/CodeMirror6/CodeMirror6.csproj +++ b/CodeMirror6/CodeMirror6.csproj @@ -9,7 +9,7 @@ GaelJ.BlazorCodeMirror6 true GaelJ.BlazorCodeMirror6 - 0.5.1 + 0.6.0 true snupkg true @@ -42,9 +42,6 @@ - - - diff --git a/CodeMirror6/CodeMirror6Wrapper.razor b/CodeMirror6/CodeMirror6Wrapper.razor index f459898d..bfa6b304 100644 --- a/CodeMirror6/CodeMirror6Wrapper.razor +++ b/CodeMirror6/CodeMirror6Wrapper.razor @@ -28,7 +28,6 @@ TabSize="@TabSize" Theme="@Theme" UploadBrowserFile="@UploadBrowserFile" - UploadFile="@UploadFile" MergeViewConfiguration="@MergeViewConfiguration" FileNameOrExtension="@FileNameOrExtension" HighlightWhitespace="@HighlightWhitespace" diff --git a/CodeMirror6/CodeMirror6Wrapper.razor.cs b/CodeMirror6/CodeMirror6Wrapper.razor.cs index 6bf316ba..505d556b 100644 --- a/CodeMirror6/CodeMirror6Wrapper.razor.cs +++ b/CodeMirror6/CodeMirror6Wrapper.razor.cs @@ -109,10 +109,6 @@ public partial class CodeMirror6Wrapper : ComponentBase /// [Parameter] public Func>>? GetMentionCompletions { get; set; } /// - /// Upload a file to a server and return the URL to the file - /// - [Parameter] public Func>? UploadFile { get; set; } - /// /// Upload an IBrowserFile to a server and returns the URL to the file /// [Parameter] public Func>? UploadBrowserFile { get; set; } diff --git a/CodeMirror6/CodeMirror6WrapperInternal.razor.JsInvokables.cs b/CodeMirror6/CodeMirror6WrapperInternal.razor.JsInvokables.cs index b7e7e985..e45a8ab2 100644 --- a/CodeMirror6/CodeMirror6WrapperInternal.razor.JsInvokables.cs +++ b/CodeMirror6/CodeMirror6WrapperInternal.razor.JsInvokables.cs @@ -108,13 +108,10 @@ [JSInvokable] public async Task> LintingRequestedFrom { if (Setup.DebugLogs) Logger.LogInformation("UploadFileFromJS: {fileName}", fileName); using var fileStream = new MemoryStream(fileBytes); - var customFormFile = new CustomFormFile(fileStream, fileName, contentType); var customBrowserFile = new CustomBrowserFile(fileStream, fileName, contentType, lastModified); - var fileUrl = UploadFile is not null - ? await UploadFile(customFormFile) - : UploadBrowserFile is not null - ? await UploadBrowserFile(customBrowserFile) - : null; + var fileUrl = UploadBrowserFile is not null + ? await UploadBrowserFile(customBrowserFile) + : null; if (!string.IsNullOrEmpty(fileUrl)) { var imageChar = contentType.StartsWith("image/") ? "!" : string.Empty; var imageLink = $"\n{imageChar}[{fileName}]({fileUrl})\n"; diff --git a/CodeMirror6/CodeMirror6WrapperInternal.razor.cs b/CodeMirror6/CodeMirror6WrapperInternal.razor.cs index bf110ec9..b2d91180 100644 --- a/CodeMirror6/CodeMirror6WrapperInternal.razor.cs +++ b/CodeMirror6/CodeMirror6WrapperInternal.razor.cs @@ -113,10 +113,6 @@ public partial class CodeMirror6WrapperInternal : ComponentBase, IAsyncDisposabl /// [Parameter] public Func>>? GetMentionCompletions { get; set; } /// - /// Upload a file to a server and return the URL to the file - /// - [Parameter] public Func>? UploadFile { get; set; } - /// /// Upload an IBrowserFile to a server and returns the URL to the file /// [Parameter] public Func>? UploadBrowserFile { get; set; } diff --git a/CodeMirror6/Models/CustomFormFile.cs b/CodeMirror6/Models/CustomFormFile.cs deleted file mode 100644 index 54c0a0bc..00000000 --- a/CodeMirror6/Models/CustomFormFile.cs +++ /dev/null @@ -1,51 +0,0 @@ -namespace GaelJ.BlazorCodeMirror6.Models; - -using Microsoft.AspNetCore.Http; - -/// -/// Represents a custom implementation of the IFormFile interface. -/// -/// -/// -/// -public class CustomFormFile(Stream stream, string fileName, string contentType) : IFormFile -{ - private readonly Stream _stream = stream ?? throw new ArgumentNullException(nameof(stream)); - private readonly string _fileName = fileName ?? throw new ArgumentNullException(nameof(fileName)); - private readonly string _contentType = contentType ?? throw new ArgumentNullException(nameof(contentType)); - - /// - public string ContentType => _contentType; - /// - public string ContentDisposition => $"form-data; name=\"{Name}\"; filename=\"{_fileName}\""; - /// - public long Length { get; } = stream.Length; - /// - public string Name => "file"; - /// - public string FileName => _fileName; - - /// - public IHeaderDictionary Headers => new HeaderDictionary(); - - /// - public void CopyTo(Stream target) - { - _stream.Seek(0, SeekOrigin.Begin); - _stream.CopyTo(target); - } - - /// - public async Task CopyToAsync(Stream target, CancellationToken cancellationToken = default) - { - _stream.Seek(0, SeekOrigin.Begin); - await _stream.CopyToAsync(target, cancellationToken); - } - - /// - public Stream OpenReadStream() - { - _stream.Seek(0, SeekOrigin.Begin); - return _stream; - } -} diff --git a/Examples.BlazorServer/Examples.BlazorServer.csproj b/Examples.BlazorServer/Examples.BlazorServer.csproj index b2d5ee24..2f66d9eb 100644 --- a/Examples.BlazorServer/Examples.BlazorServer.csproj +++ b/Examples.BlazorServer/Examples.BlazorServer.csproj @@ -4,7 +4,7 @@ enable false enable - 0.5.1 + 0.6.0 diff --git a/Examples.BlazorServerInteractive/Examples.BlazorServerInteractive.csproj b/Examples.BlazorServerInteractive/Examples.BlazorServerInteractive.csproj index cad94b3e..acbeb53f 100644 --- a/Examples.BlazorServerInteractive/Examples.BlazorServerInteractive.csproj +++ b/Examples.BlazorServerInteractive/Examples.BlazorServerInteractive.csproj @@ -4,7 +4,7 @@ enable enable false - 0.5.1 + 0.6.0 diff --git a/Examples.BlazorWasm/Examples.BlazorWasm.csproj b/Examples.BlazorWasm/Examples.BlazorWasm.csproj index 8cf6b707..3040bc42 100644 --- a/Examples.BlazorWasm/Examples.BlazorWasm.csproj +++ b/Examples.BlazorWasm/Examples.BlazorWasm.csproj @@ -4,7 +4,7 @@ enable enable false - 0.5.1 + 0.6.0 diff --git a/Examples.Common/Example.razor b/Examples.Common/Example.razor index 793d2a36..c549a2f1 100644 --- a/Examples.Common/Example.razor +++ b/Examples.Common/Example.razor @@ -120,7 +120,7 @@ Setup=@Setup ReplaceEmojiCodes=@ReplaceEmojiCodes GetMentionCompletions=@GetMentionCompletions - UploadFile=@UploadFile + UploadBrowserFile=@UploadBrowserFile Editable=@(!ReadOnly) ReadOnly=@ReadOnly LineNumbers=@(!ReadOnly) @@ -349,7 +349,7 @@ private string ButtonClass(bool enabled) => enabled ? "btn btn-sm btn-primary" : "btn btn-sm btn-outline-secondary"; - private List Styles = []; + private List Styles = []; private async Task ToggleEmojis(CMCommandDispatcher commands) { @@ -385,9 +385,9 @@ return Task.FromResult(result); } - private async Task UploadFile(Microsoft.AspNetCore.Http.IFormFile file) + private async Task UploadBrowserFile(IBrowserFile file) { - var fileBytes = new byte[file.Length]; + var fileBytes = new byte[file.Size]; await file.OpenReadStream().ReadAsync(fileBytes); var base64 = Convert.ToBase64String(fileBytes); var mimeType = file.ContentType; diff --git a/Examples.Common/Examples.Common.csproj b/Examples.Common/Examples.Common.csproj index e2482899..d88c4117 100644 --- a/Examples.Common/Examples.Common.csproj +++ b/Examples.Common/Examples.Common.csproj @@ -5,7 +5,7 @@ enable enable false - 0.5.1 + 0.6.0 diff --git a/NEW_CHANGELOG.md b/NEW_CHANGELOG.md index c5bb9649..9648cf40 100644 --- a/NEW_CHANGELOG.md +++ b/NEW_CHANGELOG.md @@ -1,13 +1,3 @@ -### ✨ Introduce new features +### 💥 Introduce breaking changes -- Implement foldMarkdownCodeBlocks -- Show styles at selection in example - -### 🔊 Add or update logs - -- Clarify log message -- Log config and setup at initialization - -### 🥅 Catch errors - -- Check for existence of the parent div and error out immediately if not found +- Drop IFormFile upload (not supported in WASM). IBrowserFile is still available (#118)