Skip to content

Commit

Permalink
Merge pull request #104 from gaelj/release
Browse files Browse the repository at this point in the history
Release 0.3.6
  • Loading branch information
gaelj authored Feb 8, 2024
2 parents 24bd373 + 82edfb2 commit 4b47469
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 90 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## 0.3.6 - 2024-02-08

### 🐛 Fix a bug

- Try to fix random crash at startup

### 💥 Introduce breaking changes

- Move Id from parameter to Setup, as it should never be changed

### 🔊 Add or update logs

- Add DebugLogs setup parameter to print debug logs

## 0.3.5 - 2024-02-07

### ✨ Introduce new features
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.3.5</Version>
<Version>0.3.6</Version>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
1 change: 0 additions & 1 deletion CodeMirror6/CodeMirror6Wrapper.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
Editable="@Editable"
FocusChanged="@FocusChanged"
GetMentionCompletions="@GetMentionCompletions"
Id="@Id"
IndentationUnit="@IndentationUnit"
IsWASM="@IsWASM"
Language="@Language"
Expand Down
2 changes: 1 addition & 1 deletion CodeMirror6/CodeMirror6WrapperInternal.razor
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<div class=@VisibleClass>
<div
id=@Id
id=@Setup.Id
@attributes=@AdditionalAttributes
>
</div>
Expand Down
4 changes: 2 additions & 2 deletions CodeMirror6/CodeMirror6WrapperInternal.razor.JsInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal async Task ModuleInvokeVoidAsync(string method, params object?[] args)
try {
var module = await _moduleTask.Value;
if (module is null) return;
args = args.Prepend(cm6WrapperComponent.Id).ToArray();
args = args.Prepend(cm6WrapperComponent.Setup.Id).ToArray();
await module.InvokeVoidAsync(method, args);
}
catch (Exception ex)
Expand All @@ -61,7 +61,7 @@ internal async Task ModuleInvokeVoidAsync(string method, params object?[] args)
try {
var module = await _moduleTask.Value;
if (module is null) return default;
args = args.Prepend(cm6WrapperComponent.Id).ToArray();
args = args.Prepend(cm6WrapperComponent.Setup.Id).ToArray();
return await module.InvokeAsync<T?>(method, args);
}
catch (Exception ex)
Expand Down
7 changes: 7 additions & 0 deletions CodeMirror6/CodeMirror6WrapperInternal.razor.JsInvokables.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using GaelJ.BlazorCodeMirror6.Models;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Logging;
using Microsoft.JSInterop;

