Skip to content

Commit

Permalink
Merge pull request #146 from gaelj/fix-diagrams-on-startup
Browse files Browse the repository at this point in the history
Improve attached files
  • Loading branch information
gaelj authored Feb 20, 2024
2 parents d6a28b1 + 824b7dc commit 8b2ebb5
Show file tree
Hide file tree
Showing 23 changed files with 642 additions and 479 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- name: 📥 Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4.1.1

- name: 🔍 Extract version from csproj
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/depoloy-on-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4.1.1

- name: 📦 Setup NuGet
uses: NuGet/[email protected]
Expand Down
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# Changelog

## 0.7.0 - 2024-02-20

### ✨ Introduce new features

- Allow embedding uploads as data URLs directly in JS (https://github.com/gaelj/BlazorCodeMirror6/issues/118#issuecomment-1947521108)
- Always enable clickable links
- Apply hyperlink decoration to markdown links
- Export code mirror instances and csvToMarkdownTable (#144)

### 🐛 Fix a bug

- Fix broken markdown link decoration when link is bigger than visible range (#145)

### ⚡️ Improve performance

- Hyperlinks: only perform doc.toString() once for all regex matches

### ⬆️ Upgrade dependencies

- Update JS dependencies: @uiw & rollup

### 🔧 Add or update configuration files

- Update actions/[email protected]

## 0.6.5 - 2024-02-15

### 🐛 Fix a bug
Expand Down
2 changes: 1 addition & 1 deletion CodeMirror6/CodeMirror6.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AssemblyName>GaelJ.BlazorCodeMirror6</AssemblyName>
<IsPackable>true</IsPackable>
<PackageId>GaelJ.BlazorCodeMirror6</PackageId>
<Version>0.6.5</Version>
<Version>0.7.0</Version>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
1 change: 1 addition & 0 deletions CodeMirror6/CodeMirror6Wrapper.razor
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
TabSize="@TabSize"
Theme="@Theme"
UploadBrowserFile="@UploadBrowserFile"
EmbedUploadsAsDataUrls="@EmbedUploadsAsDataUrls"
MergeViewConfiguration="@MergeViewConfiguration"
FileNameOrExtension="@FileNameOrExtension"
HighlightWhitespace="@HighlightWhitespace"
Expand Down
4 changes: 4 additions & 0 deletions CodeMirror6/CodeMirror6Wrapper.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ public partial class CodeMirror6Wrapper : ComponentBase
/// </summary>
[Parameter] public Func<IBrowserFile, Task<string>>? UploadBrowserFile { get; set; }
/// <summary>
/// Whether to embed uploads as data URLs instead of using the custom callback. Warning: this can cause performance issues, especially in Blazor Server apps.
/// </summary>
[Parameter] public bool EmbedUploadsAsDataUrls { get; set; }
/// <summary>
/// Define whether the component is used in a WASM or Server app. In a WASM app, JS interop can start sooner
/// </summary>
[Parameter] public bool IsWASM { get; set; }
Expand Down
4 changes: 4 additions & 0 deletions CodeMirror6/CodeMirror6WrapperInternal.razor.JsInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ internal async Task<bool> ModuleInvokeVoidAsync(string method, params object?[]
return true;
}
catch (ObjectDisposedException) {}
catch (OperationCanceledException) {}
catch (JSDisconnectedException) {}
catch (Exception ex)
{
Expand All @@ -70,6 +71,9 @@ internal async Task<bool> ModuleInvokeVoidAsync(string method, params object?[]
catch (ObjectDisposedException) {
return default;
}
catch (OperationCanceledException) {
return default;
}
catch (JSDisconnectedException) {
return default;
}
Expand Down
5 changes: 0 additions & 5 deletions CodeMirror6/CodeMirror6WrapperInternal.razor.JsInvokables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ [JSInvokable] public async Task<List<CodeMirrorDiagnostic>> LintingRequestedFrom
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";
//await CmJsInterop!.Commands.Dispatch(CodeMirrorCommandOneParameter.InsertTextAbove, imageLink);
}
return fileUrl;
}

Expand Down
17 changes: 13 additions & 4 deletions CodeMirror6/CodeMirror6WrapperInternal.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ public partial class CodeMirror6WrapperInternal : ComponentBase, IAsyncDisposabl
/// </summary>
[Parameter] public Func<IBrowserFile, Task<string>>? UploadBrowserFile { get; set; }
/// <summary>
/// Whether to embed uploads as data URLs instead of using the custom callback. Warning: this can cause performance issues, especially in Blazor Server apps.
/// </summary>
[Parameter] public bool EmbedUploadsAsDataUrls { get; set; }
/// <summary>
/// Define whether the component is used in a WASM or Server app. In a WASM app, JS interop can start sooner
/// </summary>
[Parameter] public bool IsWASM { get; set; }
Expand Down Expand Up @@ -279,7 +283,7 @@ protected override async Task OnInitializedAsync()
HighlightWhitespace,
LocalStorageKey,
FullScreen,
UploadBrowserFile is not null,
UploadBrowserFile is not null || EmbedUploadsAsDataUrls,
MaxDocumentLength,
LineNumbers,
HighlightActiveLineGutter,
Expand All @@ -288,7 +292,8 @@ protected override async Task OnInitializedAsync()
PreviewImages,
ScrollPastEnd,
HighlightActiveLine,
ShowMarkdownControlCharactersAroundCursor
ShowMarkdownControlCharactersAroundCursor,
EmbedUploadsAsDataUrls
);
try {
if (IsWASM)
Expand Down Expand Up @@ -410,8 +415,12 @@ protected override async Task OnParametersSetAsync()
Config.FullScreen = FullScreen;
updated = true;
}
if (Config.SupportFileUpload != (UploadBrowserFile is not null)) {
Config.SupportFileUpload = UploadBrowserFile is not null;
if (Config.SupportFileUpload != (UploadBrowserFile is not null || EmbedUploadsAsDataUrls)) {
Config.SupportFileUpload = UploadBrowserFile is not null || EmbedUploadsAsDataUrls;
updated = true;
}
if (Config.EmbedUploadsAsDataUrls != EmbedUploadsAsDataUrls) {
Config.EmbedUploadsAsDataUrls = EmbedUploadsAsDataUrls;
updated = true;
}
if (Config.MaxDocumentLength != MaxDocumentLength) {
Expand Down
11 changes: 9 additions & 2 deletions CodeMirror6/Models/CodeMirrorConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace GaelJ.BlazorCodeMirror6.Models;
/// <param name="scrollPastEnd"></param>
/// <param name="highlightActiveLine"></param>
/// <param name="showMarkdownControlCharactersAroundCursor"></param>
/// <param name="embedUploadsAsDataUrls"></param>
public class CodeMirrorConfiguration(
string? doc,
string? placeholder,
Expand Down Expand Up @@ -64,7 +65,8 @@ public class CodeMirrorConfiguration(
bool previewImages,
bool scrollPastEnd,
bool highlightActiveLine,
bool showMarkdownControlCharactersAroundCursor)
bool showMarkdownControlCharactersAroundCursor,
bool embedUploadsAsDataUrls)
{
/// <summary>
/// The text to display in the editor
Expand Down Expand Up @@ -162,7 +164,7 @@ public class CodeMirrorConfiguration(
[JsonPropertyName("fullScreen")] public bool FullScreen { get; internal set; } = fullScreen;

/// <summary>
/// Whether to support file upload
/// Whether to support file upload (either via a custom callback or as data URLs in the document)
/// </summary>
[JsonPropertyName("supportFileUpload")] public bool SupportFileUpload { get; internal set; } = supportFileUpload;

Expand Down Expand Up @@ -210,4 +212,9 @@ public class CodeMirrorConfiguration(
/// Whether to show markdown control characters around the cursor
/// </summary>
[JsonPropertyName("showMarkdownControlCharactersAroundCursor")] public bool ShowMarkdownControlCharactersAroundCursor { get; internal set; } = showMarkdownControlCharactersAroundCursor;

/// <summary>
/// When uploading a file, instead of using the callback, encode the file contents as base64 and include it as a data URL in the document
/// </summary>
[JsonPropertyName("embedUploadsAsDataUrls")] public bool EmbedUploadsAsDataUrls { get; internal set; } = embedUploadsAsDataUrls;
}
Loading

0 comments on commit 8b2ebb5

Please sign in to comment.