Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial development #24

Merged
merged 7 commits into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/Examples.BlazorServer/bin/Debug/net7.0/Examples.BlazorServer.dll",
"args": [],
"cwd": "${workspaceFolder}/Examples.BlazorServer",
"stopAtEntry": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": "Launch and Debug Standalone Blazor WebAssembly App",
"type": "blazorwasm",
"request": "launch",
"cwd": "${workspaceFolder}/Examples.BlazorWasm"
}
]
}
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/Examples.BlazorServer/bin/Debug/net8.0/Examples.BlazorServer.dll",
"args": [],
"cwd": "${workspaceFolder}/Examples.BlazorServer",
"stopAtEntry": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": "Launch and Debug Standalone Blazor WebAssembly App",
"type": "blazorwasm",
"request": "launch",
"cwd": "${workspaceFolder}/Examples.BlazorWasm"
}
]
}
7 changes: 6 additions & 1 deletion CodeMirror6/CodeMirror6Wrapper.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ public partial class CodeMirror6Wrapper : ComponentBase, IAsyncDisposable
/// <value></value>
[Parameter] public Func<string, CancellationToken, Task<List<CodeMirrorDiagnostic>>> LintDocument { get; set; } = (_, _) => Task.FromResult(new List<CodeMirrorDiagnostic>());
/// <summary>
/// The CodeMirror setup
/// </summary>
/// <value></value>
[Parameter] public CodeMirrorSetup Setup { get; set; } = new();
/// <summary>
/// Additional attributes to be applied to the container element
/// </summary>
/// <value></value>
Expand Down Expand Up @@ -214,7 +219,7 @@ public async Task<List<CodeMirrorDiagnostic>> LintingRequestedFromJS(string code
/// </summary>
protected override void OnInitialized()
{
Config = new CodeMirrorConfiguration(
Config = new(
Doc,
Placeholder,
Theme?.ToString(),
Expand Down
50 changes: 48 additions & 2 deletions CodeMirror6/CodeMirrorJsInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ internal async Task ModuleInvokeVoidAsync(string method, params object?[] args)
/// Methods to set JS CodeMirror properties to reflect the values of the blazor wrapper parameters. Internal use only.
/// </summary>
/// <returns></returns>
internal CMSetters PropertySetters => _setters ??= new(_dotnetHelperRef, cm6WrapperComponent.Config, this);
internal CMSetters PropertySetters => _setters ??= new(
_dotnetHelperRef,
cm6WrapperComponent.Config,
cm6WrapperComponent.Setup,
this
);

/// <summary>
/// Methods to invoke JS CodeMirror commands.
/// </summary>
Expand All @@ -64,6 +70,7 @@ public async ValueTask DisposeAsync()
internal class CMSetters(
DotNetObjectReference<CodeMirror6Wrapper> _dotnetHelperRef,
CodeMirrorConfiguration config,
CodeMirrorSetup setup,
CodeMirrorJsInterop cmJsInterop
)
{
Expand All @@ -74,7 +81,8 @@ CodeMirrorJsInterop cmJsInterop
public Task InitCodeMirror() => cmJsInterop.ModuleInvokeVoidAsync(
"initCodeMirror",
_dotnetHelperRef,
config
config,
setup
);

/// <summary>
Expand Down Expand Up @@ -168,56 +176,94 @@ public class CMCommands(CodeMirrorJsInterop cmJsInterop)
/// </summary>
/// <returns></returns>
public Task ToggleMarkdownBold() => cmJsInterop.ModuleInvokeVoidAsync("toggleMarkdownBold");

/// <summary>
/// Toggle markdown italic formatting around the selected text
/// </summary>
/// <returns></returns>
public Task ToggleMarkdownItalic() => cmJsInterop.ModuleInvokeVoidAsync("toggleMarkdownItalic");

/// <summary>
/// Toggle markdown strikethrough formatting around the selected text
/// </summary>
/// <returns></returns>
public Task ToggleMarkdownStrikethrough() => cmJsInterop.ModuleInvokeVoidAsync("toggleMarkdownStrikethrough");

/// <summary>
/// Toggle markdown code formatting around the selected text
/// </summary>
/// <returns></returns>
public Task ToggleMarkdownCode() => cmJsInterop.ModuleInvokeVoidAsync("toggleMarkdownCode");

/// <summary>
/// Toggle markdown code block formatting around the selected text
/// </summary>
/// <returns></returns>
public Task ToggleMarkdownCodeBlock() => cmJsInterop.ModuleInvokeVoidAsync("toggleMarkdownCodeBlock");

/// <summary>
/// Toggle markdown quote formatting around the selected text
/// </summary>
/// <returns></returns>
public Task ToggleMarkdownQuote() => cmJsInterop.ModuleInvokeVoidAsync("toggleMarkdownQuote");

/// <summary>
/// Toggle markdown header formatting for the selected line
/// </summary>
/// <param name="headerLevel"></param>
/// <returns></returns>
public Task ToggleMarkdownHeading(int headerLevel) => cmJsInterop.ModuleInvokeVoidAsync($"toggleMarkdownHeading{headerLevel}");

/// <summary>
/// Toggle markdown unordered list formatting for the selected line
/// </summary>
/// <returns></returns>
public Task ToggleMarkdownUnorderedList() => cmJsInterop.ModuleInvokeVoidAsync("toggleMarkdownUnorderedList");

/// <summary>
/// Toggle markdown ordered list formatting for the selected line
/// </summary>
/// <returns></returns>
public Task ToggleMarkdownOrderedList() => cmJsInterop.ModuleInvokeVoidAsync("toggleMarkdownOrderedList");

/// <summary>
/// Toggle markdown task list formatting for the selected line
/// </summary>
/// <returns></returns>
public Task ToggleMarkdownTaskList() => cmJsInterop.ModuleInvokeVoidAsync("toggleMarkdownTaskList");

/// <summary>
/// Undo the last change
/// </summary>
/// <returns></returns>
public Task PerformUndo() => cmJsInterop.ModuleInvokeVoidAsync("performUndo");

/// <summary>
/// Redo the last change
/// </summary>
/// <returns></returns>
public Task PerformRedo() => cmJsInterop.ModuleInvokeVoidAsync("performRedo");

/// <summary>
/// Undo the last selection change
/// </summary>
/// <returns></returns>
public Task PerformUndoSelection() => cmJsInterop.ModuleInvokeVoidAsync("performUndoSelection");

/// <summary>
/// Redo the last selection change
/// </summary>
/// <returns></returns>
public Task PerformRedoSelection() => cmJsInterop.ModuleInvokeVoidAsync("performRedoSelection");

/// <summary>
/// Focus the CodeMirror editor
/// </summary>
/// <returns></returns>
public Task FocusCodeMirrorEditor() => cmJsInterop.ModuleInvokeVoidAsync("focus");

/// <summary>
/// Insert or replace the selected text
/// </summary>
public Task InsertOrReplaceText(string text) => cmJsInterop.ModuleInvokeVoidAsync("insertOrReplaceText", text);
}
107 changes: 107 additions & 0 deletions CodeMirror6/Models/CodeMirrorSetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using System.Text.Json.Serialization;

namespace CodeMirror6.Models;

/// <summary>
/// Stores the configuration of a CodeMirror instance (what plugins to load).
/// Cannot be changed after the instance is created.
/// </summary>
public readonly record struct CodeMirrorSetup
{
/// <summary>
/// Default constructor
/// </summary>
public CodeMirrorSetup()
{
}

/// <summary>
/// Whether to show line numbers to the left of the editor.
/// </summary>
[JsonPropertyName("lineNumbers")] public bool LineNumbers { get; init; } = true;

/// <summary>
/// Whether to highlight the line gutter when the cursor is on it.
/// </summary>
[JsonPropertyName("highlightActiveLineGutter")] public bool HighlightActiveLineGutter { get; init; } = true;

/// <summary>
/// Whether to highlight special characters (whitespace, tabs, newlines).
/// </summary>
[JsonPropertyName("highlightSpecialChars")] public bool HighlightSpecialChars { get; init; } = true;

/// <summary>
/// Whether to enable undo/redo.
/// </summary>
[JsonPropertyName("history")] public bool History { get; init; } = true;

/// <summary>
/// Whether to enable code folding.
/// </summary>
[JsonPropertyName("foldGutter")] public bool FoldGutter { get; init; } = true;

/// <summary>
/// Whether to draw the selection when the editor is focused.
/// </summary>
[JsonPropertyName("drawSelection")] public bool DrawSelection { get; init; } = true;

/// <summary>
/// Whether to show a cursor marker when the editor is focused.
/// </summary>
[JsonPropertyName("dropCursor")] public bool DropCursor { get; init; } = true;

/// <summary>
/// Whether to allow multiple selections.
/// </summary>
[JsonPropertyName("allowMultipleSelections")] public bool AllowMultipleSelections { get; init; } = true;

/// <summary>
/// Whether to indent the current line when a character is typed that might cause the line to be re-indented.
/// </summary>
[JsonPropertyName("indentOnInput")] public bool IndentOnInput { get; init; } = true;

/// <summary>
/// Whether to enable syntax highlighting.
/// </summary>
[JsonPropertyName("syntaxHighlighting")] public bool SyntaxHighlighting { get; init; } = true;

/// <summary>
/// Whether to highlight matching brackets.
/// </summary>
[JsonPropertyName("bracketMatching")] public bool BracketMatching { get; init; } = true;

/// <summary>
/// Whether to automatically close brackets.
/// </summary>
[JsonPropertyName("closeBrackets")] public bool CloseBrackets { get; init; } = true;

/// <summary>
/// Whether to enable autocompletion.
/// </summary>
[JsonPropertyName("autocompletion")] public bool Autocompletion { get; init; } = true;

/// <summary>
/// Whether to enable rectangular selection.
/// </summary>
[JsonPropertyName("rectangularSelection")] public bool RectangularSelection { get; init; } = true;

/// <summary>
/// Whether to enable crosshair selection.
/// </summary>
[JsonPropertyName("crossHairSelection")] public bool CrossHairSelection { get; init; } = true;

/// <summary>
/// Whether to highlight the active line.
/// </summary>
[JsonPropertyName("highlightActiveLine")] public bool HighlightActiveLine { get; init; } = true;

/// <summary>
/// Whether to highlight selection matches.
/// </summary>
[JsonPropertyName("highlightSelectionMatches")] public bool HighlightSelectionMatches { get; init; } = true;

/// <summary>
/// Whether to enable preview images.
/// </summary>
[JsonPropertyName("previewImages")] public bool PreviewImages { get; init; } = true;
}
35 changes: 35 additions & 0 deletions CodeMirror6/Models/ThemeMirrorTheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,47 @@ public enum ThemeMirrorTheme
/// Preset theme: tomorrow
/// </summary>
Tomorrow,

/// <summary>
/// Preset theme: Github Dark
/// </summary>
GithubDark,

/// <summary>
/// Preset theme: Github Light
/// </summary>
GithubLight,

/// <summary>
/// Preset theme: Monokai
/// </summary>
Monokai,

/// <summary>
/// Preset theme: Nord
/// </summary>
Nord,

/// <summary>
/// Preset theme: One Light
/// </summary>
SolarizedDark,
//SolarizedLight,
// Sublime,

/// <summary>
/// Preset theme: Tomorrow Night
/// </summary>
TokyoNight,
// TokyoNightDay,

/// <summary>
/// Preset theme: Tomorrow Night Storm
/// </summary>
TokyoNightStorm,

/// <summary>
/// Preset theme: VS Code
/// </summary>
VSCode,
}
Loading
Loading