namespace GaelJ.BlazorCodeMirror6;
Expand All @@ -22,6 +23,7 @@ public partial class CodeMirror6WrapperInternal : ComponentBase, IAsyncDisposabl
/// <returns></returns>
[JSInvokable] public async Task DocChangedFromJS(string value)
{
if (Setup.DebugLogs) Logger.LogInformation("DocChangedFromJS: {value}", value);
if (Doc?.Replace("\r", "") == value?.Replace("\r", "")) return;
Doc = value?.Replace("\r", "") ?? "";
Config.Doc = Doc;
Expand All @@ -35,6 +37,7 @@ [JSInvokable] public async Task DocChangedFromJS(string value)
/// <returns></returns>
[JSInvokable] public async Task FocusChangedFromJS(bool value)
{
if (Setup.DebugLogs) Logger.LogInformation("FocusChangedFromJS: {value}", value);
if (State.HasFocus == value) return;
State.HasFocus = value;
await FocusChanged.InvokeAsync(State.HasFocus);
Expand All @@ -47,6 +50,7 @@ [JSInvokable] public async Task FocusChangedFromJS(bool value)
/// <returns></returns>
[JSInvokable] public async Task SelectionSetFromJS(IEnumerable<SelectionRange>? values)
{
if (Setup.DebugLogs) Logger.LogInformation("SelectionChangedFromJS: @{values}", values);
Selection = values?.ToList();
await SelectionChanged.InvokeAsync(Selection);
}
Expand All @@ -58,6 +62,7 @@ [JSInvokable] public async Task SelectionSetFromJS(IEnumerable<SelectionRange>?
/// <returns></returns>
[JSInvokable] public async Task MarkdownStyleChangedFromJS(IEnumerable<string>? values)
{
if (Setup.DebugLogs) Logger.LogInformation("MarkdownStyleChangedFromJS: @{values}", values);
State.MarkdownStylesAtSelections = new(values?.ToList() ?? []);
await MarkdownStylesAtSelectionsChanged.InvokeAsync(State.MarkdownStylesAtSelections);
}
Expand All @@ -69,6 +74,7 @@ [JSInvokable] public async Task MarkdownStyleChangedFromJS(IEnumerable<string>?
/// <returns></returns>
[JSInvokable] public async Task<List<CodeMirrorDiagnostic>> LintingRequestedFromJS(string document)
{
if (Setup.DebugLogs) Logger.LogInformation("LintingRequestedFromJS: {document}", document);
if (Setup.BindMode == DocumentBindMode.OnDelayedInput) {
await DocChangedFromJS(document);
}
Expand Down Expand Up @@ -100,6 +106,7 @@ [JSInvokable] public async Task<List<CodeMirrorDiagnostic>> LintingRequestedFrom
/// <returns></returns>
[JSInvokable] public async Task<string?> UploadFileFromJS(byte[] fileBytes, string fileName, string contentType, DateTime lastModified)
{
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);
Expand Down
143 changes: 74 additions & 69 deletions CodeMirror6/CodeMirror6WrapperInternal.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Microsoft.JSInterop;

namespace GaelJ.BlazorCodeMirror6;
Expand All @@ -13,12 +14,8 @@ namespace GaelJ.BlazorCodeMirror6;
public partial class CodeMirror6WrapperInternal : ComponentBase, IAsyncDisposable
{
[Inject] private IJSRuntime JSRuntime { get; set; } = null!;
/// <summary>
/// /// Gets or sets the unique identifier for the CodeMirror6 editor.
/// Defaults to CodeMirror6_Editor_{NewGuid}.
/// </summary>
/// <value></value>
[Parameter] public string Id { get; set; } = $"CodeMirror6_Editor_{Guid.NewGuid()}";
[Inject] private ILogger<CodeMirror6WrapperInternal> Logger { get; set; } = null!;

/// <summary>
/// The size of the tab character to use for the editor
/// </summary>
Expand Down Expand Up @@ -182,7 +179,7 @@ public partial class CodeMirror6WrapperInternal : ComponentBase, IAsyncDisposabl
/// <returns></returns>
public CMCommandDispatcher? CommandDispatcher => CmJsInterop?.CommandDispatcher;

private string LoadingDivId => $"{Id}_Loading";
private string LoadingDivId => $"{Setup.Id}_Loading";
private string ResizeStyle => AllowVerticalResize && AllowHorizontalResize
? "both"
: AllowVerticalResize ? "vertical"
Expand Down Expand Up @@ -264,71 +261,78 @@ protected override async Task OnParametersSetAsync()
shouldRender = true;
if (CmJsInterop is null) return;
shouldRender = false;
if (Config.TabSize != TabSize) {
Config.TabSize = TabSize;
await CmJsInterop.PropertySetters.SetTabSize();
}
if (Config.IndentationUnit != IndentationUnit) {
Config.IndentationUnit = IndentationUnit;
await CmJsInterop.PropertySetters.SetIndentUnit();
}
if (Config.Doc?.Replace("\r", "") != Doc?.Replace("\r", "")) {
Config.Doc = Doc;
await CmJsInterop.PropertySetters.SetDoc();
}
if (Config.Placeholder != Placeholder) {
Config.Placeholder = Placeholder;
await CmJsInterop.PropertySetters.SetPlaceholderText();
}
if (Config.ThemeName != Theme) {
Config.ThemeName = Theme;
await CmJsInterop.PropertySetters.SetTheme();
}
if (Config.ReadOnly != ReadOnly) {
Config.ReadOnly = ReadOnly;
await CmJsInterop.PropertySetters.SetReadOnly();
}
if (Config.Editable != Editable) {
Config.Editable = Editable;
await CmJsInterop.PropertySetters.SetEditable();
}
if (Config.LanguageName != Language) {
Config.LanguageName = Language;
await CmJsInterop.PropertySetters.SetLanguage();
}
if (Config.FileNameOrExtension != FileNameOrExtension) {
Config.FileNameOrExtension = FileNameOrExtension;
await CmJsInterop.PropertySetters.SetLanguage();
}
if (Config.AutoFormatMarkdown != AutoFormatMarkdown) {
Config.AutoFormatMarkdown = AutoFormatMarkdown;
await CmJsInterop.PropertySetters.SetAutoFormatMarkdown();
}
if (Config.ReplaceEmojiCodes != ReplaceEmojiCodes) {
Config.ReplaceEmojiCodes = ReplaceEmojiCodes;
await CmJsInterop.PropertySetters.SetReplaceEmojiCodes();
}
if (Config.Resize != ResizeStyle) {
Config.Resize = ResizeStyle;
await CmJsInterop.PropertySetters.SetResize();
}
if (Config.LineWrapping != LineWrapping) {
Config.LineWrapping = LineWrapping;
await CmJsInterop.PropertySetters.SetLineWrapping();
}
if (Config.MergeViewConfiguration != MergeViewConfiguration) {
Config.MergeViewConfiguration = MergeViewConfiguration;
await CmJsInterop.PropertySetters.SetUnifiedMergeView();
try {
if (Config.TabSize != TabSize) {
Config.TabSize = TabSize;
await CmJsInterop.PropertySetters.SetTabSize();
}
if (Config.IndentationUnit != IndentationUnit) {
Config.IndentationUnit = IndentationUnit;
await CmJsInterop.PropertySetters.SetIndentUnit();
}
if (Config.Doc?.Replace("\r", "") != Doc?.Replace("\r", "")) {
Config.Doc = Doc;
await CmJsInterop.PropertySetters.SetDoc();
}
if (Config.Placeholder != Placeholder) {
Config.Placeholder = Placeholder;
await CmJsInterop.PropertySetters.SetPlaceholderText();
}
if (Config.ThemeName != Theme) {
Config.ThemeName = Theme;
await CmJsInterop.PropertySetters.SetTheme();
}
if (Config.ReadOnly != ReadOnly) {
Config.ReadOnly = ReadOnly;
await CmJsInterop.PropertySetters.SetReadOnly();
}
if (Config.Editable != Editable) {
Config.Editable = Editable;
await CmJsInterop.PropertySetters.SetEditable();
}
if (Config.LanguageName != Language) {
Config.LanguageName = Language;
await CmJsInterop.PropertySetters.SetLanguage();
}
if (Config.FileNameOrExtension != FileNameOrExtension) {
Config.FileNameOrExtension = FileNameOrExtension;
await CmJsInterop.PropertySetters.SetLanguage();
}
if (Config.AutoFormatMarkdown != AutoFormatMarkdown) {
Config.AutoFormatMarkdown = AutoFormatMarkdown;
await CmJsInterop.PropertySetters.SetAutoFormatMarkdown();
}
if (Config.ReplaceEmojiCodes != ReplaceEmojiCodes) {
Config.ReplaceEmojiCodes = ReplaceEmojiCodes;
await CmJsInterop.PropertySetters.SetReplaceEmojiCodes();
}
if (Config.Resize != ResizeStyle) {
Config.Resize = ResizeStyle;
await CmJsInterop.PropertySetters.SetResize();
}
if (Config.LineWrapping != LineWrapping) {
Config.LineWrapping = LineWrapping;
await CmJsInterop.PropertySetters.SetLineWrapping();
}
if (Config.MergeViewConfiguration != MergeViewConfiguration) {
Config.MergeViewConfiguration = MergeViewConfiguration;
await CmJsInterop.PropertySetters.SetUnifiedMergeView();
}
if (Config.HighlightTrailingWhitespace != HighlightTrailingWhitespace) {
Config.HighlightTrailingWhitespace = HighlightTrailingWhitespace;
await CmJsInterop.PropertySetters.SetHighlightTrailingWhitespace();
}
if (Config.HighlightWhitespace != HighlightWhitespace) {
Config.HighlightWhitespace = HighlightWhitespace;
await CmJsInterop.PropertySetters.SetHighlightWhitespace();
}
}
if (Config.HighlightTrailingWhitespace != HighlightTrailingWhitespace) {
Config.HighlightTrailingWhitespace = HighlightTrailingWhitespace;
await CmJsInterop.PropertySetters.SetHighlightTrailingWhitespace();
catch (Exception ex) {
Logger.LogError(ex, "Error setting CodeMirror6 properties");
}
if (Config.HighlightWhitespace != HighlightWhitespace) {
Config.HighlightWhitespace = HighlightWhitespace;
await CmJsInterop.PropertySetters.SetHighlightWhitespace();
finally {
shouldRender = true;
}
shouldRender = true;
}

/// <summary>
Expand All @@ -349,6 +353,7 @@ public async ValueTask DisposeAsync()
{
if (CmJsInterop?.IsJSReady == true)
await CmJsInterop.DisposeAsync();
CmJsInterop = null;
try {
LinterCancellationTokenSource.Cancel();
LinterCancellationTokenSource.Dispose();
Expand Down
12 changes: 12 additions & 0 deletions CodeMirror6/Models/CodeMirrorSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ public CodeMirrorSetup()
{
}

/// <summary>
/// /// Gets or sets the unique identifier for the CodeMirror6 editor.
/// Defaults to CodeMirror6_Editor_{NewGuid}.
/// </summary>
/// <value></value>
[JsonPropertyName("id")] public string Id { get; init; } = $"CodeMirror6_Editor_{Guid.NewGuid()}";

/// <summary>
/// Whether to show line numbers to the left of the editor.
/// </summary>
Expand Down Expand Up @@ -134,4 +141,9 @@ public CodeMirrorSetup()
/// Can the user scroll past the end of the document
/// </summary>
[JsonPropertyName("scrollPastEnd")] public bool ScrollPastEnd { get; init; } = false;

/// <summary>
/// Whether to show the debug logs
/// </summary>
[JsonPropertyName("debugLogs")] public bool DebugLogs { get; init; } = false;
}
1 change: 1 addition & 0 deletions CodeMirror6/NodeLib/src/CmSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ export class CmSetup
public bindValueMode: string
public krokiUrl: string
public scrollPastEnd: boolean
public debugLogs: boolean
}
28 changes: 22 additions & 6 deletions CodeMirror6/NodeLib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,13 @@ export async function initCodeMirror(
initialConfig: CmConfiguration,
setup: CmSetup
) {
if (CMInstances[id] !== undefined)
return;
if (CMInstances[id] !== undefined) {
consoleLog(id, `CodeMirror instance ${id} already exists`)
return
}

console.log(`Initializing CodeMirror instance ${id}`)
if (setup.debugLogs === true)
console.log(`Initializing CodeMirror instance ${id}`)
try {
const minDelay = new Promise(res => setTimeout(res, 100))

Expand Down Expand Up @@ -223,13 +226,23 @@ export async function initCodeMirror(
}
}

export function getAllSupportedLanguageNames(id: string)
function consoleLog(id: string, message: string)
{
if (CMInstances[id].setup.debugLogs === true)
console.log(message)
}

export function getAllSupportedLanguageNames()
{
return languages.map((language) => language.name)
}

async function updateListenerExtension(id: string, update: ViewUpdate) {
const dotnetHelper = CMInstances[id].dotNetHelper
if (dotnetHelper === undefined){
consoleLog(id, `DotNetHelper is undefined`)
return
}
const setup = CMInstances[id].setup
if (update.docChanged) {
if (setup.bindValueMode === 'OnInput')
Expand Down Expand Up @@ -351,7 +364,10 @@ export function setHighlightWhitespace(id: string, value: boolean) {

export function forceRedraw(id: string) {
const view = CMInstances[id].view
if (!view) return
if (!view) {
consoleLog(id, `View is undefined`)
return
}

view.requestMeasure()
view.update([])
Expand Down Expand Up @@ -467,7 +483,7 @@ export function dispatchCommand(id: string, functionName: string, ...args: any[]
* @param id
*/
export function dispose(id: string) {
console.log(`Disposing of CodeMirror instance ${id}`)
consoleLog(id, `Disposing of CodeMirror instance ${id}`)
CMInstances[id].dotNetHelper.dispose()
CMInstances[id].dotNetHelper = undefined
CMInstances[id].view.destroy()
Expand Down
Loading

0 comments on commit 4b47469

Please sign in to comment.