From 444ea6f66fd68f5770889edecfe464be0b9a308f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20James?= Date: Sun, 11 Feb 2024 09:13:38 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=92=A5=20Drop=20IFormFile=20upload=20?= =?UTF-8?q?(not=20supported=20in=20WASM).=20IBrowserFile=20is=20still=20av?= =?UTF-8?q?ailable=20(#118)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CodeMirror6/CodeMirror6.csproj | 5 +- CodeMirror6/CodeMirror6Wrapper.razor | 1 - CodeMirror6/CodeMirror6Wrapper.razor.cs | 4 -- ...rror6WrapperInternal.razor.JsInvokables.cs | 9 ++-- .../CodeMirror6WrapperInternal.razor.cs | 4 -- CodeMirror6/Models/CustomFormFile.cs | 51 ------------------- Examples.Common/Example.razor | 8 +-- 7 files changed, 8 insertions(+), 74 deletions(-) delete mode 100644 CodeMirror6/Models/CustomFormFile.cs diff --git a/CodeMirror6/CodeMirror6.csproj b/CodeMirror6/CodeMirror6.csproj index f787ac24..af92348c 100644 --- a/CodeMirror6/CodeMirror6.csproj +++ b/CodeMirror6/CodeMirror6.csproj @@ -42,9 +42,6 @@ - - - @@ -63,4 +60,4 @@ - \ No newline at end of file + 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.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; From f8e53d1011352686d2f67e07c792a534201f8bdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20James?= Date: Wed, 14 Feb 2024 11:22:25 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9D=20Update=20changelog=20for=200?= =?UTF-8?q?.6.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ NEW_CHANGELOG.md | 14 ++------------ 2 files changed, 8 insertions(+), 12 deletions(-) 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/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) From dd7d0071d269afb8c56ac335e3a3d9352a4b50b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20James?= Date: Wed, 14 Feb 2024 11:22:26 +0100 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=94=96=20Bump=20version=20to=200.6.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CodeMirror6/CodeMirror6.csproj | 4 ++-- Examples.BlazorServer/Examples.BlazorServer.csproj | 2 +- .../Examples.BlazorServerInteractive.csproj | 2 +- Examples.BlazorWasm/Examples.BlazorWasm.csproj | 2 +- Examples.Common/Examples.Common.csproj | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CodeMirror6/CodeMirror6.csproj b/CodeMirror6/CodeMirror6.csproj index af92348c..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 @@ -60,4 +60,4 @@ - + \ No newline at end of file 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/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