Add MarkdownTablePasteService and integrate with NoteEditDialog and PageNoteDialog components
This commit introduces the MarkdownTablePasteService to facilitate markdown table pasting functionality. The service is registered in Program.cs and injected into NoteEditDialog and PageNoteDialog components. Additionally, OnAfterRenderAsync lifecycle methods are implemented in both dialog components to initialize the service after the editor is rendered, enhancing the user experience for note editing. This change supports improved markdown handling within the application.
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
<script src="https://cdn.jsdelivr.net/npm/sortablejs@latest/Sortable.min.js"></script>
|
||||
<script src="_content/PSC.Blazor.Components.MarkdownEditor/js/easymde.min.js"></script>
|
||||
<script src="_content/PSC.Blazor.Components.MarkdownEditor/js/markdownEditor.js"></script>
|
||||
<script src="js/markdownTablePaste.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
@inject INotesService NotesService
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IDialogService DialogService
|
||||
@inject MarkdownTablePasteService MarkdownTablePasteService
|
||||
|
||||
<MudDialog Class="@MarkdownHelper.GetNoteColorClass(_note.Id)">
|
||||
<DialogContent>
|
||||
@@ -42,6 +43,7 @@
|
||||
public bool IsEdit { get; set; }
|
||||
|
||||
private Note _note = null!;
|
||||
private bool _pasteMarkdownInitialized = false;
|
||||
|
||||
private bool IsPageNote => Note?.Title?.StartsWith("@") ?? false;
|
||||
|
||||
@@ -55,6 +57,17 @@
|
||||
};
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender && !_pasteMarkdownInitialized)
|
||||
{
|
||||
// Initialize paste-markdown after EasyMDE has rendered
|
||||
await Task.Delay(150); // Wait for EasyMDE to initialize
|
||||
await MarkdownTablePasteService.InitializeAsync();
|
||||
_pasteMarkdownInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Save()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_note.Title))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
@namespace WebApp.Components.Shared.Components
|
||||
@inject INotesService NotesService
|
||||
@inject ISnackbar Snackbar
|
||||
@inject MarkdownTablePasteService MarkdownTablePasteService
|
||||
@implements IAsyncDisposable
|
||||
|
||||
<MudDialog Class="@MarkdownHelper.GetNoteColorClass(_note.Id)">
|
||||
@@ -77,6 +78,7 @@
|
||||
private bool _isEditMode = false;
|
||||
private CancellationTokenSource? _cancellationTokenSource;
|
||||
private bool _isDisposed = false;
|
||||
private bool _pasteMarkdownInitialized = false;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
@@ -94,6 +96,20 @@
|
||||
await LoadPageNote();
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender && _isEditMode && !_pasteMarkdownInitialized)
|
||||
{
|
||||
// Initialize paste-markdown after first render if already in edit mode
|
||||
await Task.Delay(150); // Wait for EasyMDE to initialize
|
||||
if (!_isDisposed)
|
||||
{
|
||||
await MarkdownTablePasteService.InitializeAsync();
|
||||
_pasteMarkdownInitialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadPageNote()
|
||||
{
|
||||
if (_isDisposed) return;
|
||||
@@ -201,11 +217,22 @@
|
||||
}
|
||||
}
|
||||
|
||||
private void EnterEditMode()
|
||||
private async Task EnterEditMode()
|
||||
{
|
||||
if (_isDisposed) return;
|
||||
_isEditMode = true;
|
||||
StateHasChanged();
|
||||
|
||||
// Initialize paste-markdown after editor is rendered
|
||||
if (!_pasteMarkdownInitialized)
|
||||
{
|
||||
await Task.Delay(150); // Wait for EasyMDE to initialize
|
||||
if (!_isDisposed)
|
||||
{
|
||||
await MarkdownTablePasteService.InitializeAsync();
|
||||
_pasteMarkdownInitialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Cancel()
|
||||
|
||||
Reference in New Issue
Block a user